-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from vqvu/consume-mutates-consumers
Keep a reference to the correct consumer/observer array in _send (resolves #366).
- Loading branch information
Showing
2 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -688,14 +688,20 @@ Stream.prototype._send = function (err, x) { | |
} | ||
if (this._consumers.length) { | ||
token = err ? new StreamError(err) : x; | ||
for (var i = 0, len = this._consumers.length; i < len; i++) { | ||
this._consumers[i].write(token); | ||
// this._consumers may be changed from under us, | ||
// so we keep a copy. | ||
var consumers = this._consumers; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vqvu
Author
Collaborator
|
||
for (var i = 0, len = consumers.length; i < len; i++) { | ||
consumers[i].write(token); | ||
} | ||
} | ||
if (this._observers.length) { | ||
token = err ? new StreamError(err) : x; | ||
for (var j = 0, len2 = this._observers.length; j < len2; j++) { | ||
this._observers[j].write(token); | ||
// this._observers may be changed from under us, | ||
// so we keep a copy. | ||
var observers = this._observers; | ||
for (var j = 0, len2 = observers.length; j < len2; j++) { | ||
observers[j].write(token); | ||
} | ||
} | ||
if (this._send_events) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A note on this, you are relying on a reference still, if someone mutates that reference you will still get the changes.
The reason this works right now is because the _removeConsumer does a reassignment. Cloning is still a safer way to go.