Last active
August 1, 2021 11:22
-
-
Save abhimuktheeswarar/5361902c6f58ca2beffcf7d5580e33cf to your computer and use it in GitHub Desktop.
customCounterStateMachine for blog
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
fun CoroutineScope.customCounterStateMachine(channel : ReceiveChannel<CounterMessage>) | |
= launch { | |
var counter = 0 // actor state | |
channel.consumeEach { message -> | |
ensureActive() | |
when (message) { | |
is IncrementCounter -> counter++ | |
is GetCounter -> message.response.complete(counter) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment