0.0.1 • Published 12 years ago
gulag v0.0.1
NodeJS Gulag
Parallell and serial asynchronous job management in Node.js written in CoffeeScript
Examples
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
c.done()
}).run()
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;
c.done(data)
})
}, function(c) {
fs.readFile('file2.txt', 'utf-8', function(err, data) {
if (err) throw err;
c.done(data)
})
}).then(function(c, f1, f2) {
console.log(f1) // Display the contents of file1.txt
console.log(f2) // Display the contents of file2.txt
c.done()
}).run()
Usage
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.
0.0.1
12 years ago