Lua promises
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
spec
src
LICENSE
README.md
promise-0.1-0.rockspec

README.md

promise

Lua promises

Supports lua coroutines and nginx light threads

local p = require 'promise'()
local id = p:start(function() return 'foo', 'bar' end)
local foo, bar = p:fetch(id)

if not foo then error(bar) end

id = p:start(function() return 'foo', 'bar' end)
local id2 = p:start(function() return 'baz', 'bat' end)

local results = p:all()

local firstResults = results[id]
local secondResults = results[id2]

id = p:start(function() return 'foo', 'bar' end)
local id2 = p:start(function() return 'baz', 'bat' end)

while true do
  local id, foo, bar = p:first()
  if not id then break end
  print(foo)
  print(bar)
end