|
|
|
|
|
by clavigne
1024 days ago
|
|
> I'm not talking about whether the scheduler can block the task on IO. This is trivial. The whole point of coroutines is that they are trivial to block and resume, right? So the way to deal with limited resources... is to block on them. So when you need a connection, you await until one from the pool becomes available. From the point of view of the consumer it's very natural because grabbing a connection is just a standard async call, and returning it to the pool can be done the same way you would usually close it. If anything, it's a lot easier to manage them like this because unlike in a non async program you don't have to worry too much about blocking progress. |
|
On the other hand, with threads the IO block is a "proper" block. No new task will be scheduled, the thread will only continue when the IO operation finishes, providing a very natural backpressure mechanism that prevents overallocation/contention.