julioyg
04/23/2018, 1:55 PMgildor
04/23/2018, 1:58 PMgildor
04/23/2018, 2:00 PMjulioyg
04/23/2018, 2:03 PMigorvd
04/23/2018, 2:03 PMasync { call.execute() }.await()
julioyg
04/23/2018, 2:11 PMHowever, when this Job is not backed by a coroutine, like CompletableDeferred or CancellableContinuation (both of which do not posses a cancelling state), then the value of onCancelling parameter is ignored.
does that mean that code inside your registerOnCompletion
won't be executed until the request finishes?gildor
04/23/2018, 2:12 PMgildor
04/23/2018, 2:15 PMgildor
04/23/2018, 2:20 PMgildor
04/23/2018, 2:23 PMjulioyg
04/23/2018, 2:24 PMigorvd
04/23/2018, 2:27 PMgildor
04/23/2018, 2:33 PMwhen my pool is reached, the others coroutines would need to wait for some thread to be released, right@igorvd Correct, even non-blocking coroutines will wait. This is the reason why you shouldn’t block threads in default dispatcher, because all coroutines use it by default, and probably all non blocking ones If you want to use coroutines to wrap blocking call (similar what you could do with standard thread), just use custom dispatcher, for example for blocking DB or network requests create new dispacther using builder
newFixedThreadPoolContext
or Executor.asCoroutineDispatcher
extension method, so it will be safe to block thread on this thread pool
Default CommonPool dispatcher has only cpuNumber - 1
threads and intended to use only for non-blocking callsigorvd
04/23/2018, 2:41 PMgildor
04/23/2018, 2:48 PMigorvd
04/23/2018, 2:55 PMcoroutines-guide
. I haven't looked into the informal
one. I will read and watch the talk. Thank you very much 😃gildor
04/23/2018, 3:08 PMgildor
04/23/2018, 3:14 PMgildor
04/23/2018, 3:16 PMjulioyg
04/24/2018, 8:44 AM