By implementing a fiber-based scheduler to eliminate explicit async/await, the author achieves a level of architectural elegance rarely seen in hobbyist language design. It is a rigorous exercise in systems engineering that prioritizes runtime intelligence over syntactic boilerplate.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Building an async runtime from scratch (was painful) (for my language)Added:
No, I did something that was so thought to be impossible by me beforehand, but no, not anymore. Not anymore. Anyways, take a look at this. So, this is a block in TCP server. What it does is it simulates a little shell for you. Uh, let me start this again cuz I I I figured out that I actually didn't record the last time, which was weird. I should have done that. You should probably hit record when you record a video. Uh, but that's my bad. All right.
So, what do you mean it's not found? Oh, I'm stupid. I'm super stupid. Let me run that. So, it's a it makes a little sub on HTTP uh on local host 6767. Then you can ping it. You can uh give it a message and it pings it back. But if you want to if you want to do a second connection, it just waits. It hangs until you close that connection. Now, to make this asynchronous, um you have to make a lot of modifications like adding this keyword and this just makes the server asynchronous which is insane. You just do blocking code and the blocking code becomes asynchronous by itself. Can you believe that? It is that simple. It is. Why does nobody do this? Your dynamic language JavaScript you can do that. You don't have to use async. This is that this is it is hello. But yeah, anyways, you can also you can do this to any ever anything ever. So uh anything that has an async backend to it uh like can be asynchronous as long as you make it asynchronous by default. So fn s uh no fn serve as f ser this port do end and then you move all of that logic from the top back here. Uh you ser it on the port and then you then you print it they on the port while true do accepts phone ser and let me give it a port. Let me give it the port as the counter. And let me actually remove that counter. Uh, and let me actually do port minus one. So that the first the first request, the first ping is going to be Oh, and I actually didn't spawn it. So nothing happened. But let me do spawn serve.
So then we do spawn serve uh at 6767.
And let me do two more servers actually.
676 8 and 67 69. We spawn. We just spawn on three servers. Zero cost. zero mental cost at least. Uh so we ping here and we ping at the higher one first. Ping pong 6768 ping 6767.
Uh every client has its own state as you've seen before. Let me actually RL wrap this as well. Uh so that I have my arrow keys. Ping ping ping ping ping. Uh different state. This is all you have to do. This is all you have to do. And the way this is done the way this is done is this is tightly integrated into theuler.
So whenever you hit so first of all this is all of fibers. So if you are familiar with go routines it's almost that it is almost that. So it's more it's less lightweight than fibers. It is more capable than fibers. It is more lightweight than go routines but it's less capable than go routines. You actually do have channels actually. Uh I don't know why I said that twice but you do you do have channels you can send to them. Uh that is what I'm going to do uh when I want uh like actual safety. Uh but that's that's not going to that's not going to happen today. You you do have channels though. Chan uh con C equals Chan. No, let's C equals Chan.
And then you can do something with it.
You you can you can just send send to C and then two. That's all you have to do here. Um anyways, how this works? How this works? This works based on a generic async like this little system.
So the scheduleuler has uh as many files as you want and when you hit this uh so this is IO um this like back in the implementation it sends a weight token in there and then it tries to put that like on the current fiber and when it puts it on the current fiber it yields.
Now the thing about yield is when you yield uh you will have to go to a different fiber. If there's no different fiber you just don't do anything. You plug the current fiber, you wait until it completes. That's all you can do.
That's all you can do. You pull it. You just pull it uh until it's done. Uh and that's that's just what it is. So it's not it doesn't behave exactly like blocking code. Uh and this code this code is actually non-blocking by default. It just looks blocking. Um and then when that completes uh you get back this whole thing. Uh and what's different about this? What's different about this? Uh is that generic actually?
So you have this weight token. So if you go into async backend.zig right here, you have an async job. It has a fiber ID to it. It has a kind. So a kind. So now we just have three of them, right? But it's not it's not going to be that hard to extend them. Um we have a file handle, which you know, obviously I'll have to do more I'll have to make more generic, but this is super like it it is super close to being generic. All right.
I'll I'll have to have somebody smart actually do that for me unfortunately.
Um message ID that's internal state and offset is internal state and then you have a buffer. So buffer buffer is just there for receive is is you know in my exp uh is kind of there until I actually finish it until I make it fully generic.
Um and the async back back end has to implement all of that. So you can actually implement io uring instead of this. So right now it just runs on pole.
If you're familiar with postix pole, it uses that not eol cuz that's specific to Linux, not urine because that's specific to Linux, not KQ cuz that's specific to Mac OS. And I'm the only user here that uses Mac OS actually. Uh, and I do
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
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
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











