Fix New Message ONS request timeout

This commit is contained in:
Andrew
2024-06-15 00:36:10 +09:30
parent f69b629053
commit e44b401bd5
4 changed files with 71 additions and 30 deletions

View File

@@ -1,6 +1,9 @@
@file:JvmName("PromiseUtilities")
package org.session.libsignal.utilities
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.isActive
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.deferred
import nl.komponents.kovenant.functional.map
@@ -67,3 +70,19 @@ infix fun <V, E: Exception> Promise<V, E>.sideEffect(
callback(it)
it
}
/**
* Observe a [Promise] as a flow
*
* Warning: Promise will not be canceled on unsubscribe.
*/
fun <V, E: Exception> Promise<V, E>.asFlow() = callbackFlow {
success {
if (isActive) trySend(it)
close()
} fail {
close(it)
}
awaitClose()
}