Flow's onStart is called before subscribing to underlying data stream. When writing to a characteristic and expecting to receive the response via a characteristic changed event, if the Flow is slow to subscribe then the response could be lost.
Problem is described/discussed in Kotlin/kotlinx.coroutines#1758 and will be fixed with Kotlin/kotlinx.coroutines#2034.
The workaround is to use openSubscription().consumeAsFlow() which opens the subscription prior to spinning up the Flow (and in turn will be subscribed before the Flow's onStart).
Flow
'sonStart
is called before subscribing to underlying data stream. When writing to a characteristic and expecting to receive the response via a characteristic changed event, if theFlow
is slow to subscribe then the response could be lost.Problem is described/discussed in Kotlin/kotlinx.coroutines#1758 and will be fixed with Kotlin/kotlinx.coroutines#2034.
The workaround is to use
openSubscription().consumeAsFlow()
which opens the subscription prior to spinning up theFlow
(and in turn will be subscribed before theFlow
'sonStart
).