Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created June 25, 2020 15:31
Show Gist options
  • Save JoseAlcerreca/f1c2604c9914a56b6bb84c3e730e99fa to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/f1c2604c9914a56b6bb84c3e730e99fa to your computer and use it in GitHub Desktop.
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
suspend fun doOneShot(param: String) : Result<String> =
suspendCancellableCoroutine { continuation ->
api.addOnCompleteListener { result ->
continuation.resume(result)
}.addOnFailureListener { error ->
continuation.resumeWithException(error)
}.fetchSomething(param)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment