Flow-coffee
Original idea: flow-js. You can read about the concept there.
This version is rewritten in coffee using prototypes. It contains some extra features mostly needed for costa.
No js version
There is no js version. Just require('coffee-script')
before
require('flow-coffee')
.
Extra features
Custom context
obj = : -> # ... do context: obj blocks: # If context is specified last argument is always a flow instance @ == obj # true cb # It's callback do cb_multi = cbmulti -> # multi is also available setImmediate -> cb_multi # ... 'someMethod' # calls method from context # other callback
downcase
REWIND
, MULTI
, TIMEOUT
are now rewind
, multi
& setTitmeout
.
Old names are left for compatibility.
#define()
returns just function
f = flowdefine -> fexec # removed. no one used i think f # keep it simple
prototype's aftermath
This version works only on engines that support __proto__
(v8 & rhino do).
Now it does mater what context you call multi
, setTimeout
and other methods.
flowexec -> multi = @multi ... -> func multi # wrong -> state = @ ... -> func statemulti # ok
@multi()
is called, not callbacks
Multiple results are stored in the order the nt = proccessnextTickit 'should preserve results order' run = flowexec -> do cb = @multi -> nt -> nt -> runpush 1; cb 1 # this will be ready first: do cb = @multi -> nt -> runpush 2; cb 2 assertdeepEqual run21 assertdeepEqual x0for x in results12 @ cb
@multi
is called with 2 arguments
Function after It's incompatible with original flow, but I've found it very convenient.
First argument is set to the first error passed to any @multi()
. Second is the original results array.
Callback on any error
flowexec -> @ null'test' # strips first (error) arguments for usual callbacks assertequal arg'test' setImmediate => @ 'error' -> # this won't run error # this will run # resume flow with @()