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

flow-builder

v1.4.2

Published

define and execute tasks in a simple way

Downloads

15

Readme

flow-builder

define and execute tasks in a simple way.

what is it good for

flow-builder lets you define a work flow that works well with tasks with a defined API. it gives you a simple building block to handle tasks that depend on other tasks. tasks will most likely be asynchronous, but it can be used for synchronous tasks as well.

when not to use it

whenever your tasks don't have a unified API (function name and function signature).

install

npm install flow-builder

use

example



var Flow = require('flow-builder');
var flow = new Flow();

// define flow
flow
  .parallel('header', task('ADD A HEADER'))
  .parallel('footer', task('ADD A FOOTER'))
  .series('content', task('ENTER CONTENT'));

// handle flow events
var results = {};
flow
  .task(function(name, item, callback) {
    item.doSmartThing(results, function(err, result) {
      results[result] = result + ' DONE';
      callback(err);
    });
  })
  .group(function(err, group, callback) {
    console.log('group finished', group);
    callback(err);
  })
  .done(function(err) {
    if (err) return console.log('failed');
    console.log('all done', results);
  });

// start flow
flow.exec();


// example task
var projectHistory = [];
function task(todo) {
  return {
    doSmartThing: function(list, callback) {
      projectHistory.push(todo);
      callback(null, todo);
    }
  }
}

flow definition

the flow is basically executed in the order the definition methods are called.

automatic group creation

  • flow groups are created automatically, depending on your definition.
    • all eventually tasks will be in the same group: started immediately, and evaluated at the final callback (done).
    • series tasks added in a row will create a new series group.
    • parallel tasks that are added in a row will create a new `parallel group.
  • when ever you add a different task e.g. parallel after series or vice versa, a new group is being created automatically.
  • the next group is only started after the previous group has finished.

arguments the flow definition methods take any and as many arguments as you like. the provided arguments will be emitted in the task event, to let you handle the task execution. the only thing to consider is, that the arguments should be consistent in every definition method for the same flow.

the methods return this and are chainable.

methods

series([args..])

aliases: eachSeries, eachSync, sync

these tasks will execute in the defined order. the next task that was defined with series will be executed only after the previous one has finished.

parallel([args..])

aliases: each

these tasks will start their execution together. if series tasks have been defined before, they will finish first. after the defined parallel tasks in the same group

eventually([args..])

aliases: long

these tasks will be started immediately and evaluated only at the final callback (done), when the whole task flow has finished.

flow execution method

exec()

aliases: execute

start the flow execution

forEach(callback)

iterates over the defined tasks.

callback(args, stepIndex, groupName, groupIndex)

events

task

called on every defined flow execution step (task) call the callback function when the task is done callback() or when an error occured callback(err).

arguments: [args...,] callback

  • args arguments as they were defined with series, parallel or eventually.
  • callback(err)

group

called every time a defined group has finished call the callback function when the task is done callback() or when an error occured callback(err). when the callback(err) is called with a truthy err, the flow is stopped and done err is emited.

arguments: err, group, callback

  • err error
  • group definition as array [name, [steps...]] where steps are the defined arguments
  • callback(err)

done

called at the very end of the flow execution (final callback)

arguments: err

  • err truthy when an error occured

test

npm test

license

MIT