John Fields
10/14/2024, 7:10 PMCLOVIS
10/14/2024, 7:41 PMfun Observable<T>.toFlow(): Flow<T> {
val observable = this
lateinit var subscription: Subscription
return flow {
subscription = observable.subscribe {
emit(it)
}
}.onCompletion {
subscription.unsubscribe()
}
}
There is probably a nicer way to write this, but it should at least give you a starting pointCLOVIS
10/14/2024, 7:43 PMObservable.subscribe
takes a callback that is executed for each new element, starts immediately to process elements, and returns a Subscription
• Subscription.unsubscribe
kills a subscription that is startedJohn Fields
10/14/2024, 9:05 PMturansky
10/15/2024, 8:23 AMJohn Fields
10/15/2024, 3:10 PMJohn Fields
10/15/2024, 3:12 PM