https://github.com/milly/deno-async-signal
Handling process signals asynchronously in Deno.
https://github.com/milly/deno-async-signal
Last synced: 3 months ago
JSON representation
Handling process signals asynchronously in Deno.
- Host: GitHub
- URL: https://github.com/milly/deno-async-signal
- Owner: Milly
- License: mit
- Created: 2024-06-14T15:58:32.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-30T05:24:40.000Z (12 months ago)
- Last Synced: 2025-04-03T14:44:19.464Z (3 months ago)
- Language: TypeScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async-signal
[](LICENSE)
[](https://jsr.io/@milly/async-signal)
[](https://github.com/Milly/deno-async-signal/actions/workflows/test.yml)
[](https://codecov.io/gh/Milly/deno-async-signal)`async-signal` provides functions for handling process signals asynchronously in [Deno][].
Deno limitation: On Windows only `"SIGINT"` (Ctrl+C) and `"SIGBREAK"` (Ctrl+Break) are supported.
[Deno]: https://deno.com/
```typescript
import { asyncSignal, SignalError } from "@milly/async-signal";
import { delay } from "@std/async";try {
// When the block exits, the signal trap is removed.
using intTrap = asyncSignal("SIGINT");// It resolves after 5 seconds or rejecets if Ctrl+C is pressed.
await Promise.race([intTrap, delay(5000)]);
} catch (err) {
// `intTrap` rejecets with `SignalError`.
if (err instanceof SignalError) {
console.error(`${err.signal} is trapped`);
}
}
```