0Pricing
Lua Academy · Lesson

Promise-Like Patterns

Implement deferred/promise objects using coroutines and callbacks.

What Is a Promise?

A promise represents a value that will be available in the future. It can be pending, fulfilled (with a value), or rejected (with an error).

Lua Promise Table

Implement a minimal promise as a table with state, value, and callback lists.

local function newPromise()
  return {
    state    = "pending",
    value    = nil,
    _resolve = {},
    _reject  = {},
  }
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