I’m trying to use coroutines and have defined a ‘s...
# getting-started
d
I’m trying to use coroutines and have defined a ‘suspend’ function correctly. However, the call-site fails to compile with ‘should be called only from a coroutine or another suspend function’. I realise that some mechanism to bridge Kotlins coroutine system with Androids MainLooper must be required; but how to implement it?
e
darkmoon_uk: Please, join #coroutines for discussion. There is no out-of-the-box Android MainLoop support in
kotlinx.coroutines
yet, but you can easily rollout your own based on the examples for Swing and JavaFx. @gildor was writing a small library for that, too.
I'll also highly recommend reading the guide to kotlinx.coroutines: https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md
d
Thanks Roman
g
@darkmoon_uk You can check my small lib for that - https://github.com/gildor/kotlin-coroutines-android/tree/master/coroutines-android Also today I plan to update it with new API
@darkmoon_uk Actually there are two main parts: MainThread dispatcher and lifecycle events handling.
d
Great; thanks Andrey I will take a look.
…and see how you implemented your code 🙂
g
@darkmoon_uk New version has different lifecycle api, but looper is mostly the same (only changes for 0.11-rc coroutines library)
d
Ok
@elizarov Thanks for pointing me toward the Swing example, that was very helpful to read.