bloder
04/09/2019, 2:32 AMasync
is not working (newbie question probably)gildor
04/09/2019, 2:38 AMbloder
04/09/2019, 2:45 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) {}
): I have an app and a implementation of pull to refresh, and when user refreshes it the app makes some requests and the view updatings, but when I refresh like 4 or 5 times my requests that are in blocks of a withContext(<http://Dispatchers.IO|Dispatchers.IO>)
is not called but when I use my coroutine context it works...gildor
04/09/2019, 2:46 AMbloder
04/09/2019, 2:46 AMgildor
04/09/2019, 2:46 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
which is probably wrapping some blocking code, so request is probably not cancellablebloder
04/09/2019, 2:49 AMfun fetchInformation(informationType: InformationType = lastInformationType) = launch {
view?.showLoading()
view?.hideEmptyState()
view?.hideAddressEmptyState()
lastInformationType = informationType
val dishPartialInformationDeferred = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { // this block is not called when fetchInformation is called 4 or 5 times }
}
bloder
04/09/2019, 2:50 AMgildor
04/09/2019, 2:50 AMbloder
04/09/2019, 2:51 AMdishPartialInformationDeferred
withContext block is not called on 4 or 5 invoke of the functiongildor
04/09/2019, 2:51 AMgildor
04/09/2019, 2:51 AMgildor
04/09/2019, 2:52 AMbloder
04/09/2019, 2:53 AMgildor
04/09/2019, 2:57 AMfun fetchInformation(informationType: InformationType = lastInformationType) {
fetchJob?.cancel()
fetchJob = launch {
view?.showLoading()
…
}
}
bloder
04/09/2019, 2:58 AMgildor
04/09/2019, 3:02 AMbloder
04/09/2019, 3:04 AMbloder
04/09/2019, 3:05 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
is not been called and I'm cancelling the jobgildor
04/09/2019, 3:07 AMis not been calledHow do you check this?
gildor
04/09/2019, 3:07 AMgildor
04/09/2019, 3:07 AMgildor
04/09/2019, 3:08 AMbloder
04/09/2019, 3:13 AMasync(<http://Dispatchers.IO|Dispatchers.IO>)
stops on await
callbloder
04/09/2019, 3:16 AMgildor
04/09/2019, 3:17 AMgildor
04/09/2019, 3:17 AMgildor
04/09/2019, 3:18 AMgildor
04/09/2019, 3:18 AMexample if I useWhat do you mean?stops onasync(<http://Dispatchers.IO|Dispatchers.IO>)
callawait
bloder
04/09/2019, 3:18 AMbloder
04/09/2019, 3:19 AMgildor
04/09/2019, 3:21 AMgildor
04/09/2019, 3:22 AMare u cancelling all jobs including the jobs that are executed on IO context?Dispatcher is just about thread on which job will be called, cancellation strategy is the same. But blocking code by itself cannot be cancelled
bloder
04/09/2019, 3:22 AMbloder
04/09/2019, 3:24 AMgildor
04/09/2019, 3:24 AMbloder
04/09/2019, 3:24 AMbloder
04/09/2019, 3:24 AMgildor
04/09/2019, 3:25 AMgildor
04/09/2019, 3:25 AMgildor
04/09/2019, 3:25 AMbloder
04/09/2019, 3:25 AMgildor
04/09/2019, 3:25 AMprintln("Job: ${coroutineContext[Job]}")
gildor
04/09/2019, 3:27 AMgildor
04/09/2019, 3:28 AMbloder
04/09/2019, 4:05 AMbloder
04/09/2019, 4:05 AMgildor
04/09/2019, 4:11 AMgildor
04/09/2019, 4:12 AMbloder
04/09/2019, 4:15 AMbloder
04/09/2019, 11:28 AMbloder
04/09/2019, 11:29 AM