https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Paul Woitaschek

05/28/2018, 7:30 PM
AsyncTask.THREAD_POOL_EXECUTOR
i

igorvd

05/28/2018, 8:11 PM
I'm considering using it too. But my unit tests are now failing because of the android framework dependency
a

alex.krupa

05/28/2018, 8:27 PM
@igorvd pass your dispatcher through the constructor so that you can easily replace it with a non-Android one in unit tests. Another solution (that may be considered not clean) would be to make the top-level property from @louiscad's suggestion a
var
and overwrite it with a test dispatcher.
p

Paul Woitaschek

05/28/2018, 8:27 PM
I always inject the dispatchcer
i

igorvd

05/28/2018, 8:31 PM
Yeah I sugest it on the project start, but my manager tought that it would not be necessary... For now I just put it in a try-catch, and use the CommonPool in case the asyncTask is not available. At least the tests are working... But I'll definitely refactor to inject the dispatcher eventually
d

dave08

05/29/2018, 1:59 AM
Maybe a top level val with an if on BuildConfig might be better than try catch?
But injection is probably best...
i

igorvd

05/29/2018, 11:44 AM
what should I test on buildConfig? I don't want to test for debug builds to choose the dispatcher, for example
5 Views