Refactor
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package eventDemo.app.actions.playNewCard
|
||||
|
||||
import eventDemo.shared.command.GameCommandStream
|
||||
import eventDemo.shared.event.CardIsPlayedEvent
|
||||
import eventDemo.shared.event.GameEventStream
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Listen [PlayCardCommand] on [GameCommandStream], check the validity and execute the action.
|
||||
* This action produces a new [CardIsPlayedEvent]
|
||||
*/
|
||||
class PlayCardCommandHandler(
|
||||
private val commandStream: GameCommandStream,
|
||||
private val eventStream: GameEventStream,
|
||||
) {
|
||||
operator fun invoke() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
commandStream.process {
|
||||
// TODO check the command can be executed
|
||||
eventStream.publish(CardIsPlayedEvent(it.payload.game.id, it.payload.card))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user