Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mirek/node-flat-flow
Tiny flow.
https://github.com/mirek/node-flat-flow
Last synced: about 1 month ago
JSON representation
Tiny flow.
- Host: GitHub
- URL: https://github.com/mirek/node-flat-flow
- Owner: mirek
- License: mit
- Created: 2014-06-29T15:28:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-31T13:42:10.000Z (over 9 years ago)
- Last Synced: 2024-10-12T23:38:17.645Z (2 months ago)
- Language: CoffeeScript
- Homepage:
- Size: 258 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Summary
Tiny flow with conditional branching.
## Installation
npm install flat-flow --save
## Usage
{ flow } = require 'flat-flow'
# This is how to use me.
flow [# 1-arity functions are called and result from (err, result) merged with locals.
# If you pass an error as first arg, the whole flow will be finished, see the bottom.
(done) ->
done null, { a: 1, b: 2 }# 0-arity functions that return boolean manage the flow; false will all calls until true is found in 0-arity.
-> false# Will be skipped.
(done) ->
done null, { c: 3 }# Resume flow. You have access to locals merged before.
-> @a is 1# Will be called because we resumed the flow above.
(done) ->
done null, { e: @a + @b }# 2-arity functions allows you to refer to locals if you don't want to bind all nested functions.
(done, { e }) ->
process.nextTick ->
process.nextTick ->
done null, { f: e + 1 }# ...otherwise you can use locals directly
(done) ->
process.nextTick => # fat
process.nextTick => # fat
done null, { g: @f + 1 }], (err, { e, f }) -> # final callback, always called.
assert.ifError err# Locals are here as well.
assert.equal @a, 1
assert.equal @b, 2
assert.equal @c, undefined
assert.equal @d, undefined# Or you can access them from optional 2nd argument.
assert.equal e, 3
assert.equal f, 4assert.equal @g, 5