Skip to content

Commit

Permalink
Make event listener fire only once
Browse files Browse the repository at this point in the history
  • Loading branch information
longnguyen2004 committed Feb 19, 2025
1 parent d5ac5a6 commit 8e9f68c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/media/newApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export function prepareStream(
command.on("end", () => resolve());
})
promise.catch(() => {});
cancelSignal?.addEventListener("abort", () => command.kill("SIGTERM"));
cancelSignal?.addEventListener("abort", () => command.kill("SIGTERM"), { once: true });
command.run();

return { command, output, promise }
Expand Down Expand Up @@ -456,7 +456,7 @@ export async function playStream(
cancelSignal?.addEventListener("abort", () => {
cleanup();
reject(cancelSignal.reason);
})
}, { once: true })
vStream.once("finish", () => {
if (cancelSignal?.aborted)
return;
Expand Down

0 comments on commit 8e9f68c

Please sign in to comment.