Parallell and serial asynchronous job management in NodeJS.
CoffeeScript JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

NodeJS Gulag

Parallell and serial asynchronous job management in Node.js written in CoffeeScript


Hello world with Node-Gulag:

var gulag = require('gulag')
gulag(function(c) {
    c.done('Hello') // Job 1 in group 1
}, function(c) {
    c.done(' world!') // Job 2 in group 1
}).then(function(c, msg1, msg2) {
    console.log(msg1 + msg2) // Group 2 with one job runs after group 1

An asynchronous example where two files are read simultaneously:

gulag(function(c) {
  fs.readFile('file1.txt', 'utf-8', function(err, data) {
    if (err) throw err;
}, function(c) {
  fs.readFile('file2.txt', 'utf-8', function(err, data) {
    if (err) throw err;
}).then(function(c, f1, f2) {
  console.log(f1) // Display the contents of file1.txt
  console.log(f2) // Display the contents of file2.txt


Each group consists of one or more jobs. Each group may optionally be assigned a name for easier access later.

gulag([name], fn, [fn...]) // First group of jobs
  .then([name], fn, [fn...]) // Second group
  .then([name], fn, [fn...]) // etc...
  .run([args...]) // Begin working (args goes to every job in first group)

Each function fn takes a controller c as it's first argument. The controller can be used in the following ways:

c.done([args...]) // Must be called when the job is done
c.retry([args...]) // Redo only this specific job
c.jump(name|id, [args...]) // Instantly jump to another group

The optional arguments args are a way of passing objects between groups of jobs. For example, c.done(p1, p2) will make sure that the next group of jobs all will recieve the variables p1 and p2.

Author and license

Node-Gulag, Copyright 2012, Didrik Nordström

Dual licensed under the MIT or GPL Version 3 licenses.