simon.vergauwen
10/14/2019, 11:52 AMIO
can run in a cancellable way with a cancelable reference typealias Disposeable = () -> Unit
. Whenever the coroutine gets cancelled you can also cancel the underlying IO
using that reference.
fun <A> IOOf<A>.suspendCancellable() : Either<Throwable, A> =
suspendCancellableCoroutine { continuation ->
val disposable = fix().unsafeRunSyncCancellable { continuation.resume(it) }
continuation.invokeOnCancellation { disposable.invoke() }
}
than_
10/14/2019, 2:25 PM