You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
623 B
JavaScript
28 lines
623 B
JavaScript
"use strict";
|
|
|
|
module.exports = function attachWritableStreamHandlers({ stream, onClose, onError }) {
|
|
function detachEventHandlers() {
|
|
stream.removeListener("finish", onCloseWrapper);
|
|
stream.removeListener("close", onCloseWrapper);
|
|
stream.removeListener("error", onErrorWrapper);
|
|
}
|
|
|
|
function attachEventHandlers() {
|
|
stream.on("finish", onCloseWrapper);
|
|
stream.on("close", onCloseWrapper);
|
|
stream.on("error", onErrorWrapper);
|
|
}
|
|
|
|
function onCloseWrapper() {
|
|
onClose();
|
|
detachEventHandlers();
|
|
}
|
|
|
|
function onErrorWrapper(error) {
|
|
onError(error);
|
|
detachEventHandlers();
|
|
}
|
|
|
|
attachEventHandlers();
|
|
};
|