forked from slavaGanzin/async-problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync-seq.js
More file actions
33 lines (29 loc) · 767 Bytes
/
async-seq.js
File metadata and controls
33 lines (29 loc) · 767 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
31
32
33
const fs = require('fs');
const path = require('path');
const async = require('async');
const R = require('ramda');
const S = require('sanctuary');
const sync = (f) => (values, cb) => cb(null, f(values))
const join = (x, cb) => cb(null, path.join(process.argv[2], x));
const map = R.flip(async.map);
const output = (err, results) => {
if (err != undefined) {
process.stderr.write(String(err) + '\n');
process.exit(1);
} else {
process.stdout.write(results);
process.exit(0);
}
}
const main = () => {
async.seq(
join,
fs.readFile,
sync(String),
sync(S.lines),
map(join),
map(fs.readFile),
(files, cb) => cb(null, files.join(''))
)('index.txt', output)
}
if (process.mainModule.filename === __filename) main();