Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Async
  2.     constructor: ->
  3.         @stack = []
  4.    
  5.     @IF: (condition, fn) ->
  6.         async = new Async
  7.         async.stack.push (next) ->
  8.             if condition then fn(next) else next()
  9.        
  10.         process.nextTick async.run.bind(async)
  11.         return async
  12.        
  13.     ELSEIF: (condition, fn) ->
  14.         @stack.push (next) ->
  15.             if condition then fn(next) else next()
  16.            
  17.         return this
  18.    
  19.     ELSE: (fn) ->
  20.         @stack.push fn
  21.         return this
  22.        
  23.     run: ->
  24.         stack = [@stack...]
  25.         do next = ->
  26.             fn = stack.shift()
  27.             fn(next)
  28.            
  29. module.exports = Async