Parallel asynchronous functions made funky!
Switch branches/tags
Nothing to show
Pull request Compare This branch is 3 commits behind masylum:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

 ,dPYb,                           ,dPYb,
 IP'`Yb                           IP'`Yb
 I8  8I                           I8  8I
 I8  8'                           I8  8bgg,
 I8 dP  gg      gg   ,ggg,,ggg,   I8 dP" "8
 I8dP   I8      8I  ,8" "8P" "8,  I8d8bggP"
 I8P    I8,    ,8I  I8   8I   8I  I8P' "Yb,
,d8b,_ ,d8b,  ,d8b,,dP   8I   Yb,,d8    `Yb,
PI8"8888P'"Y88P"`Y88P'   8I   `Y888P      Y8
 I8 `8,
 I8  `8,
 I8   8I
 I8   8I
 I8, ,8'

Asynchronous functions made funky!

What the funk?

funk will not:

  • Make you code asynchronous as if it where synchrnous.
  • Add overhead to your application.
  • funk and revolution will not be televised.

funk will:

  • Make your asynchronous code easier to code.
  • Make your code more readable.
  • funk will make your sexual life more interesing. Try some James Brown when you get laid.


npm install funk


funk usage is really simple. You don't need to learn DSLs or weird system, just wrap your callbacks and let the groove do the rest.

  • set(name, value): Save results that will then be recovered o the serial or parallel callback.
  • get(name): Retrieve results previously saved.
  • add(function): Adds the function to funk.
  • nothing(): Adds the function to funk without setting any result.
  • result(name, value): Adds the function to funk and sets the value.
  • parallel(callback): Will run all the added functions in parallel and call callback when all are done. this holds all the results setted with set.
  • serial(callback): Will run all the added functions in serial and call callback when all are done. this holds all the results setted with set.

Parallel example

Funk is really useful when you need to do something after a bunch of asynchronous callbacks are called.

var funk = require('funk')(),
    assert = require('assert'),
    fs = require('fs');

funk.set('results', []);

fs.readFile("dance_moves/james_brown.txt", funk.add(function (er, data) {

fs.readFile("dance_moves/jackson_5.txt", funk.add(function (er, data) {

setTimeout(funk.result('foo', 'bar'), 200);

  assert.equals(this.moves.length, 2);
  assert.equals(, 'bar');
  assert.equals(funk.get('foo'), 'bar');
  console.log('This is funktastic!');

Serial example

Dealing with nested callbacks can sometimes be a PITA. funk will ease the pain.

var funk = require('funk')(),
    assert = require('assert'),
    order = 0;

setTimeout(funk.add(function () {
  funk.set('order_first', order);
}), 200);

setTimeout(funk.add(function () {
  this.order_second = order;
}), 5);

  assert.equals(this.order_first, 1);
  assert.equals(this.order_second, 2);


funk is fully tested using testosterone.

npm install testosterone

In order to run the tests type: