Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override the destroy method, use _destroy instead #135

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
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: 3 additions & 8 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ function buildProxy (options, socketWrite, socketEnd) {
objectMode: options.objectMode
})

proxy._destroyed = false
proxy._write = socketWrite
proxy._flush = socketEnd

proxy.destroy = function(err) {
if (this._destroyed) return
this._destroyed = true

proxy._destroy = function(err, cb) {
Copy link
Contributor Author

@lpinca lpinca Oct 19, 2017

Choose a reason for hiding this comment

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

Using the default implementation with

this.push(null)
this.end()

is probably better but I didn't change it as there might be something I'm missing here.

var self = this
process.nextTick(function() {
if (err)
self.emit('error', err)
cb(err);
self.emit('close')
})
}
Expand Down Expand Up @@ -155,7 +150,7 @@ function WebSocketStream(target, protocols, options) {

function onmessage(event) {
var data = event.data
if (data instanceof ArrayBuffer) data = Buffer.from(new Uint8Array(data))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is unrelated and not needed but there is no need to instantiate a new Uint8Array. You can use the ArrayBuffer directly.

I can revert this change or move it to its own commit/PR if wanted.

Copy link
Collaborator

Choose a reason for hiding this comment

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

no need.

if (data instanceof ArrayBuffer) data = Buffer.from(data)
else data = Buffer.from(data, 'utf8')
proxy.push(data)
}
Expand Down