Skip to content

Commit

Permalink
Use finished instead of on-error
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Dec 2, 2020
1 parent 33e1144 commit 797985e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/monitor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const Os = require('os');
const { pipeline } = require('stream');
const { pipeline, finished } = require('stream');

const Hoek = require('@hapi/hoek');
const Oppsy = require('@hapi/oppsy');
Expand Down Expand Up @@ -121,8 +121,10 @@ module.exports = internals.Monitor = class {

this._reporters.set(reporterName, setupPipeline(streamObjs, (err) => {

console.error(`There was a problem (${err}) in ${reporterName} and it has been destroyed.`);
console.error(err);
if (err) {
console.error(`There was a problem (${err}) in ${reporterName} and it has been destroyed.`);
console.error(err);
}
}));
}

Expand Down Expand Up @@ -205,20 +207,15 @@ module.exports = internals.Monitor = class {
}
};

const setupPipeline = (streams, onError) => {
const setupPipeline = (streams, onFinished) => {

const stream = streams[0];

if (streams.length === 1) {
stream.on('error', onError);
finished(stream, onFinished);
}
else {
pipeline(streams, (err) => {

if (err) {
onError(err);
}
});
pipeline(streams, onFinished);
}

return stream;
Expand Down

0 comments on commit 797985e

Please sign in to comment.