Skip to content

Instantly share code, notes, and snippets.

@ibrahimsn98
Created September 17, 2022 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibrahimsn98/2e6fe14ac75205a198aeb81a8e86706c to your computer and use it in GitHub Desktop.
Save ibrahimsn98/2e6fe14ac75205a198aeb81a8e86706c to your computer and use it in GitHub Desktop.
ty-demeter-blog-3
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