Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (49 sloc) 1.461 kb

Futures-Luvit

A port of the popular FuturesJS to Lua/Luvit.

Sequence

Since then is a reserved word in Lua, the API has been changed ever so slightly.

local timer = require('timer')
local Sequence = require('sequence')
local s

s = Sequence:new()
s:next(function (cb) 
  print('one')
  timer.setTimeout(500, cb)
end)
s:next(function (cb) 
  print('two')
timer.setTimeout(100, cb)
end)
s:next(function () 
  print('three')
end)

API

  • next - enqueue a function to run once the previous function has called cb

Join

local timer = require('timer')
local Join = require('join')
local j

j = Join:new()
-- poop a new callback if you need one
timer.setTimeout(100, j:add())
-- or add callback you've already constructed
j:add(function (cb)
  timer.setTimeout(100, cb)
end)
-- and when all callbacks are done get the arguments back in the right order
-- Huzzah!
j:when(function (...)
  pp({...})
end)

API

  • add - accepts or poops a callback
  • when - enques a final callback to be called once all callbacks have completed

License

Copyright AJ ONeal 2012

This project is available under the MIT and Apache v2 licenses.

Jump to Line
Something went wrong with that request. Please try again.