@tstdl/base 0.86.1 → 0.87.0
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/application/application.d.ts +3 -3
- package/application/application.js +9 -9
- package/authentication/client/authentication.service.js +3 -3
- package/cancellation/index.d.ts +1 -0
- package/cancellation/index.js +18 -0
- package/{utils/cancellation-token.d.ts → cancellation/token.d.ts} +33 -41
- package/{utils/cancellation-token.js → cancellation/token.js} +93 -49
- package/core.d.ts +6 -3
- package/core.js +12 -6
- package/data-structures/circular-buffer.d.ts +4 -4
- package/data-structures/circular-buffer.js +10 -10
- package/database/mongo/module.js +2 -2
- package/disposable/async-disposer.d.ts +4 -4
- package/disposable/async-disposer.js +6 -6
- package/distributed-loop/distributed-loop.d.ts +4 -4
- package/distributed-loop/distributed-loop.js +6 -6
- package/enumerable/async-enumerable.d.ts +2 -2
- package/enumerable/async-enumerable.js +2 -2
- package/enumerable/enumerable.d.ts +2 -2
- package/enumerable/enumerable.js +2 -2
- package/examples/api/streaming.js +3 -3
- package/http/client/adapters/undici-http-client.adapter.js +1 -1
- package/http/client/http-client-request.d.ts +5 -5
- package/http/client/http-client-request.js +9 -9
- package/http/server/node/node-http-server.js +2 -2
- package/injector/injector.js +5 -5
- package/injector/types.d.ts +3 -3
- package/lock/mongo/lock.js +2 -2
- package/lock/web/web-lock.js +2 -2
- package/message-bus/message-bus-base.d.ts +2 -2
- package/message-bus/message-bus-base.js +2 -2
- package/migration/migrator.js +2 -2
- package/module/module-base.d.ts +3 -3
- package/module/module-base.js +2 -2
- package/module/module-metric-reporter.d.ts +2 -2
- package/module/module-metric-reporter.js +3 -3
- package/module/modules/function.module.d.ts +4 -4
- package/module/modules/function.module.js +2 -2
- package/module/modules/web-server.module.d.ts +2 -2
- package/module/modules/web-server.module.js +2 -2
- package/package.json +4 -4
- package/process-shutdown.d.ts +4 -2
- package/process-shutdown.js +15 -5
- package/queue/mongo/queue.d.ts +5 -5
- package/queue/mongo/queue.js +7 -7
- package/queue/queue.d.ts +3 -3
- package/search-index/elastic/module.js +2 -2
- package/signals/to-signal-2.d.ts +6 -4
- package/utils/async-iterable-helpers/buffer.js +2 -2
- package/utils/async-iterable-helpers/observable-iterable.js +3 -3
- package/utils/async-iterable-helpers/take-until.d.ts +2 -2
- package/utils/async-iterable-helpers/take-until.js +7 -7
- package/utils/backoff.d.ts +7 -7
- package/utils/backoff.js +7 -7
- package/utils/event-loop.d.ts +2 -2
- package/utils/event-loop.js +2 -2
- package/utils/feedable-async-iterable.js +3 -3
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/iterable-helpers/take-until.d.ts +2 -2
- package/utils/iterable-helpers/take-until.js +2 -2
- package/utils/patch-worker.d.ts +1 -1
- package/utils/patch-worker.js +2 -2
- package/utils/periodic-reporter.js +2 -2
- package/utils/timing.d.ts +3 -3
- package/utils/timing.js +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.87.0",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@types/mjml": "4.7",
|
|
35
35
|
"@types/node": "20",
|
|
36
36
|
"@types/nodemailer": "6.4",
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
38
|
-
"@typescript-eslint/parser": "6.
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "6.5",
|
|
38
|
+
"@typescript-eslint/parser": "6.5",
|
|
39
39
|
"concurrently": "8.2",
|
|
40
40
|
"esbuild": "0.19",
|
|
41
41
|
"eslint": "8.48",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@elastic/elasticsearch": "^8.9",
|
|
50
50
|
"@koa/router": "^12.0",
|
|
51
|
-
"@tstdl/angular": "^0.
|
|
51
|
+
"@tstdl/angular": "^0.87",
|
|
52
52
|
"@zxcvbn-ts/core": "^3.0",
|
|
53
53
|
"@zxcvbn-ts/language-common": "^3.0",
|
|
54
54
|
"@zxcvbn-ts/language-de": "^3.0",
|
package/process-shutdown.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { CancellationSignal } from './cancellation/index.js';
|
|
2
|
+
import { CancellationToken } from './cancellation/index.js';
|
|
1
3
|
import type { Logger } from './logger/index.js';
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
+
export declare function getShutdownToken(): CancellationToken;
|
|
5
|
+
export declare function getShutdownSignal(): CancellationSignal;
|
|
4
6
|
export declare function setProcessShutdownLogger(shutdownLogger: Logger): void;
|
|
5
7
|
export declare function requestShutdown(exitCode?: number): void;
|
|
6
8
|
export declare function forceShutdown(exitCode?: number): void;
|
package/process-shutdown.js
CHANGED
|
@@ -19,17 +19,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var process_shutdown_exports = {};
|
|
20
20
|
__export(process_shutdown_exports, {
|
|
21
21
|
forceShutdown: () => forceShutdown,
|
|
22
|
+
getShutdownSignal: () => getShutdownSignal,
|
|
23
|
+
getShutdownToken: () => getShutdownToken,
|
|
22
24
|
initializeSignals: () => initializeSignals,
|
|
23
25
|
requestShutdown: () => requestShutdown,
|
|
24
|
-
setProcessShutdownLogger: () => setProcessShutdownLogger
|
|
25
|
-
shutdownToken: () => shutdownToken
|
|
26
|
+
setProcessShutdownLogger: () => setProcessShutdownLogger
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(process_shutdown_exports);
|
|
28
|
-
var
|
|
29
|
+
var import_cancellation = require("./cancellation/index.js");
|
|
29
30
|
var import_type_guards = require("./utils/type-guards.js");
|
|
30
31
|
const quitSignals = ["SIGTERM", "SIGINT", "SIGHUP", "SIGBREAK"];
|
|
31
32
|
const quitEvents = ["uncaughtException", "unhandledRejection", "rejectionHandled"];
|
|
32
|
-
|
|
33
|
+
let shutdownToken;
|
|
34
|
+
function getShutdownToken() {
|
|
35
|
+
if ((0, import_type_guards.isUndefined)(shutdownToken)) {
|
|
36
|
+
shutdownToken = new import_cancellation.CancellationToken();
|
|
37
|
+
}
|
|
38
|
+
return shutdownToken;
|
|
39
|
+
}
|
|
40
|
+
function getShutdownSignal() {
|
|
41
|
+
return getShutdownToken().signal;
|
|
42
|
+
}
|
|
33
43
|
let logger;
|
|
34
44
|
function setProcessShutdownLogger(shutdownLogger) {
|
|
35
45
|
logger = shutdownLogger;
|
|
@@ -40,7 +50,7 @@ function requestShutdown(exitCode = 1) {
|
|
|
40
50
|
return;
|
|
41
51
|
}
|
|
42
52
|
shutdownRequested = true;
|
|
43
|
-
|
|
53
|
+
getShutdownToken().set();
|
|
44
54
|
const timeout = setTimeout(() => {
|
|
45
55
|
logger.warn("forcefully quitting after 20 seconds...");
|
|
46
56
|
setTimeout(() => process.exit(exitCode), 1);
|
package/queue/mongo/queue.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../../cancellation/index.js';
|
|
1
2
|
import { Lock } from '../../lock/index.js';
|
|
2
3
|
import { MessageBusProvider } from '../../message-bus/index.js';
|
|
3
|
-
import type { EnqueueManyItem, EnqueueOptions, Job, JobTag
|
|
4
|
-
import { Queue } from '../../queue/index.js';
|
|
5
|
-
import type { ReadonlyCancellationToken } from '../../utils/cancellation-token.js';
|
|
4
|
+
import type { EnqueueManyItem, EnqueueOptions, Job, JobTag } from '../../queue/index.js';
|
|
5
|
+
import { Queue, type QueueConfig } from '../../queue/index.js';
|
|
6
6
|
import { MongoJobRepository } from './mongo-job.repository.js';
|
|
7
7
|
export declare class MongoQueue<T = unknown> extends Queue<T> {
|
|
8
8
|
private readonly repository;
|
|
@@ -27,6 +27,6 @@ export declare class MongoQueue<T = unknown> extends Queue<T> {
|
|
|
27
27
|
dequeueMany(count: number): Promise<Job<T>[]>;
|
|
28
28
|
acknowledge(job: Job<T>): Promise<void>;
|
|
29
29
|
acknowledgeMany(jobs: Job<T>[]): Promise<void>;
|
|
30
|
-
getConsumer(
|
|
31
|
-
getBatchConsumer(size: number,
|
|
30
|
+
getConsumer(cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>>;
|
|
31
|
+
getBatchConsumer(size: number, cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>[]>;
|
|
32
32
|
}
|
package/queue/mongo/queue.js
CHANGED
|
@@ -21,6 +21,7 @@ __export(queue_exports, {
|
|
|
21
21
|
MongoQueue: () => MongoQueue
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(queue_exports);
|
|
24
|
+
var import_cancellation = require("../../cancellation/index.js");
|
|
24
25
|
var import_id = require("../../database/id.js");
|
|
25
26
|
var import_decorators = require("../../injector/decorators.js");
|
|
26
27
|
var import_lock = require("../../lock/index.js");
|
|
@@ -28,7 +29,6 @@ var import_message_bus = require("../../message-bus/index.js");
|
|
|
28
29
|
var import_queue = require("../../queue/index.js");
|
|
29
30
|
var import_alphabet = require("../../utils/alphabet.js");
|
|
30
31
|
var import_backoff = require("../../utils/backoff.js");
|
|
31
|
-
var import_cancellation_token = require("../../utils/cancellation-token.js");
|
|
32
32
|
var import_date_time = require("../../utils/date-time.js");
|
|
33
33
|
var import_property_name = require("../../utils/object/property-name.js");
|
|
34
34
|
var import_random = require("../../utils/random.js");
|
|
@@ -215,9 +215,9 @@ let MongoQueue = class MongoQueue2 extends import_queue.Queue {
|
|
|
215
215
|
const jobIds = jobs.map((job) => job.id);
|
|
216
216
|
return this.cancelMany(jobIds);
|
|
217
217
|
}
|
|
218
|
-
async *getConsumer(
|
|
219
|
-
const continueToken =
|
|
220
|
-
for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions,
|
|
218
|
+
async *getConsumer(cancellationSignal) {
|
|
219
|
+
const continueToken = import_cancellation.CancellationToken.from(this.messageBus.allMessages$);
|
|
220
|
+
for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationSignal)) {
|
|
221
221
|
const job = await this.dequeue();
|
|
222
222
|
if (job != void 0) {
|
|
223
223
|
yield job;
|
|
@@ -227,9 +227,9 @@ let MongoQueue = class MongoQueue2 extends import_queue.Queue {
|
|
|
227
227
|
}
|
|
228
228
|
continueToken.complete();
|
|
229
229
|
}
|
|
230
|
-
async *getBatchConsumer(size,
|
|
231
|
-
const continueToken =
|
|
232
|
-
for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions,
|
|
230
|
+
async *getBatchConsumer(size, cancellationSignal) {
|
|
231
|
+
const continueToken = import_cancellation.CancellationToken.from(this.messageBus.allMessages$);
|
|
232
|
+
for await (const backoff of (0, import_backoff.backoffGenerator)(backoffOptions, cancellationSignal)) {
|
|
233
233
|
const jobs = await this.dequeueMany(size);
|
|
234
234
|
if (jobs.length > 0) {
|
|
235
235
|
yield jobs;
|
package/queue/queue.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
1
2
|
import type { Resolvable } from '../injector/interfaces.js';
|
|
2
3
|
import { resolveArgumentType } from '../injector/interfaces.js';
|
|
3
|
-
import type { ReadonlyCancellationToken } from '../utils/cancellation-token.js';
|
|
4
4
|
import { QueueEnqueueBatch } from './enqueue-batch.js';
|
|
5
5
|
export type JobTag = string | number | null;
|
|
6
6
|
export type Job<T> = {
|
|
@@ -53,6 +53,6 @@ export declare abstract class Queue<T> implements Resolvable<QueueArgument> {
|
|
|
53
53
|
abstract dequeueMany(count: number): Promise<Job<T>[]>;
|
|
54
54
|
abstract acknowledge(job: Job<T>): Promise<void>;
|
|
55
55
|
abstract acknowledgeMany(jobs: Job<T>[]): Promise<void>;
|
|
56
|
-
abstract getConsumer(
|
|
57
|
-
abstract getBatchConsumer(size: number,
|
|
56
|
+
abstract getConsumer(cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>>;
|
|
57
|
+
abstract getBatchConsumer(size: number, cancellationSignal: CancellationSignal): AsyncIterableIterator<Job<T>[]>;
|
|
58
58
|
}
|
|
@@ -48,9 +48,9 @@ import_injector.Injector.registerSingleton(import_elasticsearch.Client, {
|
|
|
48
48
|
context.addDisposeHandler(async () => client.close().then(() => context.data.logger.info("closed connection")));
|
|
49
49
|
return client;
|
|
50
50
|
},
|
|
51
|
-
async afterResolve(client, options, {
|
|
51
|
+
async afterResolve(client, options, { cancellationSignal, data: { logger } }) {
|
|
52
52
|
const url = getUrl(options.node ?? options.nodes);
|
|
53
|
-
await (0, import_core.connect)(`elasticsearch (${url})`, async () => client.ping().then((alive) => (0, import_type_guards.assert)(alive, "failed to connect")), logger,
|
|
53
|
+
await (0, import_core.connect)(`elasticsearch (${url})`, async () => client.ping().then((alive) => (0, import_type_guards.assert)(alive, "failed to connect")), logger, cancellationSignal);
|
|
54
54
|
},
|
|
55
55
|
defaultArgumentProvider() {
|
|
56
56
|
return elasticsearchModuleConfig.defaultOptions;
|
package/signals/to-signal-2.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type { Subscribable } from 'rxjs';
|
|
1
|
+
import type { Observable, Subscribable } from 'rxjs';
|
|
2
2
|
import type { Signal, ToSignalOptions } from './api.js';
|
|
3
|
+
type ToSignalInput<T> = Observable<T> | Subscribable<T>;
|
|
3
4
|
export type ToSignal2Options<T> = ToSignalOptions<T> & {
|
|
4
5
|
/** defer subscription until signal is used */
|
|
5
6
|
lazy?: boolean;
|
|
6
7
|
};
|
|
7
8
|
/** like `toSignal`, except that it uses untracked internal operations (required for some scenarios, but might be less safe in terms of bugs catching) and has the ability to subscribe lazily */
|
|
8
|
-
export declare function toSignal2<T>(source:
|
|
9
|
-
export declare function toSignal2<T>(source:
|
|
9
|
+
export declare function toSignal2<T>(source: ToSignalInput<T>): Signal<T | undefined>;
|
|
10
|
+
export declare function toSignal2<T>(source: ToSignalInput<T>, options: ToSignal2Options<undefined> & {
|
|
10
11
|
requireSync: true;
|
|
11
12
|
}): Signal<T>;
|
|
12
|
-
export declare function toSignal2<T, const I = undefined>(source:
|
|
13
|
+
export declare function toSignal2<T, const I = undefined>(source: ToSignalInput<T>, options: ToSignal2Options<I> & {
|
|
13
14
|
requireSync?: false;
|
|
14
15
|
}): Signal<T | I>;
|
|
16
|
+
export {};
|
|
@@ -21,13 +21,13 @@ __export(buffer_exports, {
|
|
|
21
21
|
bufferAsync: () => bufferAsync
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(buffer_exports);
|
|
24
|
+
var import_token = require("../../cancellation/token.js");
|
|
24
25
|
var import_circular_buffer = require("../../data-structures/circular-buffer.js");
|
|
25
|
-
var import_cancellation_token = require("../cancellation-token.js");
|
|
26
26
|
var import_object = require("../object/object.js");
|
|
27
27
|
var import_take_until = require("./take-until.js");
|
|
28
28
|
async function* bufferAsync(iterable, size) {
|
|
29
29
|
const buffer = new import_circular_buffer.CircularBuffer(Math.max(1, size));
|
|
30
|
-
const consumerEndedToken = new
|
|
30
|
+
const consumerEndedToken = new import_token.CancellationToken();
|
|
31
31
|
let consumerHasError = false;
|
|
32
32
|
let consumerError;
|
|
33
33
|
void (async () => {
|
|
@@ -21,13 +21,13 @@ __export(observable_iterable_exports, {
|
|
|
21
21
|
observableAsyncIterable: () => observableAsyncIterable
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(observable_iterable_exports);
|
|
24
|
+
var import_token = require("../../cancellation/token.js");
|
|
24
25
|
var import_rxjs = require("rxjs");
|
|
25
26
|
var import_observable_array = require("../../collections/observable/observable-array.js");
|
|
26
|
-
var import_cancellation_token = require("../cancellation-token.js");
|
|
27
27
|
async function* observableAsyncIterable(observable) {
|
|
28
28
|
const buffer = new import_observable_array.ObservableArray();
|
|
29
|
-
const completeToken = new
|
|
30
|
-
const errorToken = new
|
|
29
|
+
const completeToken = new import_token.CancellationToken();
|
|
30
|
+
const errorToken = new import_token.CancellationToken();
|
|
31
31
|
let error;
|
|
32
32
|
const subscription = observable.subscribe({
|
|
33
33
|
next: (value) => buffer.add(value),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../../cancellation/token.js';
|
|
1
2
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
|
-
|
|
3
|
-
export declare function takeUntilAsync<T>(iterable: AnyIterable<T>, cancellationToken: ReadonlyCancellationToken): AsyncIterableIterator<T>;
|
|
3
|
+
export declare function takeUntilAsync<T>(iterable: AnyIterable<T>, cancellationSignal: CancellationSignal): AsyncIterableIterator<T>;
|
|
@@ -23,23 +23,23 @@ __export(take_until_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(take_until_exports);
|
|
24
24
|
var import_rxjs = require("rxjs");
|
|
25
25
|
var import_is_async_iterable = require("./is-async-iterable.js");
|
|
26
|
-
function takeUntilAsync(iterable,
|
|
27
|
-
return (0, import_is_async_iterable.isAsyncIterable)(iterable) ? async(iterable,
|
|
26
|
+
function takeUntilAsync(iterable, cancellationSignal) {
|
|
27
|
+
return (0, import_is_async_iterable.isAsyncIterable)(iterable) ? async(iterable, cancellationSignal) : sync(iterable, cancellationSignal);
|
|
28
28
|
}
|
|
29
|
-
async function* sync(iterable,
|
|
30
|
-
if (
|
|
29
|
+
async function* sync(iterable, cancellationSignal) {
|
|
30
|
+
if (cancellationSignal.isSet) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
for (const item of iterable) {
|
|
34
34
|
yield item;
|
|
35
|
-
if (
|
|
35
|
+
if (cancellationSignal.isSet) {
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
async function* async(iterable,
|
|
40
|
+
async function* async(iterable, cancellationSignal) {
|
|
41
41
|
const iterator = iterable[Symbol.asyncIterator]();
|
|
42
|
-
const cancel$ =
|
|
42
|
+
const cancel$ = cancellationSignal.set$.pipe((0, import_rxjs.map)(() => ({ done: true, value: void 0 })));
|
|
43
43
|
try {
|
|
44
44
|
while (true) {
|
|
45
45
|
const result = await (0, import_rxjs.firstValueFrom)((0, import_rxjs.race)([iterator.next(), cancel$]));
|
package/utils/backoff.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { CancellationToken } from '
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
|
+
import { CancellationToken } from '../cancellation/token.js';
|
|
3
3
|
export type BackoffStrategy = 'linear' | 'exponential';
|
|
4
4
|
export type BackoffOptions = {
|
|
5
5
|
/**
|
|
@@ -51,22 +51,22 @@ export declare class BackoffHelper {
|
|
|
51
51
|
* @param loopFunction function to call
|
|
52
52
|
*/
|
|
53
53
|
export declare function autoBackoffLoop(options: BackoffOptions, loopFunction: BackoffLoopFunction, extras?: {
|
|
54
|
-
|
|
54
|
+
cancellationSignal?: CancellationSignal;
|
|
55
55
|
errorHandler?: (error: Error) => void;
|
|
56
56
|
}): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* runs a function until token is set or controller returns.
|
|
59
59
|
* @param options backoff options
|
|
60
|
-
* @param cancellationToken
|
|
60
|
+
* @param cancellationToken signal to cancel loop
|
|
61
61
|
* @param loopFunction function to call
|
|
62
62
|
*/
|
|
63
63
|
export declare function backoffLoop(options: BackoffOptions, loopFunction: BackoffLoopFunction, extras?: {
|
|
64
|
-
|
|
64
|
+
cancellationSignal?: CancellationSignal;
|
|
65
65
|
}): Promise<void>;
|
|
66
66
|
/**
|
|
67
67
|
* generates endless function which, when called, backs off next iteration
|
|
68
68
|
* @param options backoff options
|
|
69
|
-
* @param
|
|
69
|
+
* @param cancellationSignal signal to cancel loop
|
|
70
70
|
* @example
|
|
71
71
|
* for await (const backoff of backoffGenerator(options, token)) {
|
|
72
72
|
* if (iWantToBackoff) {
|
|
@@ -74,4 +74,4 @@ export declare function backoffLoop(options: BackoffOptions, loopFunction: Backo
|
|
|
74
74
|
* }
|
|
75
75
|
* }
|
|
76
76
|
*/
|
|
77
|
-
export declare function backoffGenerator(options: BackoffOptions,
|
|
77
|
+
export declare function backoffGenerator(options: BackoffOptions, cancellationSignal: CancellationSignal): AsyncIterableIterator<BackoffGeneratorYield>;
|
package/utils/backoff.js
CHANGED
|
@@ -24,7 +24,7 @@ __export(backoff_exports, {
|
|
|
24
24
|
backoffLoop: () => backoffLoop
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(backoff_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_token = require("../cancellation/token.js");
|
|
28
28
|
var import_noop = require("./noop.js");
|
|
29
29
|
var import_timing = require("./timing.js");
|
|
30
30
|
var import_type_guards = require("./type-guards.js");
|
|
@@ -58,11 +58,11 @@ async function autoBackoffLoop(options, loopFunction, extras) {
|
|
|
58
58
|
errorHandler(error);
|
|
59
59
|
controller.backoff();
|
|
60
60
|
}
|
|
61
|
-
}, {
|
|
61
|
+
}, { cancellationSignal: extras?.cancellationSignal });
|
|
62
62
|
}
|
|
63
63
|
async function backoffLoop(options, loopFunction, extras) {
|
|
64
64
|
const backoffHelper = new BackoffHelper(options);
|
|
65
|
-
const loopCancellationToken = extras?.
|
|
65
|
+
const loopCancellationToken = extras?.cancellationSignal?.createChild({ unset: false, complete: false }) ?? new import_token.CancellationToken();
|
|
66
66
|
let backoff = false;
|
|
67
67
|
const controller = {
|
|
68
68
|
backoff: () => backoff = true,
|
|
@@ -82,15 +82,15 @@ async function backoffLoop(options, loopFunction, extras) {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
async function* backoffGenerator(options,
|
|
85
|
+
async function* backoffGenerator(options, cancellationSignal) {
|
|
86
86
|
const backoffHelper = new BackoffHelper(options);
|
|
87
|
-
while (
|
|
87
|
+
while (cancellationSignal.isUnset) {
|
|
88
88
|
let backoff = false;
|
|
89
|
-
let timeoutToken =
|
|
89
|
+
let timeoutToken = cancellationSignal;
|
|
90
90
|
const backoffFunction = (continueToken) => {
|
|
91
91
|
backoff = true;
|
|
92
92
|
if ((0, import_type_guards.isDefined)(continueToken)) {
|
|
93
|
-
timeoutToken =
|
|
93
|
+
timeoutToken = cancellationSignal.createChild().inherit(continueToken);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
yield backoffFunction;
|
package/utils/event-loop.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
1
2
|
import type { Logger } from '../logger/index.js';
|
|
2
|
-
import type { ReadonlyCancellationToken } from './cancellation-token.js';
|
|
3
3
|
export declare function measureEventLoopDelay(): Promise<number>;
|
|
4
|
-
export declare function runEventLoopWatcher(logger: Logger,
|
|
4
|
+
export declare function runEventLoopWatcher(logger: Logger, cancellationSignal: CancellationSignal): void;
|
package/utils/event-loop.js
CHANGED
|
@@ -34,9 +34,9 @@ async function measureEventLoopDelay() {
|
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
function runEventLoopWatcher(logger,
|
|
37
|
+
function runEventLoopWatcher(logger, cancellationSignal) {
|
|
38
38
|
const sampler = new import_periodic_sampler.PeriodicSampler(measureEventLoopDelay, 50);
|
|
39
39
|
sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0, import_format.formatDuration)(delay, 2)}`));
|
|
40
40
|
sampler.start();
|
|
41
|
-
|
|
41
|
+
cancellationSignal.then(async () => sampler.stop());
|
|
42
42
|
}
|
|
@@ -21,9 +21,9 @@ __export(feedable_async_iterable_exports, {
|
|
|
21
21
|
FeedableAsyncIterable: () => FeedableAsyncIterable
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(feedable_async_iterable_exports);
|
|
24
|
-
var import_circular_buffer = require("../data-structures/circular-buffer.js");
|
|
25
24
|
var import_rxjs = require("rxjs");
|
|
26
|
-
var
|
|
25
|
+
var import_token = require("../cancellation/token.js");
|
|
26
|
+
var import_circular_buffer = require("../data-structures/circular-buffer.js");
|
|
27
27
|
class FeedableAsyncIterable {
|
|
28
28
|
readSubject;
|
|
29
29
|
closedToken;
|
|
@@ -42,7 +42,7 @@ class FeedableAsyncIterable {
|
|
|
42
42
|
}
|
|
43
43
|
constructor() {
|
|
44
44
|
this.readSubject = new import_rxjs.Subject();
|
|
45
|
-
this.closedToken = new
|
|
45
|
+
this.closedToken = new import_token.CancellationToken();
|
|
46
46
|
this.buffer = new import_circular_buffer.CircularBuffer();
|
|
47
47
|
}
|
|
48
48
|
feed(item) {
|
package/utils/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * from './base64.js';
|
|
|
6
6
|
export * from './benchmark.js';
|
|
7
7
|
export * from './binary-search.js';
|
|
8
8
|
export * from './binary.js';
|
|
9
|
-
export * from './cancellation-token.js';
|
|
10
9
|
export * from './clone.js';
|
|
11
10
|
export * from './comparison.js';
|
|
12
11
|
export * from './date-time.js';
|
package/utils/index.js
CHANGED
|
@@ -23,7 +23,6 @@ __reExport(utils_exports, require("./base64.js"), module.exports);
|
|
|
23
23
|
__reExport(utils_exports, require("./benchmark.js"), module.exports);
|
|
24
24
|
__reExport(utils_exports, require("./binary-search.js"), module.exports);
|
|
25
25
|
__reExport(utils_exports, require("./binary.js"), module.exports);
|
|
26
|
-
__reExport(utils_exports, require("./cancellation-token.js"), module.exports);
|
|
27
26
|
__reExport(utils_exports, require("./clone.js"), module.exports);
|
|
28
27
|
__reExport(utils_exports, require("./comparison.js"), module.exports);
|
|
29
28
|
__reExport(utils_exports, require("./date-time.js"), module.exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function takeUntil<T>(iterable: Iterable<T>,
|
|
1
|
+
import type { CancellationSignal } from '../../cancellation/token.js';
|
|
2
|
+
export declare function takeUntil<T>(iterable: Iterable<T>, cancellationSignal: CancellationSignal): IterableIterator<T>;
|
|
@@ -21,9 +21,9 @@ __export(take_until_exports, {
|
|
|
21
21
|
takeUntil: () => takeUntil
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(take_until_exports);
|
|
24
|
-
function* takeUntil(iterable,
|
|
24
|
+
function* takeUntil(iterable, cancellationSignal) {
|
|
25
25
|
const iterator = iterable[Symbol.iterator]();
|
|
26
|
-
while (
|
|
26
|
+
while (cancellationSignal.isUnset) {
|
|
27
27
|
const result = iterator.next();
|
|
28
28
|
if (result.done == true) {
|
|
29
29
|
return;
|
package/utils/patch-worker.d.ts
CHANGED
package/utils/patch-worker.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(patch_worker_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(patch_worker_exports);
|
|
24
24
|
var import_rxjs = require("rxjs");
|
|
25
|
-
var
|
|
25
|
+
var import_token = require("../cancellation/token.js");
|
|
26
26
|
var import_timing = require("./timing.js");
|
|
27
27
|
var import_type_guards = require("./type-guards.js");
|
|
28
28
|
const defaultDebounceTime = 5e3;
|
|
@@ -37,7 +37,7 @@ class PatchWorker {
|
|
|
37
37
|
this.options = options;
|
|
38
38
|
this.patchAddedSubject = new import_rxjs.Subject();
|
|
39
39
|
this.handleSubject = new import_rxjs.Subject();
|
|
40
|
-
this.completeToken = new
|
|
40
|
+
this.completeToken = new import_token.CancellationToken();
|
|
41
41
|
this.patch = void 0;
|
|
42
42
|
if ((0, import_type_guards.isDefined)(options.handleOn)) {
|
|
43
43
|
this.handleOn(options.handleOn);
|
|
@@ -22,8 +22,8 @@ __export(periodic_reporter_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(periodic_reporter_exports);
|
|
24
24
|
var import_rxjs = require("rxjs");
|
|
25
|
+
var import_token = require("../cancellation/token.js");
|
|
25
26
|
var import_deferred_promise = require("../promise/deferred-promise.js");
|
|
26
|
-
var import_cancellation_token = require("./cancellation-token.js");
|
|
27
27
|
var import_timing = require("./timing.js");
|
|
28
28
|
class PeriodicReporter {
|
|
29
29
|
reportSubject;
|
|
@@ -43,7 +43,7 @@ class PeriodicReporter {
|
|
|
43
43
|
this.ignoreZero = ignoreZero;
|
|
44
44
|
this.resetAfterReport = resetAfterReport;
|
|
45
45
|
this.running = false;
|
|
46
|
-
this.stopToken = new
|
|
46
|
+
this.stopToken = new import_token.CancellationToken();
|
|
47
47
|
this.stopped = new import_deferred_promise.DeferredPromise();
|
|
48
48
|
this.reportSubject = new import_rxjs.Subject();
|
|
49
49
|
}
|
package/utils/timing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CancellationSignal } from '../cancellation/token.js';
|
|
2
2
|
import type { ValueOrProvider } from './value-or-provider.js';
|
|
3
3
|
/** timeout for specified duration */
|
|
4
4
|
export declare function timeout(milliseconds?: number, options?: {
|
|
@@ -7,9 +7,9 @@ export declare function timeout(milliseconds?: number, options?: {
|
|
|
7
7
|
/** timeout until specified time */
|
|
8
8
|
export declare function timeoutUntil(timestamp: number | Date): Promise<void>;
|
|
9
9
|
/** timeout for specified duration */
|
|
10
|
-
export declare function cancelableTimeout(milliseconds: number,
|
|
10
|
+
export declare function cancelableTimeout(milliseconds: number, cancelSignal: CancellationSignal): Promise<boolean>;
|
|
11
11
|
/** timeout until specified time */
|
|
12
|
-
export declare function cancelableTimeoutUntil(timestamp: number | Date,
|
|
12
|
+
export declare function cancelableTimeoutUntil(timestamp: number | Date, cancelSignal: CancellationSignal): Promise<boolean>;
|
|
13
13
|
export declare function withTimeout<T>(milliseconds: number, promiseOrProvider: ValueOrProvider<Promise<T>>, options?: {
|
|
14
14
|
errorMessage?: string;
|
|
15
15
|
}): Promise<T>;
|
package/utils/timing.js
CHANGED
|
@@ -29,8 +29,8 @@ __export(timing_exports, {
|
|
|
29
29
|
withTimeout: () => withTimeout
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(timing_exports);
|
|
32
|
-
var import_timeout_error = require("../error/timeout.error.js");
|
|
33
32
|
var import_rxjs = require("rxjs");
|
|
33
|
+
var import_timeout_error = require("../error/timeout.error.js");
|
|
34
34
|
var import_throw = require("./throw.js");
|
|
35
35
|
var import_value_or_provider = require("./value-or-provider.js");
|
|
36
36
|
async function timeout(milliseconds = 0, options) {
|
|
@@ -47,16 +47,16 @@ async function timeoutUntil(timestamp) {
|
|
|
47
47
|
const left = timestamp.valueOf() - Date.now();
|
|
48
48
|
return timeout(left);
|
|
49
49
|
}
|
|
50
|
-
async function cancelableTimeout(milliseconds,
|
|
50
|
+
async function cancelableTimeout(milliseconds, cancelSignal) {
|
|
51
51
|
return (0, import_rxjs.firstValueFrom)((0, import_rxjs.race)([
|
|
52
52
|
(0, import_rxjs.timer)(milliseconds).pipe((0, import_rxjs.map)(() => false)),
|
|
53
|
-
|
|
53
|
+
cancelSignal.set$.pipe((0, import_rxjs.map)(() => true))
|
|
54
54
|
// eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
55
55
|
]));
|
|
56
56
|
}
|
|
57
|
-
async function cancelableTimeoutUntil(timestamp,
|
|
57
|
+
async function cancelableTimeoutUntil(timestamp, cancelSignal) {
|
|
58
58
|
const left = timestamp.valueOf() - Date.now();
|
|
59
|
-
return cancelableTimeout(left,
|
|
59
|
+
return cancelableTimeout(left, cancelSignal);
|
|
60
60
|
}
|
|
61
61
|
async function withTimeout(milliseconds, promiseOrProvider, options) {
|
|
62
62
|
const abortController = new AbortController();
|