Mark
05/29/2019, 12:11 PMsuspend fun myFun() {
repeat(100) {
someSuspendingFunSpecifyingIODispatcher()
someQuickNonSuspendingFun()
}
}
At the top-level of myFun() is it better to have withContext(Dispatchers.IO), coroutineScope {} or leave it as it is?gildor
05/29/2019, 1:10 PMgildor
05/29/2019, 1:11 PMMark
05/29/2019, 1:12 PMgildor
05/29/2019, 1:12 PMMark
05/29/2019, 1:13 PMgildor
05/29/2019, 1:13 PMMark
05/29/2019, 1:13 PMgildor
05/29/2019, 1:14 PMgildor
05/29/2019, 1:14 PMMark
05/29/2019, 1:15 PMMark
05/29/2019, 1:16 PMsuspend fun myFun() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
repeat(100) {
someSuspendingFunSpecifyingIODispatcher()
someQuickNonSuspendingFun()
}
}
Mark
05/29/2019, 1:17 PMgildor
05/29/2019, 1:17 PMgildor
05/29/2019, 1:18 PMgildor
05/29/2019, 1:18 PMMark
05/29/2019, 1:19 PMgildor
05/29/2019, 1:21 PMMark
05/29/2019, 1:22 PMMark
05/29/2019, 1:22 PMgildor
05/29/2019, 1:22 PMgildor
05/29/2019, 1:24 PMMark
05/29/2019, 1:24 PMgildor
05/29/2019, 1:24 PMgildor
05/29/2019, 1:25 PMgildor
05/29/2019, 1:27 PMMark
05/29/2019, 1:27 PMpakoito
05/29/2019, 1:29 PMBut careful with cancellation, check for isActive or call yield if you don't have other suspend calls between blocking calls to make it cancellation friendlywhy do you need to check for this, shouldn't the next suspension at
someSuspendingFunSpecifyingIODispatcher
just not be triggered?Mark
05/29/2019, 1:30 PMgildor
05/29/2019, 2:42 PMgildor
05/29/2019, 2:42 PM