Skip to content

Commit

Permalink
fix(runtime): fix signal promise API (#11069)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jun 22, 2021
1 parent 097c02f commit 4e3ec47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
29 changes: 29 additions & 0 deletions cli/tests/unit/signal_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,35 @@ unitTest(
},
);

// https://github.com/denoland/deno/issues/9806
unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true } },
async function signalPromiseTest2(): Promise<void> {
const resolvable = deferred();
// This prevents the program from exiting.
const t = setInterval(() => {}, 1000);

let called = false;
const sig = Deno.signal(Deno.Signal.SIGUSR1);
sig.then(() => {
called = true;
});
setTimeout(() => {
sig.dispose();
setTimeout(() => {
resolvable.resolve();
}, 10);
}, 10);

clearInterval(t);
await resolvable;

// Promise callback is not called because it didn't get
// the corresponding signal.
assert(!called);
},
);

unitTest(
{ ignore: Deno.build.os === "windows", perms: { run: true } },
function signalShorthandsTest(): void {
Expand Down
10 changes: 9 additions & 1 deletion runtime/js/40_signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,15 @@
f,
g,
) {
return this.#pollingPromise.then(() => {}).then(f, g);
return this.#pollingPromise.then((done) => {
if (done) {
// If pollingPromise returns true, then
// this signal stream is finished and the promise API
// should never be resolved.
return new Promise(() => {});
}
return;
}).then(f, g);
}

async next() {
Expand Down

0 comments on commit 4e3ec47

Please sign in to comment.