Skip to content

Instantly share code, notes, and snippets.

@JacquesSmuts
Last active May 21, 2019 20:28
Show Gist options
  • Save JacquesSmuts/8ae63a3da81d38708c0c35a300280a86 to your computer and use it in GitHub Desktop.
Save JacquesSmuts/8ae63a3da81d38708c0c35a300280a86 to your computer and use it in GitHub Desktop.
suspend fun saveUsername(username: String) {
val result = suspendAsync(StorageService.getInstance()::saveUsername, username)
handleResult(result)
}
suspend fun <Input, Output> suspendAsync(function: (Input, (Output) -> Unit) -> Unit,
input: Input) = suspendCoroutine<Output> { continuation ->
function(input) { output ->
continuation.resume(output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment