@tstdl/base 0.93.138 → 0.93.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -0
- package/ai/genkit/multi-region.plugin.js +5 -3
- package/ai/genkit/tests/multi-region.test.d.ts +1 -0
- package/ai/genkit/tests/multi-region.test.js +5 -2
- package/ai/parser/parser.js +2 -2
- package/ai/prompts/build.js +1 -0
- package/ai/prompts/instructions-formatter.d.ts +15 -2
- package/ai/prompts/instructions-formatter.js +36 -31
- package/ai/prompts/prompt-builder.js +5 -5
- package/ai/prompts/steering.d.ts +3 -2
- package/ai/prompts/steering.js +3 -1
- package/ai/tests/instructions-formatter.test.js +1 -0
- package/api/README.md +403 -0
- package/api/client/client.js +7 -13
- package/api/client/tests/api-client.test.js +10 -10
- package/api/default-error-handlers.js +1 -1
- package/api/response.d.ts +2 -2
- package/api/response.js +22 -33
- package/api/server/api-controller.d.ts +1 -1
- package/api/server/api-controller.js +3 -3
- package/api/server/api-request-token.provider.d.ts +1 -0
- package/api/server/api-request-token.provider.js +1 -0
- package/api/server/middlewares/allowed-methods.middleware.js +2 -1
- package/api/server/middlewares/content-type.middleware.js +2 -1
- package/api/types.d.ts +3 -2
- package/application/README.md +240 -0
- package/application/application.js +2 -2
- package/audit/README.md +267 -0
- package/authentication/README.md +288 -0
- package/authentication/client/authentication.service.d.ts +12 -11
- package/authentication/client/authentication.service.js +21 -21
- package/authentication/client/http-client.middleware.js +2 -2
- package/authentication/tests/authentication.client-error-handling.test.js +2 -1
- package/authentication/tests/authentication.client-service-refresh.test.js +5 -3
- package/browser/README.md +401 -0
- package/cancellation/README.md +156 -0
- package/cancellation/tests/coverage.test.d.ts +1 -0
- package/cancellation/tests/coverage.test.js +49 -0
- package/cancellation/tests/leak.test.d.ts +1 -0
- package/cancellation/tests/leak.test.js +35 -0
- package/cancellation/tests/token.test.d.ts +1 -0
- package/cancellation/tests/token.test.js +136 -0
- package/cancellation/token.d.ts +53 -177
- package/cancellation/token.js +132 -201
- package/context/README.md +174 -0
- package/cookie/README.md +161 -0
- package/css/README.md +157 -0
- package/data-structures/README.md +320 -0
- package/decorators/README.md +140 -0
- package/distributed-loop/README.md +231 -0
- package/distributed-loop/distributed-loop.js +1 -1
- package/document-management/README.md +403 -0
- package/document-management/server/services/document-management.service.js +9 -7
- package/document-management/tests/document-management-core.test.js +2 -7
- package/document-management/tests/document-management.api.test.js +6 -7
- package/document-management/tests/document-statistics.service.test.js +11 -12
- package/document-management/tests/document.service.test.js +3 -3
- package/document-management/tests/enum-helpers.test.js +2 -3
- package/dom/README.md +213 -0
- package/enumerable/README.md +259 -0
- package/enumeration/README.md +121 -0
- package/errors/README.md +267 -0
- package/file/README.md +191 -0
- package/formats/README.md +210 -0
- package/function/README.md +144 -0
- package/http/README.md +318 -0
- package/http/client/adapters/undici.adapter.js +1 -1
- package/http/client/http-client-request.d.ts +6 -5
- package/http/client/http-client-request.js +8 -9
- package/http/server/node/node-http-server.js +1 -2
- package/image-service/README.md +137 -0
- package/injector/README.md +491 -0
- package/injector/injector.d.ts +1 -0
- package/injector/injector.js +17 -5
- package/injector/tests/leak.test.d.ts +1 -0
- package/injector/tests/leak.test.js +45 -0
- package/intl/README.md +113 -0
- package/json-path/README.md +182 -0
- package/jsx/README.md +154 -0
- package/key-value-store/README.md +191 -0
- package/lock/README.md +249 -0
- package/lock/web/web-lock.js +119 -47
- package/logger/README.md +287 -0
- package/mail/README.md +256 -0
- package/memory/README.md +144 -0
- package/message-bus/README.md +244 -0
- package/message-bus/message-bus-base.js +1 -1
- package/module/README.md +182 -0
- package/module/module.d.ts +1 -1
- package/module/module.js +77 -17
- package/module/modules/web-server.module.js +1 -1
- package/notification/tests/notification-type.service.test.js +24 -15
- package/object-storage/README.md +300 -0
- package/openid-connect/README.md +274 -0
- package/orm/README.md +423 -0
- package/package.json +8 -6
- package/password/README.md +164 -0
- package/pdf/README.md +246 -0
- package/polyfills.js +1 -0
- package/pool/README.md +198 -0
- package/process/README.md +237 -0
- package/promise/README.md +252 -0
- package/promise/cancelable-promise.js +1 -1
- package/random/README.md +193 -0
- package/reflection/README.md +305 -0
- package/rpc/README.md +386 -0
- package/rxjs-utils/README.md +262 -0
- package/schema/README.md +342 -0
- package/serializer/README.md +342 -0
- package/signals/implementation/README.md +134 -0
- package/sse/README.md +278 -0
- package/task-queue/README.md +300 -0
- package/task-queue/postgres/task-queue.d.ts +2 -1
- package/task-queue/postgres/task-queue.js +32 -2
- package/task-queue/task-context.js +1 -1
- package/task-queue/task-queue.d.ts +17 -0
- package/task-queue/task-queue.js +103 -44
- package/task-queue/tests/complex.test.js +4 -4
- package/task-queue/tests/dependencies.test.js +4 -2
- package/task-queue/tests/queue.test.js +111 -0
- package/task-queue/tests/worker.test.js +21 -13
- package/templates/README.md +287 -0
- package/testing/README.md +157 -0
- package/text/README.md +346 -0
- package/threading/README.md +238 -0
- package/types/README.md +311 -0
- package/utils/README.md +322 -0
- package/utils/async-iterable-helpers/observable-iterable.d.ts +1 -1
- package/utils/async-iterable-helpers/observable-iterable.js +4 -8
- package/utils/async-iterable-helpers/take-until.js +4 -4
- package/utils/backoff.js +89 -30
- package/utils/retry-with-backoff.js +1 -1
- package/utils/timer.d.ts +1 -1
- package/utils/timer.js +5 -7
- package/utils/timing.d.ts +1 -1
- package/utils/timing.js +2 -4
- package/utils/z-base32.d.ts +1 -0
- package/utils/z-base32.js +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import '../../polyfills.js';
|
|
2
|
+
import { firstValueFrom, from } from 'rxjs';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { CancellationSignal, CancellationToken } from '../token.js';
|
|
5
|
+
describe('CancellationToken', () => {
|
|
6
|
+
it('should be unset by default', () => {
|
|
7
|
+
const token = new CancellationToken();
|
|
8
|
+
expect(token.isSet).toBe(false);
|
|
9
|
+
expect(token.isUnset).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
it('should be set when set() is called', () => {
|
|
12
|
+
const token = new CancellationToken();
|
|
13
|
+
token.set('reason');
|
|
14
|
+
expect(token.isSet).toBe(true);
|
|
15
|
+
expect(token.isUnset).toBe(false);
|
|
16
|
+
expect(token.reason).toBeInstanceOf(Error);
|
|
17
|
+
expect(token.reason.message).toBe('Operation cancelled');
|
|
18
|
+
expect(token.reason.cause).toBe('reason');
|
|
19
|
+
});
|
|
20
|
+
it('should fork a new token', () => {
|
|
21
|
+
const parent = new CancellationToken();
|
|
22
|
+
const child = parent.fork();
|
|
23
|
+
expect(child).toBeInstanceOf(CancellationToken);
|
|
24
|
+
expect(child.isSet).toBe(false);
|
|
25
|
+
parent.set();
|
|
26
|
+
expect(child.isSet).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('should support multiple parents', () => {
|
|
29
|
+
const parent1 = new CancellationToken();
|
|
30
|
+
const parent2 = new CancellationToken();
|
|
31
|
+
const child = new CancellationToken([parent1, parent2]);
|
|
32
|
+
expect(child.isSet).toBe(false);
|
|
33
|
+
parent2.set();
|
|
34
|
+
expect(child.isSet).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it('should support single parent', () => {
|
|
37
|
+
const parent = new CancellationToken();
|
|
38
|
+
const child = new CancellationToken(parent);
|
|
39
|
+
expect(child.isSet).toBe(false);
|
|
40
|
+
parent.set();
|
|
41
|
+
expect(child.isSet).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it('should support AbortController as a source', () => {
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const signal = CancellationSignal.from(controller);
|
|
46
|
+
expect(signal.isSet).toBe(false);
|
|
47
|
+
controller.abort();
|
|
48
|
+
expect(signal.isSet).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('should support AbortSignal as a source', () => {
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const signal = CancellationSignal.from(controller.signal);
|
|
53
|
+
expect(signal.isSet).toBe(false);
|
|
54
|
+
controller.abort();
|
|
55
|
+
expect(signal.isSet).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
it('should wait for cancellation (resolve)', async () => {
|
|
58
|
+
const token = new CancellationToken();
|
|
59
|
+
setTimeout(() => token.set(), 10);
|
|
60
|
+
await token.wait();
|
|
61
|
+
expect(token.isSet).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
it('should wait and throw (waitThrow)', async () => {
|
|
64
|
+
const token = new CancellationToken();
|
|
65
|
+
setTimeout(() => token.set('foo'), 10);
|
|
66
|
+
await expect(token.waitThrow()).rejects.toThrow('Operation cancelled');
|
|
67
|
+
});
|
|
68
|
+
it('should resolve immediately if already set', async () => {
|
|
69
|
+
const token = new CancellationToken();
|
|
70
|
+
token.set();
|
|
71
|
+
await token.wait();
|
|
72
|
+
expect(token.isSet).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it('should throw immediately if already set with waitThrow', async () => {
|
|
75
|
+
const token = new CancellationToken();
|
|
76
|
+
token.set();
|
|
77
|
+
await expect(token.waitThrow()).rejects.toThrow();
|
|
78
|
+
});
|
|
79
|
+
it('should throw immediately if already set', async () => {
|
|
80
|
+
const token = new CancellationToken();
|
|
81
|
+
token.set();
|
|
82
|
+
expect(() => token.throwIfSet()).toThrow();
|
|
83
|
+
});
|
|
84
|
+
it('should not throw if not set', () => {
|
|
85
|
+
const token = new CancellationToken();
|
|
86
|
+
expect(() => token.throwIfSet()).not.toThrow();
|
|
87
|
+
});
|
|
88
|
+
it('should support timeouts', async () => {
|
|
89
|
+
const token = new CancellationToken();
|
|
90
|
+
const timedSignal = token.withTimeout(10);
|
|
91
|
+
expect(timedSignal.isSet).toBe(false);
|
|
92
|
+
await timedSignal.wait();
|
|
93
|
+
expect(timedSignal.isSet).toBe(true);
|
|
94
|
+
expect(token.isSet).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
it('should be observable', async () => {
|
|
97
|
+
const token = new CancellationToken();
|
|
98
|
+
const promise = firstValueFrom(from(token));
|
|
99
|
+
token.set();
|
|
100
|
+
await promise;
|
|
101
|
+
});
|
|
102
|
+
it('should support subscribe', () => {
|
|
103
|
+
const token = new CancellationToken();
|
|
104
|
+
const next = vi.fn();
|
|
105
|
+
const complete = vi.fn();
|
|
106
|
+
const subscription = token.subscribe({ next, complete });
|
|
107
|
+
token.set();
|
|
108
|
+
expect(next).toHaveBeenCalled();
|
|
109
|
+
expect(complete).toHaveBeenCalled();
|
|
110
|
+
subscription.unsubscribe();
|
|
111
|
+
});
|
|
112
|
+
it('should support Symbol.observable', () => {
|
|
113
|
+
const token = new CancellationToken();
|
|
114
|
+
const result = token[Symbol.observable]();
|
|
115
|
+
expect(result).toBe(token);
|
|
116
|
+
});
|
|
117
|
+
it('should return self as signal', () => {
|
|
118
|
+
const token = new CancellationToken();
|
|
119
|
+
expect(token.signal).toBe(token);
|
|
120
|
+
});
|
|
121
|
+
it('should handle subscribe when already set', () => {
|
|
122
|
+
const token = new CancellationToken();
|
|
123
|
+
token.set();
|
|
124
|
+
const next = vi.fn();
|
|
125
|
+
token.subscribe({ next });
|
|
126
|
+
expect(next).toHaveBeenCalled();
|
|
127
|
+
});
|
|
128
|
+
it('should support unsubscribe', () => {
|
|
129
|
+
const token = new CancellationToken();
|
|
130
|
+
const next = vi.fn();
|
|
131
|
+
const subscription = token.subscribe({ next });
|
|
132
|
+
subscription.unsubscribe();
|
|
133
|
+
token.set();
|
|
134
|
+
expect(next).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
});
|
package/cancellation/token.d.ts
CHANGED
|
@@ -1,207 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type ConnectConfig = {
|
|
6
|
-
/**
|
|
7
|
-
* Propagate 'set' (true) states to the child token.
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
set?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Propagate 'unset' (false) states to the child token.
|
|
13
|
-
* @default true
|
|
14
|
-
*/
|
|
15
|
-
unset?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Propagate the 'complete' event to the child token.
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
complete?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Propagate errors to the child token.
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
error?: boolean;
|
|
1
|
+
import type { InteropObservable, Observer, Subscribable, Unsubscribable } from 'rxjs';
|
|
2
|
+
import type { OneOrMany } from '../types/types.js';
|
|
3
|
+
export type CancellationSource = CancellationToken | CancellationSignal | AbortController | AbortSignal;
|
|
4
|
+
export type CancellationSignalWaitOptions = {
|
|
26
5
|
/**
|
|
27
|
-
*
|
|
28
|
-
* If false,
|
|
29
|
-
* @default true
|
|
30
|
-
*/
|
|
31
|
-
immediate?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Only propagate the first applicable state change, then disconnect.
|
|
6
|
+
* If true, the promise returned by `wait()` will reject with the error when the token is set.
|
|
7
|
+
* If false, it will resolve normally when the token is set.
|
|
34
8
|
* @default false
|
|
35
9
|
*/
|
|
36
|
-
|
|
10
|
+
throw?: boolean;
|
|
37
11
|
};
|
|
38
12
|
/**
|
|
39
|
-
* A
|
|
40
|
-
*
|
|
41
|
-
* It
|
|
42
|
-
* or convert to other signal types (like AbortSignal) without being able
|
|
43
|
-
* to change the token's state.
|
|
44
|
-
*
|
|
45
|
-
* It is both `PromiseLike<void>` (resolves when set) and `Subscribable<void>`
|
|
46
|
-
* (emits when set).
|
|
13
|
+
* A CancellationSignal represents a signal that can be used to indicate cancellation of an operation.
|
|
14
|
+
* It is immutable and can be shared across multiple operations.
|
|
15
|
+
* It can be created from one or more cancellation sources, such as other signals or AbortControllers.
|
|
47
16
|
*/
|
|
48
|
-
export declare class CancellationSignal implements
|
|
17
|
+
export declare class CancellationSignal implements Disposable, Subscribable<void>, InteropObservable<void> {
|
|
49
18
|
#private;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Observable which emits the current state (true for set, false for unset)
|
|
53
|
-
* and any subsequent state changes.
|
|
54
|
-
*/
|
|
55
|
-
readonly state$: Observable<boolean>;
|
|
56
|
-
/**
|
|
57
|
-
* Observable which emits `void` only when the token becomes set.
|
|
58
|
-
*/
|
|
59
|
-
readonly set$: Observable<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Observable which emits `void` only when the token becomes unset.
|
|
62
|
-
*/
|
|
63
|
-
readonly unset$: Observable<void>;
|
|
64
|
-
/**
|
|
65
|
-
* A promise that resolves with the next state of the token.
|
|
66
|
-
*/
|
|
67
|
-
get $state(): Promise<boolean>;
|
|
68
|
-
/**
|
|
69
|
-
* A promise that resolves when the token is next set.
|
|
70
|
-
* If the token is already set, it resolves immediately.
|
|
71
|
-
*/
|
|
72
|
-
get $set(): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* A promise that resolves when the token is next unset.
|
|
75
|
-
* If the token is already unset, it resolves immediately.
|
|
76
|
-
*/
|
|
77
|
-
get $unset(): Promise<void>;
|
|
78
|
-
/**
|
|
79
|
-
* The current state of the token.
|
|
80
|
-
* @returns `true` if set, `false` if unset.
|
|
81
|
-
*/
|
|
82
|
-
get state(): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Whether the token is currently in a 'set' state.
|
|
85
|
-
*/
|
|
19
|
+
get abortSignal(): AbortSignal;
|
|
86
20
|
get isSet(): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Whether the token is currently in an 'unset' state.
|
|
89
|
-
*/
|
|
90
21
|
get isUnset(): boolean;
|
|
22
|
+
get reason(): any;
|
|
23
|
+
constructor(sources: OneOrMany<CancellationSource>);
|
|
24
|
+
static from(sources: OneOrMany<CancellationSource>): CancellationSignal;
|
|
25
|
+
static timeout(milliseconds: number): CancellationSignal;
|
|
26
|
+
[Symbol.dispose](): void;
|
|
27
|
+
[Symbol.observable](): Subscribable<void>;
|
|
28
|
+
dispose(): void;
|
|
91
29
|
/**
|
|
92
|
-
*
|
|
30
|
+
* Creates a new CancellationToken that is also set when this signal is set.
|
|
31
|
+
* If this signal is already set, the new token will also be set.
|
|
93
32
|
*/
|
|
94
|
-
|
|
33
|
+
fork(): CancellationToken;
|
|
95
34
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
35
|
+
* Creates a new CancellationSignal that is set when either this signal or any of the specified parent signals are set.
|
|
36
|
+
* If any of the parent signals are already set, the new signal will also be set.
|
|
37
|
+
* @param parents The parent token or signal(s) to inherit from.
|
|
98
38
|
*/
|
|
99
|
-
|
|
39
|
+
inherit(parents: OneOrMany<CancellationSource>): CancellationSignal;
|
|
100
40
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
41
|
+
* Creates a new CancellationSignal that is set when either this signal or any of the specified parent signals are set.
|
|
42
|
+
* If any of the parent signals are already set, the new signal will also be set.
|
|
43
|
+
* If no parents are provided, it simply returns this signal.
|
|
44
|
+
* @param parents The parent token or signal(s) to optionally inherit from.
|
|
103
45
|
*/
|
|
104
|
-
|
|
46
|
+
optionallyInherit(parents?: OneOrMany<CancellationSource>): CancellationSignal;
|
|
105
47
|
/**
|
|
106
|
-
* Creates a new
|
|
107
|
-
*
|
|
108
|
-
* @see {@link connect}
|
|
48
|
+
* Creates a new CancellationSignal that is set when either this signal is set or the specified timeout elapses.
|
|
49
|
+
* @param milliseconds The timeout duration in milliseconds.
|
|
109
50
|
*/
|
|
110
|
-
|
|
51
|
+
withTimeout(milliseconds: number): CancellationSignal;
|
|
111
52
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @param
|
|
53
|
+
* Creates a new CancellationSignal that is set when either this signal is set or the specified timeout elapses.
|
|
54
|
+
* If no timeout is provided, it simply returns this signal.
|
|
55
|
+
* @param milliseconds The timeout duration in milliseconds.
|
|
115
56
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* Allows this object to be awaited. The promise resolves when the token is set.
|
|
119
|
-
* Implements the `PromiseLike<void>` interface.
|
|
120
|
-
*/
|
|
121
|
-
then<TResult>(onfulfilled?: ((value: void) => TResult | PromiseLike<TResult>) | null): Promise<TResult>;
|
|
57
|
+
withOptionalTimeout(milliseconds?: number): CancellationSignal;
|
|
58
|
+
subscribe(observer: Partial<Observer<void>>): Unsubscribable;
|
|
122
59
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* Implements the `Subscribable<void>` interface.
|
|
60
|
+
* Waits for the token to be set. Resolves or rejects when the token is set.
|
|
61
|
+
* @param options Configuration for the wait behavior.
|
|
126
62
|
*/
|
|
127
|
-
|
|
63
|
+
wait(options?: CancellationSignalWaitOptions): Promise<void>;
|
|
64
|
+
waitThrow(): Promise<void>;
|
|
65
|
+
throwIfSet(): void;
|
|
128
66
|
}
|
|
129
67
|
/**
|
|
130
|
-
* A CancellationToken
|
|
131
|
-
* It can be
|
|
132
|
-
*
|
|
133
|
-
* You can create child tokens, connect them to other async primitives
|
|
134
|
-
* (Promises, AbortSignals), and pass around its read-only `signal`
|
|
135
|
-
* to consumers that should only react to cancellation, not trigger it.
|
|
68
|
+
* A CancellationToken is a mutable cancellation source that can be set to signal cancellation.
|
|
69
|
+
* It extends CancellationSignal, so it can be used wherever a CancellationSignal is expected.
|
|
70
|
+
* It provides a `set()` method to signal cancellation, which will trigger any subscribers or waiters on the token or any tokens that inherit from it.
|
|
136
71
|
*/
|
|
137
72
|
export declare class CancellationToken extends CancellationSignal {
|
|
138
73
|
#private;
|
|
139
|
-
/**
|
|
140
|
-
* A read-only view of this token.
|
|
141
|
-
* Useful for passing to functions that should only be able to check for
|
|
142
|
-
* cancellation but not trigger it.
|
|
143
|
-
*/
|
|
144
74
|
get signal(): CancellationSignal;
|
|
145
75
|
/**
|
|
146
|
-
*
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Creates a token that is set when the source signals.
|
|
151
|
-
* @param source The event source to listen to.
|
|
152
|
-
* @example
|
|
153
|
-
* // From a fetch promise
|
|
154
|
-
* const token = CancellationToken.from(fetch('/api/data'));
|
|
155
|
-
*
|
|
156
|
-
* // From a browser AbortSignal
|
|
157
|
-
* const controller = new AbortController();
|
|
158
|
-
* const token = CancellationToken.from(controller.signal);
|
|
159
|
-
*/
|
|
160
|
-
static from(source: AbortSignal | PromiseLike<any> | Observable<void>, config?: ConnectConfig): CancellationToken;
|
|
161
|
-
/**
|
|
162
|
-
* Creates a token and connects it to an `Observable<boolean>` source.
|
|
163
|
-
* The token's state will mirror the boolean values emitted by the observable.
|
|
164
|
-
* @param source The observable source.
|
|
165
|
-
* @param config Configuration for the connection.
|
|
166
|
-
*/
|
|
167
|
-
static from(source: Observable<boolean>, config?: ConnectConfig): CancellationToken;
|
|
168
|
-
/**
|
|
169
|
-
* Connects an observable state source to a target token.
|
|
170
|
-
* @param source$ The observable providing boolean state.
|
|
171
|
-
* @param target The CancellationToken to update.
|
|
172
|
-
* @param config The connection configuration.
|
|
173
|
-
*/
|
|
174
|
-
static connect(source$: Observable<boolean>, target: CancellationToken, config?: ConnectConfig): void;
|
|
175
|
-
/**
|
|
176
|
-
* Makes this token a child of a parent token.
|
|
177
|
-
* State changes from the parent will propagate to this token.
|
|
178
|
-
* @param parent The token to inherit state from.
|
|
179
|
-
* @param config Configuration for the connection.
|
|
180
|
-
*/
|
|
181
|
-
inherit(parent: CancellationToken | CancellationSignal, config?: ConnectConfig): this;
|
|
182
|
-
/**
|
|
183
|
-
* Sets the token's state to `true`.
|
|
184
|
-
* This signals cancellation or completion of the associated operation.
|
|
185
|
-
*/
|
|
186
|
-
set(): void;
|
|
187
|
-
/**
|
|
188
|
-
* Sets the token's state to `false`.
|
|
189
|
-
* This can be used to reset the token.
|
|
190
|
-
*/
|
|
191
|
-
unset(): void;
|
|
192
|
-
/**
|
|
193
|
-
* Explicitly sets the state of the token.
|
|
194
|
-
* @param state `true` for set, `false` for unset.
|
|
195
|
-
*/
|
|
196
|
-
setState(state: boolean): void;
|
|
197
|
-
/**
|
|
198
|
-
* Puts the token into an errored state.
|
|
199
|
-
* All current and future subscribers will receive this error.
|
|
200
|
-
*/
|
|
201
|
-
error(error: Error): void;
|
|
202
|
-
/**
|
|
203
|
-
* Completes the token's lifecycle.
|
|
204
|
-
* No further state changes can occur. Active awaits may throw an error.
|
|
76
|
+
* Creates a new CancellationToken that is set when the parent signals.
|
|
77
|
+
* If the parent is already set, the new token will also be set.
|
|
78
|
+
* @param parents The parent token or signal(s) to inherit from.
|
|
205
79
|
*/
|
|
206
|
-
|
|
80
|
+
constructor(parents?: OneOrMany<CancellationSource>);
|
|
81
|
+
set(reason?: any): void;
|
|
207
82
|
}
|
|
83
|
+
export declare function sourcesToAbortSignal(...sources: OneOrMany<CancellationSource>[]): AbortSignal;
|