pajatopmr
02/11/2019, 4:47 AMgildor
02/11/2019, 5:38 AMrunBlocking
, but instead make function suspendable
2. It’s not clear for me, why do you need channel in this case
3. Instead of passing scope as argument, I would just make function suspend (as in item 1) and use coroutineScope {}
block, because this function shouldn’t return until it finish job
4. I would convert fetchLines to suspend function + withContext(IO)
, so function become non blocking and you can just can call it, without worry about dispatcher
5. Using MutableMap to return value doesn’t seems correct, better just return valuepajatopmr
02/11/2019, 6:09 AMgildor
02/11/2019, 6:13 AM2) Channel is for safe transfer of list back to the main thread.This is strange reason, suspend function is also completely trade safe for that (of course if you don’t touch global state)
1) Making dailyExportTask() suspend causes an error: the invoking code must be a coroutine,Yes, because you use launch it outside of coroutine, I added a couple TODO with suggestion just expost this API as asyncronous suspend function rather than do blocking network call on singleton access, which is really smells
pajatopmr
02/11/2019, 6:25 AMgildor
02/11/2019, 6:25 AMmap + awaitAll
patter to run multiple coroutines concurrently and await all the results
It doesn’t look complicated for me
Approach with Channel was much more complicated, it true, but there is no reason to use itpajatopmr
02/11/2019, 6:32 AMgildor
02/11/2019, 6:33 AMrunBlocking
pajatopmr
02/11/2019, 6:34 AMgildor
02/11/2019, 6:34 AMpajatopmr
02/11/2019, 6:35 AMgildor
02/11/2019, 6:40 AM