-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilewrite.js
More file actions
45 lines (39 loc) · 1.15 KB
/
filewrite.js
File metadata and controls
45 lines (39 loc) · 1.15 KB
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
42
43
44
45
function doSomethingOnceAllAreDone() {
console.log('Everything is done.');
}
function Item(delay) {
this.delay = delay;
}
Item.prototype.someAsyncCall = function(callback) {
var temp = this;
console.log('Item Started', temp.delay);
setTimeout(function() {
console.log('Item is done. -------', temp.delay);
if (typeof callback === 'function') callback();
}, this.delay);
};
var items = [];
items.push(new Item(1000));
items.push(new Item(200));
items.push(new Item(500));
var async = require('async');
const fse = require('fs-extra');
var asyncTasks = [];
var outPath = './build/';
var name = 'file';
var ext = 'txt';
items.forEach(function(item) {
asyncTasks.push(function(callback) {
item.someAsyncCall(function() {
try {
fse.outputFileSync(outPath + name + item.delay + '.' + ext, item.delay);
} catch (error) {
console.log('Error writing Component file ' + name + ': ' + error);
}
callback();
});
});
});
async.parallel(asyncTasks, function() {
doSomethingOnceAllAreDone();
});