freeform
A small asynchronous task order manager, primarily for decoupled shutdown handling. This involves a mechanism to define a losely ordered sequence of potentially asynchronous tasks.
Test
Run any of the following:
$ mocha$ npm test$ make test
Note: remember to npm install
!
Install
$ npm install freeform
API
// create function optionally takes an options objectvar freeform = ;var form = ; // just print text instead of running a task { return { console; done && ; };} form; form;form; form; // print doesn't actually get a done() callbackform;// runs synchronously because individual tasks are synchronous
put([name], [fn])
Registers a new named task. Returns a named Node.
// define a hello task which doesn't actually do anythingform; // feel free to add a handler to an existing task, add as many as you wantform; // define an anonymous taskform;
before(name|node, [fn])
Registers a new anonymous task which will run before the specified task. Returns an anonymous Node.
var fin = form; // these are functionally equivalent, if not very usefulform;form; // these are functionally equivalentform; form;
after(name|node, [fn])
Registers a new anonymous task which will run after the specified task. Returns an anonymous Node.
var begin = form; // these are functionally equivalent, if not very usefulform;form; // these are functionally equivalentform; form;
run(complete)
Runs the contained tasks in-order, call the complete
callback once finished. The system cannot be run multiple times concurrently. Call reset()
to allow the system to run again.
{ return { ; };} // each task "takes" one secondvar second = ; form; // not strictly necessaryform;form;form; // not strictly necessary form;
reset()
Resets the statuses of all tasks and the system as a whole.
node.goBefore(name|node)
Specifies that the node should run before the named node.
Aliased as node.before
.
node.goAfter(name|node)
Specifies that the node should run after the named node.
Aliased as node.after
.
License
The MIT License (MIT)
Copyright © 2013 GlobeSherpa
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.