fstn
11/30/2017, 1:15 PMsuspend fun <T> awaitEvent(block: (h: Handler<T>) -> Unit) : T {
return suspendCancellableCoroutine { cont: CancellableContinuation<T> ->
try {
block.invoke(Handler { t ->
cont.resume(t)
})
} catch(e: Exception) {
cont.resumeWithException(e)
}
}
}
How can I use awaitEvent to listen to an handler of AsyncResult<String> and return MyObjectResult
This is what I try to do:
`
override suspend fun get(userId: String): ContextInsideMessageBody? {
return awaitEvent { handler ->
val context = redis.get("peter/user/$userId/context", handler)
if (context != null) {
ContextInsideMessageBody().update(JsonObject(context)) as ContextInsideMessageBody
} else {
null
}
}
}`
I want to return a different type from my awaitEvent { handler -> that the type the handler use