Pass Reason to the streamDispatcher end event (#985)

* Pass Reason to the streamDispatcher end event

* Update <dispatcher>.end() to bring inline with <collector>.stop()

Also changed "Stream is not generating quickly enough." from an end to an error, per Crawl...

* Fix docs Copy/Paste fail from collection end event
This commit is contained in:
bdistin
2016-12-15 10:32:37 -06:00
committed by Amish Shah
parent a20bac7258
commit fbe1929bde

View File

@@ -114,9 +114,10 @@ class StreamDispatcher extends EventEmitter {
/**
* Stops the current stream permanently and emits an `end` event.
* @param {string} [reason='user'] An optional reason for stopping the dispatcher.
*/
end() {
this._triggerTerminalState('end', 'user requested');
end(reason = 'user') {
this._triggerTerminalState('end', reason);
}
_setSpeaking(value) {
@@ -179,7 +180,7 @@ class StreamDispatcher extends EventEmitter {
const data = this.streamingData;
if (data.missed >= 5) {
this._triggerTerminalState('end', 'Stream is not generating quickly enough.');
this._triggerTerminalState('error', 'Stream is not generating quickly enough.');
return;
}
@@ -233,12 +234,14 @@ class StreamDispatcher extends EventEmitter {
}
}
_triggerEnd() {
_triggerEnd(reason) {
/**
* Emitted once the stream has ended. Attach a `once` listener to this.
* @event StreamDispatcher#end
* @param {string} reason The reason for the end of the dispatcher. If it ended because it reached the end of the
* stream, this would be `stream`. If you invoke `.end()` without specifying a reason, this would be `user`.
*/
this.emit('end');
this.emit('end', reason);
}
_triggerError(err) {
@@ -280,7 +283,7 @@ class StreamDispatcher extends EventEmitter {
return;
}
this.stream.on('end', err => this._triggerTerminalState('end', err));
this.stream.on('end', err => this._triggerTerminalState('end', err || 'stream'));
this.stream.on('error', err => this._triggerTerminalState('error', err));
const data = this.streamingData;