AndroidCoroutinesHelper icon indicating copy to clipboard operation
AndroidCoroutinesHelper copied to clipboard

Top-level functions launch() & async() are deprecated

Open marcardar opened this issue 7 years ago • 3 comments

Not sure how you would fix this. Doesn't seem like a good idea to just shove GlobalScope. in front of those calls.

marcardar avatar Oct 29 '18 10:10 marcardar

Yeah, I haven't had time to look at this properly. It should be possible, but I need to find some time to update this (and the blog post).

ErikHellman avatar Oct 29 '18 10:10 ErikHellman

If you try to pass in a scope to the then() function, then that won't compile because infix functions only take a single argument.

marcardar avatar Oct 29 '18 11:10 marcardar

The trick would be to put the scope on the lifecycle-listener and let that one own the coroutines.

While this approach looks nice I have some concerns about initiating coroutines from an activity or fragment. While it works, it is usually less optimal as we have the LiveData classes today. If we move the coroutines to a ViewModel, the need to pass the data back to the main thread disappears as we can do postValue() on a LiveData from a background thread.

Basically, I think my approach as it is right now is unnecessary. :)

ErikHellman avatar Oct 30 '18 08:10 ErikHellman