Gopal S Akshintala
08/23/2020, 6:14 AMdelay()
octylFractal
08/23/2020, 6:16 AMdelay
is actually one of the more complex bits, the specifics depend on the dispatcher you're usingoctylFractal
08/23/2020, 6:18 AMTimer
to schedule and execute delays
if you're on the Default dispatcher, it has its own scheduling logic that is very complex and can be viewed in kotlinx.coroutines.EventLoop
and other classesGopal S Akshintala
08/23/2020, 6:23 AMoctylFractal
08/23/2020, 6:25 AMoctylFractal
08/23/2020, 6:26 AMGopal S Akshintala
08/23/2020, 6:28 AMoctylFractal
08/23/2020, 6:30 AMGopal S Akshintala
08/23/2020, 6:33 AM<http://Dispatchers.IO|Dispatchers.IO>
how does "Thread doesn't block work? When I launch coroutines on <http://Dispatchers.IO|Dispatchers.IO>
it spawns a large pool of threads, which eventually block and wait for the data, right?octylFractal
08/23/2020, 6:34 AM<http://Dispatchers.IO|Dispatchers.IO>
does block, it's the exception to allow compatibility with blocking codeGopal S Akshintala
08/23/2020, 6:36 AM<http://Dispatchers.IO|Dispatchers.IO>
would allocate me one thread, which blocks on InputStream
, right?octylFractal
08/23/2020, 6:36 AMGopal S Akshintala
08/23/2020, 6:37 AMGopal S Akshintala
08/23/2020, 6:37 AMoctylFractal
08/23/2020, 6:38 AMGopal S Akshintala
08/23/2020, 6:42 AMGopal S Akshintala
08/23/2020, 6:42 AMoctylFractal
08/23/2020, 6:44 AMoctylFractal
08/23/2020, 6:45 AMsuspend
rather than blockGopal S Akshintala
08/23/2020, 6:47 AMGopal S Akshintala
08/23/2020, 6:48 AMoctylFractal
08/23/2020, 6:48 AMoctylFractal
08/23/2020, 6:49 AMDispatchers.Default
and <http://Dispatchers.IO|Dispatchers.IO>
may share threads, if needed they will use new ones to their pool limitGopal S Akshintala
08/23/2020, 6:50 AMoctylFractal
08/23/2020, 6:51 AMDefault
, that's part of the "lightweight" bit -- you don't really need a bunch of thread pools, you can mostly use the 2 given to youoctylFractal
08/23/2020, 6:52 AMoctylFractal
08/23/2020, 6:54 AMGopal S Akshintala
08/23/2020, 7:33 AM