This might be a very basic question in terms of Asynchronous Programming, but I tried reading about it and couldn't find any resource for the same.
Assumption: A general idea I have about asynchronous programming:
When we start a blocking operation(networks call, reading from DB/file), we can delegate it to Kernel thread(s) which will keep our application thread(s) free for other jobs. The kernel thread waits for the job to be done and gives a callback to the application thread whenever the job is done.
Coroutines: I have been reading about Kotlin Coroutines for last few days. I think the concept wise coroutines are language agnostic though. The question I have been getting is:
How the suspension
and continuation
takes place for a co-routine. Coroutines are not threads(which are given a slice of the processor by OS), they are tasks
which will be scheduled on a thread to be executed.
Who keeps looking for the program in execution and say, this coroutine has hit a suspension point and it should be taken out of thread. Another coroutine which needs to be resumed from continuation
should be scheduled on the thread. As for as I have read about Java Fibers
it will be done by a Fiber Scheduler
, is it similar in Kotlin?
Thank for the help in advance.