StreamHelpers: await for finish event

This commit is contained in:
Starbeamrainbowlabs 2020-10-05 18:31:56 +01:00
parent 03fc6b55ea
commit aca3fb0278
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
1 changed files with 4 additions and 2 deletions

View File

@ -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 };