I have a problem with two scopes that I kinda both...
# coroutines
r
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>
)
Copy code
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
Copy code
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)
Copy code
binding {
  scope.launch {
    val goodValue = getFoo().bind()
  }
}
So how do I combine those?
a
If this is kotlin-result, wasn’t there a suspending version of
binding
?
r
@AdamW Thanks, that looks perfect!
👍 1