Created
September 17, 2022 18:34
-
-
Save ibrahimsn98/2e6fe14ac75205a198aeb81a8e86706c to your computer and use it in GitHub Desktop.
ty-demeter-blog-3
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
internal class OperationQueue(demeter: Demeter, coroutineScope: CoroutineScope) { | |
private val queue = Channel<Operation>(BUFFER_SIZE) | |
init { | |
queue.receiveAsFlow() | |
.onEach { operation -> | |
runCatching { | |
operation.operate(demeter) | |
}.onFailure { | |
demeter.eventResultReporter.report(Result.failure(it)) | |
} | |
} | |
.flowOn(Dispatchers.Default) | |
.launchIn(coroutineScope) | |
} | |
fun append(operation: Operation) { | |
queue.trySend(operation) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment