TightRope tolerant cancellation for 200ms
This commit is contained in:
1 parent
6aa0878480
commit
a4b0c1fe36
1 file changed
+1
-1
@@ -34,7 +34,7 @@ suspend inline fun <T> CancellableContinuation<T>.evalAndResume(f: suspend () ->
|
||||
class TightRope : CoroutineScope, Counter by counter() {
|
||||
override val coroutineContext = Dispatchers.IO + Job()
|
||||
val actions = Channel<F>()
|
||||
val flow = actions.receiveAsFlow().map(F::invoke).buffer(0).shareIn(this, SharingStarted.WhileSubscribed())
|
||||
val flow = actions.receiveAsFlow().map(F::invoke).buffer(0).shareIn(this, SharingStarted.WhileSubscribed(stopTimeoutMillis = 200))
|
||||
suspend inline fun <R> sendAndAwait(crossinline block: suspend () -> R) = raceN(
|
||||
{ flow.collect {} },
|
||||
{ suspendCancellableCoroutine { cont -> launch { actions.send { cont.evalAndResume(block) } } } },
|
||||
|
||||
Reference in new issue
Block a user