kuji

0.0.4 • Public • Published

kuji

Asynchronous Control Flow library for Node.

Browsers are not supported yet, it will be added later.

Control Flow

kuji.inline

kuji.inline runs tasks in-line:

Inline Timeline Example

var kuji = require('kuji');
 
kuji.inline([
  function (next) {
    next();
  },
  function (next) {
    next();
  },
  function (next) {
    next();
  },
  function (next) {
    next();
  }
]);
 

kuji.parallel

kuji.parallel runs tasks in parallel and goes to the final callback when all tasks finished:

Parallel Timeline Example

var kuji = require('kuji');
 
kuji.parallel([
  function (next) {
    next();
  },
  function (next) {
    next();
  },
  function (next) {
    next();
  },
  function (next) {
    next();
  }
], function () {
  // This will be executed when all will be finished
});

kuji.graph

kuji.graph permits you to easily run tasks graphs:

Graph Timeline Example

You can see that D will be executed once its dependencies (A and B) are finished, permitting you to be sure that the data you need from these tasks will be available.

For the moment you need to use a closure to share data between tasks, but this will be patched in the next few days.

var kuji = require('kuji'),
    dependsOn = kuji._dependsOn;
 
kuji.graph({
  a: function (next) {
    next()
  },
  b: function (next) {
    next();
  },
  c: function (next) {  
    next();
  },
  d: dependsOn(['a', 'b'], function (next) {
    next();
  }),
  e: dependsOn(['d', 'c'], function (next) {
    next();
  })
}, function () {
  // This will be executed at the end of your graph
});
 

Coming next

  • Error handling through next()
  • Passing values through next()
  • Benchmark
  • Perfomance optimization

Testing

To run the tests :

mocha

License

MIT

/kuji/

    Package Sidebar

    Install

    npm i kuji

    Weekly Downloads

    1

    Version

    0.0.4

    License

    MIT

    Last publish

    Collaborators

    • kube