-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparallel1.js
More file actions
30 lines (27 loc) · 736 Bytes
/
parallel1.js
File metadata and controls
30 lines (27 loc) · 736 Bytes
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
var capitalize = function(text, callback) {
setTimeout(function (text) {
try {
callback(null, text.toUpperCase());
} catch (exception) {
callback(exception);
}
}, 100, text);
};
var words = ['one', 'two', 'three', 'four', 'five'];
var upcasedWords = [];
// bad, don't do this
words.forEach(function (word) {
capitalize(word, function(err, word) {
upcasedWords.push(word);
});
});
console.log('Done, upcased words: <' + upcasedWords.join(' ') + '>');
var count = words.length;
words.forEach(function (word) {
capitalize(word, function(err, word) {
upcasedWords.push(word);
if (--count === 0) {
console.log('Done, upcased words: <' + upcasedWords.join(' ') + '>');
}
});
});