than_
10/14/2019, 11:05 AMlifecycleCoroutineScope with provided await function seems to work.
suspend fun <T> Kind<ForIO, T>.await(ur: UnsafeRun<ForIO>): Either<Throwable, T> = ur.run {
suspendCancellableCoroutine { continuation ->
val cancellableAction = this@await.fork(continuation.context)
.bracketCase(
use = { IO.just(Unit) },
release = { fiber, exitCase: ExitCase<Throwable> ->
when (exitCase) {
is ExitCase.Completed ->
fiber.join().attempt().map { continuation.resume(it) }
ExitCase.Canceled -> {
continuation.cancel()
fiber.cancel()
}
is ExitCase.Error -> {
continuation.resume(exitCase.e.left())
fiber.cancel()
}
}
}
)
unsafe {
runNonBlocking(
fa = { cancellableAction },
cb = { }
)
}
}
}
But I feel I'm missing some more graceful solution. Is there a better way?