0Pricing
Lua Academy · Lesson

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)
end

All lessons in this course

  1. Building a Simple Event Loop
  2. Async/Await with Coroutines
  3. Promise-Like Patterns
  4. Non-Blocking I/O with luasocket
← Back to Lua Academy