summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2021-06-22 15:17:44 +0900
committerGitHub <noreply@github.com>2021-06-22 15:17:44 +0900
commit4e3ec478573ede7247fd306cad1ea5bf2d5c9565 (patch)
treeb78cd4de810d68052f85ae933c4e125d3a4a21ba
parent097c02f11bb5fd43e4346fce03b4bacaed119ed2 (diff)
fix(runtime): fix signal promise API (#11069)
-rw-r--r--cli/tests/unit/signal_test.ts29
-rw-r--r--runtime/js/40_signals.js10
2 files changed, 38 insertions, 1 deletions
diff --git a/cli/tests/unit/signal_test.ts b/cli/tests/unit/signal_test.ts
index 801e15d8b..e0e94b49a 100644
--- a/cli/tests/unit/signal_test.ts
+++ b/cli/tests/unit/signal_test.ts
@@ -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 {
diff --git a/runtime/js/40_signals.js b/runtime/js/40_signals.js
index dfc604759..bf6be1263 100644
--- a/runtime/js/40_signals.js
+++ b/runtime/js/40_signals.js
@@ -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() {