npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

freeform

v0.2.3

Published

a small asynchronous task order manager

Downloads

22

Readme

freeform

Build Status

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 object
var freeform = require('freeform');
var form = freeform({
  // default; whether to use the name of the function to the put method if no
  // string name specified
  functionName: 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 task
function print(text) {
  return function(done) {
    console.log(text);
    done && done();
  };
}

form.put('redis', function(done) {
  client.quit(done);
});

form.before('redis', print('stopping redis'));
form.after('redis', print('redis stopped'));

form.put('unsubscribe', function(done) {
  client.unsubscribe();
  done();
}).goBefore('redis');

// print doesn't actually get a done() callback
form.run(print('all done'));
// 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 anything
form.put('hello');

// feel free to add a handler to an existing task, add as many as you want
form.put('hello', function(done) {
  // process some potentially asynchronous task
  // call done when completed
});

// define an anonymous task
form.put(function(done) {
  // ...
}).;

before(name|node, [fn])

Registers a new anonymous task which will run before the specified task. Returns an anonymous Node.

var fin = form.put('finally');

// these are functionally equivalent, if not very useful
form.before('finally');
form.before(fin);

// these are functionally equivalent
form.before('finally', function(done) {
  // ...
});

form.before(fin, function(done) {
  // ...
});

after(name|node, [fn])

Registers a new anonymous task which will run after the specified task. Returns an anonymous Node.

var begin = form.put('begin');

// these are functionally equivalent, if not very useful
form.after('begin');
form.after(begin);

// these are functionally equivalent
form.after('begin', function(done) {
  // ...
});

form.after(begin, function(done) {
  // ...
});

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.

function wait(time) {
  return function(done) {
    setTimeout(done, time);
  };
}

// each task "takes" one second
var second = wait(1000);

form.put('a', second); // not strictly necessary
form.put('b', second).after('a');
form.put('alpha', second).before('beta');
form.put('beta', second); // not strictly necessary

form.run(function() {
  // all done after 2000ms
  console.log('all done');
});

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.