Improved code readability for shutdown() function

This commit is contained in:
peteriman 2022-01-01 00:29:25 +08:00
parent 1e066b9bfa
commit 44bf7ce5bb
No known key found for this signature in database
GPG Key ID: 90F6ABECF080D7BF

View File

@ -104,9 +104,13 @@ function shutdown(cb) {
(accum, next) => (next.shutdown ? accum + 1 : accum),
0
);
if (shutdownFunctions === 0) {
debug("No appenders with shutdown functions found.");
return cb !== undefined && cb();
}
let completed = 0;
let error;
debug(`Found ${shutdownFunctions} appenders with shutdown functions.`);
function complete(err) {
error = error || err;
@ -119,12 +123,6 @@ function shutdown(cb) {
}
}
}
if (shutdownFunctions === 0) {
debug("No appenders with shutdown functions found.");
return cb !== undefined && cb();
}
appendersToCheck.filter(a => a.shutdown).forEach(a => a.shutdown(complete));
return null;