Somehow, the `withTimeout` doesn’t work on iOS without `runBlocking`. Is there another way round?
s
Somehow, the
withTimeout
doesn’t work on iOS without
runBlocking
. Is there another way round?
b
Nope. It requires an event loop from runBlocking or a custom main-thread only Dispatcher
s
b
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
This is for general usage on the main thread or background?
s
Generally it is supposed to be backgroud. But we can use it on the main thread for now.
b
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
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