Skip to content

Instantly share code, notes, and snippets.

@nakamura-to
Created February 1, 2012 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakamura-to/1717789 to your computer and use it in GitHub Desktop.
Save nakamura-to/1717789 to your computer and use it in GitHub Desktop.
nue v0.0.2 sample
var nue = require('nue');
var serial = nue.serial;
var serialEach = nue.serialEach;
var parallel = nue.parallel;
var parallelEach = nue.parallelEach;
var start = nue.start;
start(serial(
function () { console.log('a'); this.next(); },
function () { console.log('b'); this.next(); },
function () { console.log('c'); this.next(); },
parallel(
function () { this.fork('f', 'e', 'd'); },
[
function (arg) { var self = this; setTimeout(function() { console.log(arg); self.join();}, 30); },
function (arg) { var self = this; setTimeout(function() { console.log(arg); self.join();}, 20); },
function (arg) { var self = this; setTimeout(function() { console.log(arg); self.join();}, 10); }
],
function () { console.log('g'); this.next(); }
),
function () { console.log('h'); this.next()},
parallelEach(
function () { this.begin('i', 'j', 'k'); },
function (arg) { console.log(arg); this.join(); },
function () { console.log('l'); this.next(); }
),
serialEach(
function () { this.begin('m', 'n', 'o'); },
function (arg) { console.log(arg); this.next(); },
function () { console.log('p'); this.next(); }
),
function () { console.log('q');}
));
/* RESULT
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment