Skip to content

Instantly share code, notes, and snippets.

@MovileGente
Created March 21, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MovileGente/83be227ae98404385e7483385577ed77 to your computer and use it in GitHub Desktop.
Save MovileGente/83be227ae98404385e7483385577ed77 to your computer and use it in GitHub Desktop.
suspend fun <T> CompletableFuture<T>.await(): T =
   suspendCoroutine<T> { cont: Continuation<T> ->
       whenComplete { result, exception ->
           if (exception == null) {
               cont.resume(result)
           } else {
               cont.resumeWithException(exception)
           }
       }
   }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment