https://kotlinlang.org logo
Title
s

sunbreak

08/31/2019, 5:13 AM
Somehow, the
withTimeout
doesn’t work on iOS without
runBlocking
. Is there another way round?
b

basher

08/31/2019, 5:57 AM
Nope. It requires an event loop from runBlocking or a custom main-thread only Dispatcher
s

sunbreak

08/31/2019, 7:52 AM
b

basher

08/31/2019, 2:34 PM
You can try it! What is it you're trying to accomplish?
As
Observable.timeout
is not available now, I’d like to implement it with
withTimeout
b

basher

08/31/2019, 11:17 PM
This is for general usage on the main thread or background?
s

sunbreak

08/31/2019, 11:25 PM
Generally it is supposed to be backgroud. But we can use it on the main thread for now.
b

basher

08/31/2019, 11:37 PM
For main thread, if you can't use runBlocking and only need it on apple platforms, I would implement a CoroutineDispatcher that also implements Delay via GCD that only dispatches blocks to the main queue. Then, you should be able to use all of that. For background: github.com/autodesk/CoroutineWorker
I personally haven't tested out the GCD-driven dispatcher approach yet, but it should work fine with the native threading model, and I've seen references to other folks trying it (main thread only though)
s

sunbreak

08/31/2019, 11:51 PM
Thank you so much. I tried with GCD on iOS and
Handler.postDelayed
on Android, and both work. I’ll take this way for now.
🙌 1
github.com/autodesk/CoroutineWorker looks promising. I’ll try it next feature version
👍 1