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
Next Next commit
stream: re-use existing once() implementation
  • Loading branch information
addaleax committed Dec 12, 2018
commit 165ed803d4366c6f63da6eb400d9a4c259f3fe3c
10 changes: 1 addition & 9 deletions lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PREMATURE_CLOSE
} = require('internal/errors').codes;
const { once } = require('internal/util');

function isRequest(stream) {
return stream.setHeader && typeof stream.abort === 'function';
}

function once(callback) {
let called = false;
return function(err) {
if (called) return;
called = true;
callback.call(this, err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like the callback has a different context in once from internal/util. Is this something we want to pay attention to / align the behavior?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, thanks – I’ve made the one in internal/util more generic 👍

};
}

function eos(stream, opts, callback) {
if (arguments.length === 2) {
callback = opts;
Expand Down