log("about to create the task...") thread { Thread.sleep(500) log("task is created...") callback("The answer to life, universe and everything") } } @RittmeyerW
create the task...") val future = CompletableFuture<String>() thread { Thread.sleep(500) log("task is created...") future.complete("The answer to life, universe and everything") } return future } @RittmeyerW
do some stuff suspendingly: delay(500) println("after delay") // do something else; suspendingly or not } println("after runBlocking will be printed") } @RittmeyerW
someApiWithCallback { result -> if (continuation.isActive) { when (result) { is Result.Success -> continuation.resume(result.success) is Result.Error -> continuation.resumeWithException(result.error) } } } } @RittmeyerW
public fun resumeWith(result: Result<T>) } public inline fun <T> Continuation<T>.resume(value: T): Unit = resumeWith(Result.success(value)) public inline fun <T> Continuation<T>.resumeWithException(exception: Throwable): Unit = resumeWith(Result.failure(exception)) @RittmeyerW
public fun resumeWith(result: Result<T>) } public inline fun <T> Continuation<T>.resume(value: T): Unit = resumeWith(Result.success(value)) public inline fun <T> Continuation<T>.resumeWithException(exception: Throwable): Unit = resumeWith(Result.failure(exception)) @RittmeyerW