Files: d2f2697f296dd39aed6a8b63c6d04a736a7db5b3 / node_modules / stream-to-pull-stream / test / test-stdout.js
861 bytesRaw
1 | |
2 | |
3 | //i saw bugs with streams to stdout not ending correctly. |
4 | //if there was a pause, it would not. |
5 | |
6 | |
7 | var cp = require('child_process') |
8 | var toPull = require('../') |
9 | var pull = require('pull-stream') |
10 | var split = require('pull-split') |
11 | |
12 | |
13 | console.log(process.execPath, [require.resolve('./stdout')]) |
14 | var child = cp.spawn(process.execPath, [require.resolve('./stdout')]) |
15 | child.on('exit', function () { |
16 | console.log('ended') |
17 | }) |
18 | pull( |
19 | toPull.source(child.stdout), |
20 | split('\n\n'), |
21 | pull.filter(), |
22 | pull.map(function (e) { |
23 | try { |
24 | return JSON.parse(e) |
25 | } catch (err) { |
26 | console.log(JSON.stringify(e)) |
27 | //throw err |
28 | } |
29 | |
30 | }), |
31 | pull.asyncMap(function (data, cb) { |
32 | setTimeout(function () { |
33 | cb(null, data) |
34 | }, 10) |
35 | }), |
36 | pull.drain(null, function (err) { |
37 | console.log('DONE') |
38 | if(err) throw err |
39 | console.log('done') |
40 | }) |
41 | ) |
42 | |
43 |
Built with git-ssb-web