Slide 58
Slide 58 text
fun loadUserData(userId: UserID, callback: (UserData?, Throwable?) -> Unit)
suspend fun loadUserData(userId: UserID): UserData {
return suspendCoroutine { continuation ->
loadUserData(userId) { data, exception ->
if (data != null) {
continuation.resume(data)
} else {
continuation.resumeWithException(exception!!)
}
}
}
}
Wrapping third-party callback-based API