-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove UglyHack, replace with Deferred
- Loading branch information
Showing
6 changed files
with
67 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
games-mpp/games-server/src/main/kotlin/net/zomis/games/listeners/SteppingGameListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.zomis.games.listeners | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.sync.Mutex | ||
import net.zomis.games.dsl.GameListener | ||
import net.zomis.games.dsl.impl.FlowStep | ||
|
||
class SteppingGameListener: GameListener { | ||
|
||
private val internalChannel = Channel<FlowStep>() | ||
|
||
override suspend fun handle(coroutineScope: CoroutineScope, step: FlowStep) { | ||
internalChannel.send(step) | ||
} | ||
|
||
suspend fun takeUntil(function: (FlowStep) -> Boolean): FlowStep { | ||
while (true) { | ||
val output = next() | ||
if (function.invoke(output)) return output | ||
} | ||
} | ||
|
||
suspend fun next(): FlowStep = internalChannel.receive() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
games-mpp/games-server/src/test/kotlin/net/zomis/games/dsl/flow/GameFlowTestHelper.kt
This file was deleted.
Oops, something went wrong.
22 changes: 10 additions & 12 deletions
22
games-mpp/games-server/src/test/kotlin/net/zomis/games/dsl/flow/RoyalGameOfUrFlowTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters