Building a Simple Event Loop
Implement a coroutine scheduler with a run queue and resume loop.
What Is an Event Loop?
An event loop runs a scheduler that resumes coroutines when their awaited events are ready. It enables multiple concurrent tasks without OS threads.
The Run Queue
Start with a queue of ready coroutines. Each tick, process all ready coroutines one by one.
local queue = {}
local function spawn(fn)
queue[#queue+1] = coroutine.create(fn)
endAll lessons in this course
- Building a Simple Event Loop
- Async/Await with Coroutines
- Promise-Like Patterns
- Non-Blocking I/O with luasocket