Dmytro Danylyk
10/09/2017, 6:14 AMgildor
10/09/2017, 6:22 AMioContext
probably not the best alias for CommonPool, because if you want to use rxjava scheduler analogue you should name it computationContext
.
Just because use CommonPool for blocking IO operations is bad ideaval task = async(ioContext) { dataProvider.loadData("Task") }
val result: Result<String> = task.await()
you can use
val result: Result<String> = run(ioContext) { dataProvider.loadData("Task") }
Result
with better and API and avoid nullable fieldsDmytro Danylyk
10/10/2017, 4:28 AMgildor
10/10/2017, 4:54 AMdataProvider.loadData("Task")
?async.await()
call, I don’t see difference with run
in your examplefun processError(result: Result.Error)
. Also, you can have more complicated Sealed class with additional helper methods and combinators.Dmytro Danylyk
10/10/2017, 8:49 AMstartPresenting
2. Call stopPresenting
3. You will see stack trace with cancellation exception
Exactly same code but with run
1. Call startPresenting
2. Call stopPresenting
3. You will see stack trace with cancellation exception
4. In 5 sec app crash with IllegalStateException("Ooops you are unlucky")
gildor
10/10/2017, 8:52 AMrun
? because run by default uses context of parent coroutineDmytro Danylyk
10/10/2017, 8:54 AMgildor
10/10/2017, 8:58 AM