I have a problem with two scopes that I kinda both need at the same time:
There is this monadic Result library, where you can write code like this (
getFoo
returns a
Result<GoodValue, ErrValue>
)
binding {
val goodValue = getFoo().bind()
}
The problem I have is that I can’t get it to work with coroutines:
This doesn’t compile, because
getFoo()
is a suspend function, so I must call it from a coroutine scope
scope.launch {
binding {
val goodValue = getFoo().bind()
}
}
This crashes at runtime, because
binding
apparently can’t catch the
bind()
event (makes sense if it’s thrown asynchronously)
binding {
scope.launch {
val goodValue = getFoo().bind()
}
}
So how do I combine those?