rook
05/14/2019, 7:00 PMrook
05/14/2019, 7:09 PMIO for anything in Bar, but I need the action arg for getAThing to have its body defaulted to Main and have every suspend in it suspended to IO.louiscad
05/14/2019, 7:16 PMfoo and bar are not helping much.
Some observations regarding your snippet still:
It seems there's no reason Bar should implement CoroutineScope. The async block in getAThing is code smell. It breaks structured concurrency as it doesn't use a local scope and its result is not used. Please, read async doc and understand that you rarely need it.rook
05/14/2019, 7:24 PMFoo is a presenter-type object and it needs to invoke view actions on the main thread.
Bar is a repository-type object. It needs to make network requests and db queries via the appropriate interfaces. Those kinds of transactions have to happen off the main thread. Some network objects need additional network requests made in order coalesce multiple data sources. I need the original result immediately displayed to the screen and continue to resolve the extra requests in the background, invoking view updates using action. I’m using async to force the extra calls to be made asynchronously.rook
05/14/2019, 7:28 PMlouiscad
05/14/2019, 7:29 PMrook
05/14/2019, 7:30 PMlouiscad
05/14/2019, 7:32 PMaction supposed to do?rook
05/14/2019, 7:33 PMdoWork fun in Presenterrook
05/14/2019, 7:33 PMupdateThinglouiscad
05/14/2019, 7:34 PMrook
05/14/2019, 7:35 PMThing type objectrook
05/14/2019, 7:35 PMrook
05/14/2019, 7:50 PMCoroutineScope from Repository. That actually helped me understand a lot better. I reorganized the code a bit to just invoke updateThing from doWork and pass in the updates there at the end of the block.rook
05/14/2019, 7:51 PMbdawg.io
05/14/2019, 8:07 PMval thing = db.getThing() ?: network.getThing() instead of var thing ...rook
05/14/2019, 9:08 PMnetwork.getThing() portion is vastly over simplified in this example. I was hoping to get more input on the way I've organized coroutines in this example.uli
05/15/2019, 5:37 AMrook
05/15/2019, 2:41 PMThing is a list that can have hundreds of entries and updateThing has to do a network call for each thing. I want the view to be updated as each entry is resolved, rather than wait for potentially hundreds of network calls to resolve.uli
05/15/2019, 8:55 PMactionuli
05/15/2019, 8:57 PMrook
05/15/2019, 9:57 PMuli
05/15/2019, 10:06 PMthing from all methods. In the end the return value seem unused.
Instead you could return a freshly created channel.louiscad
05/16/2019, 6:03 AMrook
05/16/2019, 3:03 PM