Hi, guys, is there any API in `Flow` like `Observa...
# coroutines
s
Hi, guys, is there any API in
Flow
like
Observable.timeout
?
m
I guess you could use
withTimeout
method of the coroutines?
g
withTimeout is not the same, you cannot control emission of items, only overall collect yime. I would create a feature request for this if you have good use case
s
I'm writing a MPP for Bluetooth communication. Some code like this
Copy code
private fun receiveChunks(count: Int) = notepadType!!.receiveFileInput()
        .filter { it.first() == 0x05.toByte() }
        // TODO Take with timeout
        .take(count)
The 1.x version was writed in RxKotlin & RxSwift, quit the same way. It receives data in indexed and unsorted chunks, then reduces to a block, kind of TCP --> HTTP
g
Yeah, make sense. I would create a feature request on kotlinx.coroutunes issue tracker. But in general it's not hard to write own operator for that with required semantics
s
@gildor somehow, the
withTimeout
doesn't work on iOS without
runBlocking
. Is there another way round?
g
Hard to say, maybe some bug, bit better reproduce it and report
But again, not sure what is required semantics for you, because withContext is not the same as Observable.timeout
s
https://github.com/Kotlin/kotlinx.coroutines/issues/462#issuecomment-430111440
delay
requires
runBlocking
.
withTimeout
maybe the same
I tried implement the
Observabel.timeout
by
withTimeout
, but no luck. I find another way round, with
dispatch_after
on iOS and
Handler.postDelayed
on Android.