(throwCodeInbetween)
| 3 | const stream = require('stream'); |
| 4 | |
| 5 | function test(throwCodeInbetween) { |
| 6 | // Check that a pipe does not stall if .read() is called unexpectedly |
| 7 | // (i.e. the stream is not resumed by the pipe). |
| 8 | |
| 9 | const n = 1000; |
| 10 | let counter = n; |
| 11 | const rs = stream.Readable({ |
| 12 | objectMode: true, |
| 13 | read: common.mustCallAtLeast(() => { |
| 14 | if (--counter >= 0) |
| 15 | rs.push({ counter }); |
| 16 | else |
| 17 | rs.push(null); |
| 18 | }, n) |
| 19 | }); |
| 20 | |
| 21 | const ws = stream.Writable({ |
| 22 | objectMode: true, |
| 23 | write: common.mustCall((data, enc, cb) => { |
| 24 | setImmediate(cb); |
| 25 | }, n) |
| 26 | }); |
| 27 | |
| 28 | setImmediate(() => throwCodeInbetween(rs, ws)); |
| 29 | |
| 30 | rs.pipe(ws); |
| 31 | } |
| 32 | |
| 33 | test((rs) => rs.read()); |
| 34 | test((rs) => rs.resume()); |
no test coverage detected
searching dependent graphs…