From aca3fb02783042f304a2fd85bdb25c5bb203cab3 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 5 Oct 2020 18:31:56 +0100 Subject: [PATCH] StreamHelpers: await for finish event --- src/Helpers/StreamHelpers.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Helpers/StreamHelpers.mjs b/src/Helpers/StreamHelpers.mjs index aa63cac..a15bc9f 100644 --- a/src/Helpers/StreamHelpers.mjs +++ b/src/Helpers/StreamHelpers.mjs @@ -42,9 +42,11 @@ function write_safe(stream_out, data) { */ function end_safe(stream, chunk = undefined) { return new Promise((resolve, _reject) => { - if(typeof chunk == "undefined") stream.end(resolve); - else stream.end(chunk, resolve); + stream.once("finish", resolve); + if(typeof chunk == "undefined") stream.end(); + else stream.end(chunk); }); } + export { write_safe, end_safe };