summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-end-paused.js
blob: 9cc32db880ea880762ad1ab7eaa6fe16f6444826 (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
30
31
32
33
'use strict';
require('../common');
var assert = require('assert');
var gotEnd = false;

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

var Readable = require('stream').Readable;
var stream = new Readable();
var 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(function() {
  stream.on('end', function() {
    gotEnd = true;
  });
  stream.resume();
});

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