Eugen Martynov
07/21/2025, 11:54 AMval waithForDBSave = async { setupListenerAndWait() }
db.save() // I want to wait before executing here to be sure listener was setup
waitForDBSave.await()
Eugen Martynov
07/21/2025, 11:57 AMDmitry Khalanskiy [JB]
07/21/2025, 11:57 AMsetupListenerAndWait()
will not suspend until the listener is installed, you can do this:
val waithForDBSave = async(start = CoroutineStart.UNDISPATCHED) {
Eugen Martynov
07/21/2025, 12:00 PMsuspendCoroutine { continuation ->
val saveListener = object : SaveListener {
override fun onSaved() {
continuation.resume(Unit)
}
}
db.addListener(saveListener)
}
Dmitry Khalanskiy [JB]
07/21/2025, 12:00 PMsuspendCoroutine
won't suspend until its block finishes executing, so UNDISPATCHED
should work.Eugen Martynov
07/21/2025, 12:00 PMEugen Martynov
07/21/2025, 12:00 PMNitesh Singh
07/21/2025, 12:53 PMEugen Martynov
07/21/2025, 1:04 PMZach Klippenstein (he/him) [MOD]
07/21/2025, 3:14 PMlaunch
instead of async
if your callback doesn't have a result.Eugen Martynov
07/21/2025, 4:53 PMNitesh Singh
07/21/2025, 5:02 PM