A sobering reminder that even the most sophisticated Rust architects often trip over basic runtime hygiene. Your "high-performance" async code is just one lazy synchronous call away from total paralysis.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
You’re Blocking Rust Without Knowing ItAdded:
Hello and welcome back to yet another interesting video on this channel. In today's video, we'll discuss how blocking kills async rust. We'll visualize the problem, understand, and then discuss the solution. So, if you want to program async rust like pro, make sure you stick around and watch till the end. First of all, let's understand the problem. How blocking task kills async operation.
Right here, we have asynchronous task where we simulate with a sleep. Think of it as some fetch, some DB call, or sending out an email. And then we have blocking task. Think of it as a sleep or wait or some synchronous file IO or even some heavy CPU operation. Now, here we are using thread sleep, which is blocking.
And then right here for simulation, we are using Tokyo sleep, which is an asynchronous analog of thread sleep.
So, right here, we'll just build some task and we'll simulate some asynchronous task. And there we have a blocking operation.
And then we have Tokyo join with async task one, async task two, and then there's a blocking task.
And if you have been programming async rust or following my channel for some time now, we already have discussed Tokyo join.
But just for a reminder, Tokyo join runs multiple asynchronous task concurrently on the same thread and waits for all of them to complete returning their results.
Now, let's see what happens. Like, do the asynchronous task just execute without getting blocked? Or because they are part of same join, are they getting blocked? Let's see. Let's try to run this.
There you go. Task one, task two, and then there's a blocking.
For how much? For 5 seconds we were blocked.
Blocking task started, blocking task finished, and only then our asynchronous task could continue. Now, think of the problem that we were simulating or discussed in the start. Your blocking task may be just writing some logs to your file. And then you have your asynchronous task sending out emails.
So, by the time you are not able to complete the IO or your blocking task, all the asynchronous task are blocked, meaning the emails that you are sending out, the requests that you are sending out, the DB calls that you're making, all of them were blocked until your blocking task could finish.
So, this is a serious problem. If you are someone really looking to ace up your rust programming and go to pro level, how do you solve this?
Well, let's discuss the solution.
Everything else remains as it is. Our asynchronous task, our main remains as it is. The only part we change is the blocking task.
Previously, we were just having this statement, which is our blocking task itself. [clears throat] As I mentioned, it's a simulation of something which is blocking by wait or sleep, but you can have some heavy CPU operation or some IO.
And then everything else remains same.
But what we did is we wrapped it and spawn black blocking. And then we await and unwrap and just finish the blocking task. Now, first of all, let's run this and see difference visualize. And then we discuss how spawn blocking solves this problem and how does it work internally.
And now if we run this, there you go. Task one ticked, task two ticked, blocking started, but everything else continued and blocking task finished because blocking task took 5 seconds and other task, the async task, are just 200 milliseconds.
That's not the point. The point is that blocking task started, but it didn't block the execution completely for our asynchronous task as well. Asynchronous task still continued to execute. And when blocking task finished, that's the That's the point when our Tokyo join completely finished all the task.
So, how does this work?
So, what happens here is spawn blocking runs the blocking sleep right here, which again could be any blocking operation, on a separate thread pool. So, your async runtime doesn't freeze. Then waits for it to finish.
And how spawn blocking works is it basically offloads your blocking code, which could be anything that you write in between this bracket, which could be your blocking code.
So, spawn blocking would offload that code to Tokyo's dedicated blocking thread pool and returns a future, so you can wait. So, basically, what happens is this is executed on a separate thread pool, a dedicated thread pool for blocking task, while your async operations can continue and you get a future, which again then you can await and return. So, that's why now our execution was not blocked and we were able to successfully return or execute asynchronous task while blocking task was executing concurrently.
So, these are small optimizations, as you can see, it's just a one-liner, but it literally changed how your code executes now. It literally changes entirely your program execution time and all those stuff.
Because now, since your async operations are not blocked, meaning your async operations can continue.
So, that's it for this video, guys. I hope you guys learned something new. If you do, try it out on your end. And don't worry about the code. I'll post a link in the description to my GitHub, where you can find the code used in this video. I'll catch you guys in another video with another interesting topic.
Until then, bye-bye.
Related Videos
resume fixed instantly 😭 Comment “app”andI’ll sendyou the link #parakeetaipartnership #resumetips
Ritcareer
686 views•2026-05-31
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
Making Minecraft Clone with C++ & Raylib
PecaCSLive
686 views•2026-06-04
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











