
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.64 KB | hits: 14 | expires: Never
class Async
constructor: ->
@stack = []
@IF: (condition, fn) ->
async = new Async
async.stack.push (next) ->
if condition then fn(next) else next()
process.nextTick async.run.bind(async)
return async
ELSEIF: (condition, fn) ->
@stack.push (next) ->
if condition then fn(next) else next()
return this
ELSE: (fn) ->
@stack.push fn
return this
run: ->
stack = [@stack...]
do next = ->
fn = stack.shift()
fn(next)
module.exports = Async