Open qwwdfsad opened 5 years ago
I will think about those questions.
Since my use case of EventSource
is pretty anectdotical, I would suggest to turn this issue into a more global one like "Provide suspending function and Flow based extensions on top of Web APIs".
The more I use Kotlin/JS, the more I think you could do for frontend what you did on Android with carefully crafted Kotlin extensions on top of Web APIs.
Another example using suspending functions:
suspend fun Window.awaitLoad() = suspendCoroutine<Unit> { cont ->
onload = {
cont.resume(Unit)
}
}
I'd prefer to support cancellation:
suspend fun Window.awaitLoad() {
try {
suspendCancellableCoroutine<Unit> { cont ->
onload = {
onload = null
cont.resume(Unit)
}
}
} finally {
onload = null
}
}
Even if in the case of waiting for window loading, cancellation is unlikely at this point, it might help some coroutines being cancelled earlier if the case applies.
Open questions:
EventSource
?