summaryrefslogtreecommitdiff
path: root/cli/dts/lib.deno.unstable.d.ts
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2021-10-26 12:03:38 +0900
committerGitHub <noreply@github.com>2021-10-26 12:03:38 +0900
commita9b34118a9338323532c3b6b2e0336c343a0e834 (patch)
tree9ad40347dcd92fb05a2f7f4c3a27b8cb8fd84110 /cli/dts/lib.deno.unstable.d.ts
parent56d9a020d94f022e0c9081d661c73f278d92084a (diff)
feat(runtime): add Deno.addSignalListener API (#12512)
Diffstat (limited to 'cli/dts/lib.deno.unstable.d.ts')
-rw-r--r--cli/dts/lib.deno.unstable.d.ts57
1 files changed, 19 insertions, 38 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index fd33e1a74..a84883574 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -566,56 +566,37 @@ declare namespace Deno {
/** **UNSTABLE**: new API, yet to be vetted.
*
- * Represents the stream of signals, implements both `AsyncIterator` and
- * `PromiseLike`. */
- export class SignalStream
- implements AsyncIterableIterator<void>, PromiseLike<void> {
- constructor(signal: Signal);
- then<T, S>(
- f: (v: void) => T | Promise<T>,
- g?: (v: void) => S | Promise<S>,
- ): Promise<T | S>;
- next(): Promise<IteratorResult<void>>;
- [Symbol.asyncIterator](): AsyncIterableIterator<void>;
- dispose(): void;
- }
-
- /** **UNSTABLE**: new API, yet to be vetted.
- *
- * Returns the stream of the given signal number. You can use it as an async
- * iterator.
+ * Registers the given function as a listener of the given signal event.
*
* ```ts
- * for await (const _ of Deno.signal("SIGTERM")) {
- * console.log("got SIGTERM!");
- * }
+ * Deno.addSignalListener("SIGTERM", () => {
+ * console.log("SIGTERM!")
+ * });
* ```
*
- * You can also use it as a promise. In this case you can only receive the
- * first one.
- *
- * ```ts
- * await Deno.signal("SIGTERM");
- * console.log("SIGTERM received!")
- * ```
+ * NOTE: This functionality is not yet implemented on Windows.
+ */
+ export function addSignalListener(signal: Signal, handler: () => void): void;
+
+ /** **UNSTABLE**: new API, yet to be vetted.
*
- * If you want to stop receiving the signals, you can use `.dispose()` method
- * of the signal stream object.
+ * Removes the given signal listener that has been registered with
+ * Deno.addSignalListener.
*
* ```ts
- * const sig = Deno.signal("SIGTERM");
- * setTimeout(() => { sig.dispose(); }, 5000);
- * for await (const _ of sig) {
+ * const listener = () => {
* console.log("SIGTERM!")
- * }
+ * };
+ * Deno.addSignalListener("SIGTERM", listener);
+ * Deno.removeSignalListener("SIGTERM", listener);
* ```
*
- * The above for-await loop exits after 5 seconds when `sig.dispose()` is
- * called.
- *
* NOTE: This functionality is not yet implemented on Windows.
*/
- export function signal(sig: Signal): SignalStream;
+ export function removeSignalListener(
+ signal: Signal,
+ handler: () => void,
+ ): void;
export type SetRawOptions = {
cbreak: boolean;