-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
41 lines (36 loc) · 893 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var Flow = require('flow-builder');
var flow = new Flow();
// define flow
flow
.parallel('header', task('ADD A HEADER'))
.parallel('footer', task('ADD A FOOTER'))
.series('content', task('ENTER CONTENT'));
// handle flow events
var results = {};
flow
.on('task', function(name, item, callback) {
item.doSmartThing(results, function(err, result) {
results[result] = result + ' :: DONE';
callback(err);
});
})
.on('group', function(err, group, callback) {
console.log('group finished', group);
callback(err);
})
.on('done', function(err) {
if (err) return console.log('failed');
console.log('all done', results);
});
// start flow
flow.exec();
// example task
var projectHistory = [];
function task(todo) {
return {
doSmartThing: function(list, callback) {
projectHistory.push(todo);
callback(null, todo);
}
}
}