-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.ts
More file actions
31 lines (29 loc) · 1017 Bytes
/
process.ts
File metadata and controls
31 lines (29 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @fileoverview Process control helpers.
* Lazily creates and exposes a shared `AbortController` and its `AbortSignal`
* so cooperating modules can coordinate cancellation from a single source.
*/
// Abort controller and signal.
let _abortController: AbortController
/**
* Get the process-scoped shared `AbortController` singleton.
* Cooperating modules use this to coordinate cancellation across the library.
*
* @returns The lazily-created shared `AbortController` instance.
*/
export function getAbortController(): AbortController {
if (_abortController === undefined) {
_abortController = new AbortController()
}
return _abortController
}
/**
* Get the process-scoped shared `AbortSignal` singleton.
* This is the `signal` property of {@link getAbortController}'s controller and
* is intended to be passed to APIs that accept an `AbortSignal`.
*
* @returns The shared `AbortSignal` instance.
*/
export function getAbortSignal(): AbortSignal {
return getAbortController().signal
}