summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-end-paused.js
blob: 4b585fdb999890b28686ee18fafffd350fdcd4a5 (plain)
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
'use strict';
const common = require('../common');
const assert = require('assert');

// Make sure we don't miss the end event for paused 0-length streams

const Readable = require('stream').Readable;
const stream = new Readable();
let calledRead = false;
stream._read = function() {
  assert(!calledRead);
  calledRead = true;
  this.push(null);
};

stream.on('data', function() {
  throw new Error('should not ever get data');
});
stream.pause();

setTimeout(common.mustCall(function() {
  stream.on('end', common.mustCall(function() {}));
  stream.resume();
}), 1);

process.on('exit', function() {
  assert(calledRead);
  console.log('ok');
});