Skip to content
Permalink
Browse files

Added suspendable variant of whenReady #1145

  • Loading branch information
sksamuel committed Jan 12, 2020
1 parent a7da0c9 commit 0a16cc643d8cf38ca9525a6daec03cf08aad995f
@@ -45,6 +45,7 @@ object Libs {
object Coroutines {
private const val version = "1.3.3"
const val coreCommon = "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version"
const val jdk8 = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$version"
const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val coreJs = "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$version"
}
@@ -61,6 +61,7 @@ kotlin {
api(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation(Libs.Coroutines.core)
implementation(Libs.Coroutines.jdk8)
api(Libs.JUnitJupiter.api)
implementation(Libs.Slf4j.api)
implementation("io.arrow-kt:arrow-core:0.10.3")
@@ -1,12 +1,19 @@
package io.kotest

import kotlinx.coroutines.future.await
import java.util.concurrent.CompletableFuture

/**
* Allows callers to queue up futures with a callback that will be executed
* when the future has completed.
*/
@Deprecated("use the extension function variant: future.whenReady { } which uses coroutines rather than blocking")
fun <A> whenReady(f: CompletableFuture<A>, test: (A) -> Unit) {
val a = f.get()
test(a)
}
val a = f.get()
test(a)
}

suspend fun <A> CompletableFuture<A>.whenReady(test: (A) -> Unit) {
val a = this.await()
test(a)
}

0 comments on commit 0a16cc6

Please sign in to comment.
You can’t perform that action at this time.