Hi! I want to wrap my player callback into suspend...
# coroutines
o
Hi! I want to wrap my player callback into suspend function that will just suspend until something completed without returning any value. Is there some alternative for
suspendCoroutine
that doesn’t require passing result value?
I can rewrite it as
Copy code
private suspend fun waitForPlayerOpen() {
        suspendCoroutine<Unit> {
            player.addOpenListener {
                it.resume(Unit) //what if I don't need to return value?    
            }
        }
    }
But it still looks as workaround, isn’t it?
g
Pass Unit
it’s not a workaround, it’s exactly how it should work for functions that return Unit (which is any function “without returning any value.“, just language allows you to omit return type if it’s Unit
o
Great, thank you!
m
How about
it.resumeWith(Result.success)
? It’s still a return value but more meaningful.
o
success
is also function that takes value and wraps it into
Result
, so I need to write
it.resumeWith(Result.success(Unit))
. It almost the same as previous variant
g
It almost the same as previous variant
It’s exactly the same, function
resume
is juste extension function that wraps object to Result.success
m
Ah you’re right