asad.awadia
07/31/2018, 10:48 PMlouiscad
07/31/2018, 11:16 PMsuspend fun
are allowed to do so.asad.awadia
07/31/2018, 11:51 PMVsevolod Tolstopyatov [JB]
08/01/2018, 4:57 AMBut apparently - go runtime can detect blocking calls and offload them into its own worker pool?Something like this, it has all its syscalls instrumented at runtime level. When blocking syscall is detected, current thread offloads all its work to another thread and signals that it is “blocking” (so runtime can create or unpark one more thread)
we make our own fixedThreadPool.asCoroutineDispatcher and run it on thatMore or less, depending on your blocking frequency and CPU-load. Latest release has experimental dispatcher, which has smarter blocking code execution (though you still should directly mark code as blocking)
dekans
08/01/2018, 9:46 AMgo function()
is launch { function() }
asad.awadia
08/04/2018, 12:42 PMVsevolod Tolstopyatov [JB]
08/04/2018, 3:37 PMbuildSequence
. Is it a wrapper over callback? Is suspend fun foo(): Unit
a wrapper over callback?
Coroutines allow to translate callback-based code to “sequential”-ish, but it’s not a syntactic sugar to avoid callbacks, it’s something bigger (continuation
and therefore to handy features as buildSequence
, generators or Erlang-like state machineslaunch
have roughly the same footprintasad.awadia
08/04/2018, 3:48 PMVsevolod Tolstopyatov [JB]
08/04/2018, 4:23 PMX
doesn’t automatically means that the feature is a syntactic sugar over X
🙂
at the end of the day you are still blocking - just blocking another threadYes.
The code inside still needs to be non blocking?For Go it doesn’t matter. Go detects blocking calls from runtime and offloads them to “blocking” threadpool (kind of, Go scheduler is a bit more complicated). For
kotlinx.coroutines
-- yes, or you should offload blocking calls to another threadpool.
For n threads - launching n+1 coroutines that all have blocking work - the last 1 coroutine has to wait yes?Yes.
asad.awadia
08/04/2018, 4:58 PMVsevolod Tolstopyatov [JB]
08/04/2018, 5:15 PM