You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe the issue is with Kable's internals not properly handling the premature closure in the callbackFlow.
As per the callbackFlow KDoc, we should be catching exceptions when trying to emit within the callbackFlow (emphasis shown in green):
fun flowFrom(api: CallbackBasedApi): Flow<T> = callbackFlow {
val callback = object : Callback { // Implementation of some callback interface
override fun onNextValue(value: T) {
// To avoid blocking you can configure channel capacity using
// either buffer(Channel.CONFLATED) or buffer(Channel.UNLIMITED) to avoid overfill
+ try {
sendBlocking(value)
+ } catch (e: Exception) {+ // Handle exception from the channel: failure in flow or premature closing+ }
}
override fun onApiError(cause: Throwable) {
cancel(CancellationException("API Error", cause))
}
override fun onCompleted() = channel.close()
}
api.register(callback)
/*
* Suspends until either 'onCompleted'/'onApiError' from the callback is invoked
* or flow collector is cancelled (e.g. by 'take(1)' or because a collector's coroutine was cancelled).
* In both cases, callback will be properly unregistered.
*/
awaitClose { api.unregister(callback) }
}
The text was updated successfully, but these errors were encountered:
Issue/question raised on StackOverflow.
I believe the issue is with Kable's internals not properly handling the premature closure in the
callbackFlow
.As per the
callbackFlow
KDoc, we should be catching exceptions when trying to emit within thecallbackFlow
(emphasis shown in green):The text was updated successfully, but these errors were encountered: