forked from slavaGanzin/async-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.js
35 lines (28 loc) · 840 Bytes
/
async.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
'use strict';
const fs = require('fs');
const path = require('path');
const async = require('async');
const S = require('sanctuary');
const readFile = (filename, callback) => {
fs.readFile(filename, {encoding: 'utf8'}, callback);
};
const main = () => {
const dir = process.argv[2];
readFile(path.join(dir, 'index.txt'), (err, data) => {
if (err != null) {
process.stderr.write(String(err) + '\n');
process.exit(1);
}
const filenames = S.lines(data).map(s => path.join(dir, s));
async.map(filenames, readFile, (err, results) => {
if (err != null) {
process.stderr.write(String(err) + '\n');
process.exit(1);
} else {
process.stdout.write(results.join(''));
process.exit(0);
}
});
});
};
if (process.mainModule.filename === __filename) main();