Async Reliability · 18 min · free with an account

Blocking in Async Code

Lesson preview · about 30%

Keep executor threads available to poll other futures.

Core idea

A blocking call occupies an executor worker without yielding, so unrelated tasks can stall.

Start with the idea

A blocking call occupies an executor worker without yielding, so unrelated tasks can stall. Move CPU-heavy or blocking work to a dedicated pool and await its result.

An executor worker can poll many async tasks because each task yields while waiting for nonblocking I/O. A synchronous sleep, filesystem call, expensive compression loop, or blocking foreign-library call can occupy that worker instead. Other ready tasks then wait even though they could run. Putting async on a function signature does not change a blocking call inside it into cooperative work.

Use the runtime's blocking pool or a dedicated worker thread for truly blocking operations, and pass owned input into it.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Concurrency & Async