From bdf41e5b8be0ad94b3f8702fe1f8ea666bf410a9 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 5 Jan 2024 13:07:22 +1100 Subject: [PATCH] BREAKING: remove `std/signal` sub-module (#4105) --- README.md | 1 - .../check_circular_submodule_dependencies.ts | 1 - signal/mod.ts | 86 ------------------ signal/test.ts | 87 ------------------- 4 files changed, 175 deletions(-) delete mode 100644 signal/mod.ts delete mode 100644 signal/test.ts diff --git a/README.md b/README.md index 101f0b417..e0a70d8d0 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ Check out the documentation [here](https://deno.land/std?doc). | permissions | Deprecated | | regexp | Unstable | | semver | Unstable | -| signal | Deprecated | | streams | Unstable | | testing | Stable | | toml | Stable | diff --git a/_tools/check_circular_submodule_dependencies.ts b/_tools/check_circular_submodule_dependencies.ts index 00050634c..f61bcf8c8 100644 --- a/_tools/check_circular_submodule_dependencies.ts +++ b/_tools/check_circular_submodule_dependencies.ts @@ -113,7 +113,6 @@ deps["path"] = await check("path", "needs clean up"); deps["permissions"] = await check("permissions", "deprecated"); deps["regexp"] = await check("regexp", "not ready"); deps["semver"] = await check("semver", "not ready"); -deps["signal"] = await check("signal", "deprecated"); deps["streams"] = await check("streams", "needs clean up"); deps["testing"] = await check("testing", "ready", [ "bdd.ts", diff --git a/signal/mod.ts b/signal/mod.ts deleted file mode 100644 index 0bb0d38f6..000000000 --- a/signal/mod.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -/** - * Higher level API for dealing with OS signals. - * - * @module - * @deprecated (will be removed in 0.212.0) Use the {@link https://docs.deno.com/runtime/tutorials/os_signals|Deno Signals API} directly instead. - */ - -import { MuxAsyncIterator } from "../async/mux_async_iterator.ts"; - -export type Disposable = { dispose: () => void }; - -/** - * Generates an AsyncIterable which can be awaited on for one or more signals. - * `dispose()` can be called when you are finished waiting on the events. - * - * Example: - * - * ```ts - * import { signal } from "https://deno.land/std@$STD_VERSION/signal/mod.ts"; - * - * const sig = signal("SIGUSR1", "SIGINT"); - * setTimeout(() => {}, 5000); // Prevents exiting immediately - * - * for await (const _ of sig) { - * // .. - * } - * - * // At some other point in your code when finished listening: - * sig.dispose(); - * ``` - * - * @param signals - one or more signals to listen to - * - * @deprecated (will be removed in 0.212.0) Use the {@link https://docs.deno.com/runtime/tutorials/os_signals|Deno Signals API} directly instead. - */ -export function signal( - ...signals: [Deno.Signal, ...Deno.Signal[]] -): AsyncIterable & Disposable { - const mux = new MuxAsyncIterator(); - - if (signals.length < 1) { - throw new Error( - "No signals are given. You need to specify at least one signal to create a signal stream.", - ); - } - - const streams = signals.map(createSignalStream); - - streams.forEach((stream) => { - mux.add(stream); - }); - - // Create dispose method for the muxer of signal streams. - const dispose = () => { - streams.forEach((stream) => { - stream.dispose(); - }); - }; - - return Object.assign(mux, { dispose }); -} - -function createSignalStream( - signal: Deno.Signal, -): AsyncIterable & Disposable { - let streamContinues = Promise.withResolvers(); - const handler = () => { - streamContinues.resolve(true); - }; - Deno.addSignalListener(signal, handler); - - const gen = async function* () { - while (await streamContinues.promise) { - streamContinues = Promise.withResolvers(); - yield undefined; - } - }; - - return Object.assign(gen(), { - dispose() { - streamContinues.resolve(false); - Deno.removeSignalListener(signal, handler); - }, - }); -} diff --git a/signal/test.ts b/signal/test.ts deleted file mode 100644 index 76c174049..000000000 --- a/signal/test.ts +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; -import { delay } from "../async/delay.ts"; -import { signal } from "./mod.ts"; - -const isWindows = Deno.build.os === "windows"; - -Deno.test({ - name: "signal() throws when called with empty signals", - ignore: isWindows, - fn() { - assertThrows( - () => { - // deno-lint-ignore no-explicit-any - (signal as any)(); - }, - Error, - "No signals are given. You need to specify at least one signal to create a signal stream.", - ); - }, -}); - -Deno.test({ - name: "signal() iterates for multiple signals", - ignore: isWindows, - fn: async () => { - // This prevents the program from exiting. - const t = setInterval(() => {}, 1000); - - let c = 0; - const sig = signal( - "SIGUSR1", - "SIGUSR2", - ); - - setTimeout(async () => { - await delay(20); - Deno.kill(Deno.pid, "SIGUSR2"); - await delay(20); - Deno.kill(Deno.pid, "SIGUSR1"); - await delay(20); - Deno.kill(Deno.pid, "SIGUSR2"); - await delay(20); - Deno.kill(Deno.pid, "SIGUSR1"); - await delay(20); - sig.dispose(); - }); - - for await (const _ of sig) { - console.log(c); - c += 1; - } - - assertEquals(c, 4); - - clearTimeout(t); - }, -}); - -Deno.test({ - name: "signal(), multiple .next() results don't resolve at the same time", - ignore: isWindows, - async fn() { - // This prevents the program from exiting. - const t = setInterval(() => {}, 1000); - const sig = signal("SIGUSR1"); - const sigIter = sig[Symbol.asyncIterator](); - let done0 = false; - let done1 = false; - sigIter.next().then(() => { - done0 = true; - }); - sigIter.next().then(() => { - done1 = true; - }); - Deno.kill(Deno.pid, "SIGUSR1"); - await delay(20); - assert(done0); - assert(!done1); - Deno.kill(Deno.pid, "SIGUSR1"); - await delay(20); - assert(done0); - assert(done1); - sig.dispose(); - clearTimeout(t); - }, -});