mirror of
https://github.com/marko-js/marko.git
synced 2026-02-01 16:07:13 +00:00
Deprecate "end" event for writer (since Writable streams should emit "finish" according to NodeJS docs). When listening for "finish"/"end" event, actually listen for both since older stream implementations might emit "end" and not "finish" as indication that writing has ended.
This commit is contained in:
parent
42231bdff1
commit
5ee74887a8
@ -43,16 +43,40 @@ var voidWriter = {
|
||||
|
||||
function onProxy(asyncWriter, type, event, callback) {
|
||||
var global = asyncWriter.global;
|
||||
var events = global.events;
|
||||
|
||||
if (event === 'end') {
|
||||
var endEvent = (event === 'end');
|
||||
if (endEvent) {
|
||||
console.error('WARNING: "end" event type is deprecated. Use "finish" instead.', (new Error()).stack);
|
||||
}
|
||||
|
||||
// Writable streams are only suppose to emit "finish" but
|
||||
// "through" streams (from the "through" module) only output
|
||||
// "end" event. Therefor, we need to normalize "end" and "finish"
|
||||
// events
|
||||
if (endEvent || (event === 'finish')) {
|
||||
if (global.ended) {
|
||||
callback();
|
||||
return asyncWriter;
|
||||
}
|
||||
}
|
||||
|
||||
var events = global.events;
|
||||
events[type](event, callback);
|
||||
var emitted = false;
|
||||
|
||||
var onFinish = function() {
|
||||
if (emitted) {
|
||||
return;
|
||||
}
|
||||
|
||||
emitted = true;
|
||||
callback();
|
||||
};
|
||||
|
||||
events[type]('end', onFinish);
|
||||
events[type]('finish', onFinish);
|
||||
} else {
|
||||
events[type](event, callback);
|
||||
}
|
||||
|
||||
return asyncWriter;
|
||||
}
|
||||
|
||||
@ -378,7 +402,7 @@ AsyncWriter.prototype = {
|
||||
if (this.stream.end) {
|
||||
this.stream.end();
|
||||
} else {
|
||||
this.emit('end');
|
||||
this.emit('finish');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user