1
0
Fork 0
mirror of https://github.com/sbrl/terrain50-cli.git synced 2024-11-26 07:33:00 +00:00

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

View file

@ -42,9 +42,11 @@ function write_safe(stream_out, data) {
*/ */
function end_safe(stream, chunk = undefined) { function end_safe(stream, chunk = undefined) {
return new Promise((resolve, _reject) => { return new Promise((resolve, _reject) => {
if(typeof chunk == "undefined") stream.end(resolve); stream.once("finish", resolve);
else stream.end(chunk, resolve); if(typeof chunk == "undefined") stream.end();
else stream.end(chunk);
}); });
} }
export { write_safe, end_safe }; export { write_safe, end_safe };