Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions test/parallel/test-stream2-readable-empty-buffer-no-eof.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,27 @@ function test1() {

const buf = Buffer.alloc(5, 'x');
let reads = 5;
const timeout = common.platformTimeout(50);
r._read = function(n) {
switch (reads--) {
case 0:
return r.push(null); // EOF
case 1:
return r.push(buf);
case 2:
setTimeout(r.read.bind(r, 0), timeout);
setImmediate(r.read.bind(r, 0));
return r.push(Buffer.alloc(0)); // Not-EOF!
case 3:
setTimeout(r.read.bind(r, 0), timeout);
setImmediate(r.read.bind(r, 0));
return process.nextTick(function() {
return r.push(Buffer.alloc(0));
});
case 4:
setTimeout(r.read.bind(r, 0), timeout);
return setTimeout(function() {
setImmediate(setImmediate, r.read.bind(r, 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double setImmediate() here intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott yes, it’s so that this one still gets executed after the one below (I think that appropriately maps the timeout-vs-no-timeout relation the timers had before?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're guaranteed to execute in the order they are called so I don't think that inner setImmediate is needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but then the test fails. Hmmm... Not sure what's wrong.

Copy link
Member

@Trott Trott Oct 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misread your comment. Urp. Yeah, I wonder if the thing to do is just swap them like this:

        const rv = setImmediate(function() {
          return r.push(Buffer.alloc(0));
        });
        setImmediate(r.read.bind(r, 0));
        return rv;

Easier to read/understand and same effect?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Whoops, typo'ed in the code snippet, edited, above is what I meant.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott Mh, I’ve switched to two single setImmediates with reverse order, that should be okay 👍

return setImmediate(function() {
return r.push(Buffer.alloc(0));
});
case 5:
return setTimeout(function() {
return setImmediate(function() {
return r.push(buf);
});
default:
Expand Down