a small asynchronous task order manager
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.
Run any of the following:
$ mocha$ npm test$ make test
Note: remember to
$ npm install freeform
// create function optionally takes an options objectvar freeform = require'freeform';var form = freeform// default; whether to use the name of the function to the put method if no// string name specifiedfunctionName: false// whether to collect errors in an object or immediately interrupt the process// when an error occurs (default)collectErrors: false;// just print text instead of running a taskreturnconsole.logtext;done && done;;formput'redis'clientquitdone;;formbefore'redis' print'stopping redis';formafter'redis' print'redis stopped';formput'unsubscribe'clientunsubscribe;done;goBefore'redis';// print doesn't actually get a done() callbackformrunprint'all done';// runs synchronously because individual tasks are synchronous
Registers a new named task. Returns a named Node.
// define a hello task which doesn't actually do anythingformput'hello';// feel free to add a handler to an existing task, add as many as you wantformput'hello'// process some potentially asynchronous task// call done when completed;// define an anonymous taskformput// ...;
Registers a new anonymous task which will run before the specified task. Returns an anonymous Node.
var fin = formput'finally';// these are functionally equivalent, if not very usefulformbefore'finally';formbeforefin;// these are functionally equivalentformbefore'finally'// ...;formbeforefin// ...;
Registers a new anonymous task which will run after the specified task. Returns an anonymous Node.
var begin = formput'begin';// these are functionally equivalent, if not very usefulformafter'begin';formafterbegin;// these are functionally equivalentformafter'begin'// ...;formafterbegin// ...;
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.
returnsetTimeoutdone time;;// each task "takes" one secondvar second = wait1000;formput'a' second; // not strictly necessaryformput'b' secondafter'a';formput'alpha' secondbefore'beta';formput'beta' second; // not strictly necessaryformrun// all done after 2000msconsole.log'all done';;
Resets the statuses of all tasks and the system as a whole.
Specifies that the node should run before the named node.
Specifies that the node should run after the named node.
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.