From c64aa2ea715bc0e2c98ffafee8925a7f6d10033e Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 1 May 2018 15:32:09 +0100 Subject: [PATCH] WIP 5 --- lib/readable.js | 1 + lib/writable.js | 1 + test/all.test.js | 29 ----------------------------- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/lib/readable.js b/lib/readable.js index aae1e35..c06cdd1 100644 --- a/lib/readable.js +++ b/lib/readable.js @@ -89,6 +89,7 @@ function _read(size) { } function readStdout(duplex, size) { + // TODO Ensure doesn't read again while awaiting 'readable' event console.log('------------'); console.log(`readStdout() called: size ${size}`); diff --git a/lib/writable.js b/lib/writable.js index 1fbec07..980d1fb 100644 --- a/lib/writable.js +++ b/lib/writable.js @@ -111,6 +111,7 @@ function writeStdin(duplex, chunk, cb) { if (keepWriting) return cb(null); // Stdin needs to drain - callback only once drained or stdin errors + // TODO Move listeners to be global rather than adding and removing function done(err) { stdin.removeListener('drain', done); stdin.removeListener('error', done); diff --git a/test/all.test.js b/test/all.test.js index b7a5a7b..6fefc17 100644 --- a/test/all.test.js +++ b/test/all.test.js @@ -22,33 +22,4 @@ describe('Tests', function() { it.skip('dummy', function() { expect(DuplexChild).to.be.ok; }); - - it('check Readable', function(cb) { - const {Readable} = require('stream'); - - const stream = new Readable(); - - let called = false, - calledTwice = false; - stream._read = function(size) { - console.log(`_read() called: ${size} bytes`); - - if (called) { - calledTwice = true; - return this.push(null); - } - - called = true; - - const wantsMore = this.push(Buffer.alloc(1000, 'a')); - console.log(`wantsMore: ${wantsMore}`); - }; - - stream.resume(); - - stream.on('end', () => { - if (calledTwice) return cb(new Error('_read called again before .push returns false')); - cb(); - }); - }); });