@mtkruto/browser 0.128.0 → 0.129.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/esm/0_deps.d.ts +4 -3
- package/esm/0_deps.d.ts.map +1 -1
- package/esm/0_deps.js +4 -3
- package/esm/3_types.d.ts +3 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +3 -0
- package/esm/client/1_client_generic.d.ts +19 -1
- package/esm/client/1_client_generic.d.ts.map +1 -1
- package/esm/client/2_account_manager.d.ts +3 -0
- package/esm/client/2_account_manager.d.ts.map +1 -1
- package/esm/client/2_account_manager.js +16 -1
- package/esm/client/6_client.d.ts +19 -1
- package/esm/client/6_client.d.ts.map +1 -1
- package/esm/client/6_client.js +24 -0
- package/esm/client/6_client_dispatcher.d.ts +19 -1
- package/esm/client/6_client_dispatcher.d.ts.map +1 -1
- package/esm/client/6_client_dispatcher.js +24 -0
- package/esm/types/0_calling_code.d.ts +27 -0
- package/esm/types/0_calling_code.d.ts.map +1 -0
- package/esm/types/0_calling_code.js +26 -0
- package/esm/types/0_timezone.d.ts +31 -0
- package/esm/types/0_timezone.d.ts.map +1 -0
- package/esm/types/0_timezone.js +26 -0
- package/esm/types/1_chat_p.d.ts +1 -1
- package/esm/types/1_chat_p.d.ts.map +1 -1
- package/esm/types/1_chat_p.js +1 -1
- package/esm/types/1_country.d.ts +30 -0
- package/esm/types/1_country.d.ts.map +1 -0
- package/esm/types/1_country.js +30 -0
- package/esm/types/2_user.d.ts +1 -1
- package/esm/types/2_user.d.ts.map +1 -1
- package/esm/types/2_user.js +2 -2
- package/package.json +1 -1
- package/script/0_deps.d.ts +4 -3
- package/script/0_deps.d.ts.map +1 -1
- package/script/0_deps.js +13 -12
- package/script/3_types.d.ts +3 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +3 -0
- package/script/client/1_client_generic.d.ts +19 -1
- package/script/client/1_client_generic.d.ts.map +1 -1
- package/script/client/2_account_manager.d.ts +3 -0
- package/script/client/2_account_manager.d.ts.map +1 -1
- package/script/client/2_account_manager.js +15 -0
- package/script/client/6_client.d.ts +19 -1
- package/script/client/6_client.d.ts.map +1 -1
- package/script/client/6_client.js +24 -0
- package/script/client/6_client_dispatcher.d.ts +19 -1
- package/script/client/6_client_dispatcher.d.ts.map +1 -1
- package/script/client/6_client_dispatcher.js +24 -0
- package/script/types/0_calling_code.d.ts +27 -0
- package/script/types/0_calling_code.d.ts.map +1 -0
- package/script/types/0_calling_code.js +29 -0
- package/script/types/0_timezone.d.ts +31 -0
- package/script/types/0_timezone.d.ts.map +1 -0
- package/script/types/0_timezone.js +29 -0
- package/script/types/1_chat_p.d.ts +1 -1
- package/script/types/1_chat_p.d.ts.map +1 -1
- package/script/types/1_chat_p.js +1 -1
- package/script/types/1_country.d.ts +30 -0
- package/script/types/1_country.d.ts.map +1 -0
- package/script/types/1_country.js +33 -0
- package/script/types/2_user.d.ts +1 -1
- package/script/types/2_user.d.ts.map +1 -1
- package/script/types/2_user.js +2 -2
- package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
- package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/_util.js +0 -6
- package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
- package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -46
- package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
- package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -41
- package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
- package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -57
- package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
- package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/mod.js +0 -23
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -154
- package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
- package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/retry.js +0 -147
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +0 -79
- package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
- package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/_util.js +0 -9
- package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
- package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -49
- package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
- package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -44
- package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
- package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -60
- package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
- package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/mod.js +0 -39
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -158
- package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
- package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/retry.js +0 -152
- package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
- package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +0 -82
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** Options for {@linkcode deadline}. */
|
|
2
|
-
export interface DeadlineOptions {
|
|
3
|
-
/** Signal used to abort the deadline. */
|
|
4
|
-
signal?: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Create a promise which will be rejected with {@linkcode DOMException} when
|
|
8
|
-
* a given delay is exceeded.
|
|
9
|
-
*
|
|
10
|
-
* Note: Prefer to use {@linkcode AbortSignal.timeout} instead for the APIs
|
|
11
|
-
* that accept {@linkcode AbortSignal}.
|
|
12
|
-
*
|
|
13
|
-
* @throws {DOMException & { name: "TimeoutError" }} If the provided duration
|
|
14
|
-
* runs out before resolving.
|
|
15
|
-
* @throws {DOMException & { name: "AbortError" }} If the optional signal is
|
|
16
|
-
* aborted with the default `reason` before resolving or timing out.
|
|
17
|
-
* @throws {AbortSignal["reason"]} If the optional signal is aborted with a
|
|
18
|
-
* custom `reason` before resolving or timing out.
|
|
19
|
-
* @typeParam T The type of the provided and returned promise.
|
|
20
|
-
* @param p The promise to make rejectable.
|
|
21
|
-
* @param ms Duration in milliseconds for when the promise should time out. If
|
|
22
|
-
* greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire.
|
|
23
|
-
* @param options Additional options.
|
|
24
|
-
* @returns A promise that will reject if the provided duration runs out before resolving.
|
|
25
|
-
*
|
|
26
|
-
* @example Usage
|
|
27
|
-
* ```ts ignore
|
|
28
|
-
* import { deadline } from "@std/async/deadline";
|
|
29
|
-
* import { delay } from "@std/async/delay";
|
|
30
|
-
*
|
|
31
|
-
* const delayedPromise = delay(1_000);
|
|
32
|
-
* // Below throws `DOMException` after 10 ms
|
|
33
|
-
* const result = await deadline(delayedPromise, 10);
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function deadline<T>(p: Promise<T>, ms: number, options?: DeadlineOptions): Promise<T>;
|
|
37
|
-
//# sourceMappingURL=deadline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deadline.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/deadline.ts"],"names":[],"mappings":"AAKA,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EACb,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,CAAC,CAAC,CAKZ"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
import { abortable } from "./abortable.js";
|
|
4
|
-
/**
|
|
5
|
-
* Create a promise which will be rejected with {@linkcode DOMException} when
|
|
6
|
-
* a given delay is exceeded.
|
|
7
|
-
*
|
|
8
|
-
* Note: Prefer to use {@linkcode AbortSignal.timeout} instead for the APIs
|
|
9
|
-
* that accept {@linkcode AbortSignal}.
|
|
10
|
-
*
|
|
11
|
-
* @throws {DOMException & { name: "TimeoutError" }} If the provided duration
|
|
12
|
-
* runs out before resolving.
|
|
13
|
-
* @throws {DOMException & { name: "AbortError" }} If the optional signal is
|
|
14
|
-
* aborted with the default `reason` before resolving or timing out.
|
|
15
|
-
* @throws {AbortSignal["reason"]} If the optional signal is aborted with a
|
|
16
|
-
* custom `reason` before resolving or timing out.
|
|
17
|
-
* @typeParam T The type of the provided and returned promise.
|
|
18
|
-
* @param p The promise to make rejectable.
|
|
19
|
-
* @param ms Duration in milliseconds for when the promise should time out. If
|
|
20
|
-
* greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire.
|
|
21
|
-
* @param options Additional options.
|
|
22
|
-
* @returns A promise that will reject if the provided duration runs out before resolving.
|
|
23
|
-
*
|
|
24
|
-
* @example Usage
|
|
25
|
-
* ```ts ignore
|
|
26
|
-
* import { deadline } from "@std/async/deadline";
|
|
27
|
-
* import { delay } from "@std/async/delay";
|
|
28
|
-
*
|
|
29
|
-
* const delayedPromise = delay(1_000);
|
|
30
|
-
* // Below throws `DOMException` after 10 ms
|
|
31
|
-
* const result = await deadline(delayedPromise, 10);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export async function deadline(p, ms, options = {}) {
|
|
35
|
-
const signals = [];
|
|
36
|
-
if (ms < Number.MAX_SAFE_INTEGER)
|
|
37
|
-
signals.push(AbortSignal.timeout(ms));
|
|
38
|
-
if (options.signal)
|
|
39
|
-
signals.push(options.signal);
|
|
40
|
-
return await abortable(p, AbortSignal.any(signals));
|
|
41
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A debounced function that will be delayed by a given `wait`
|
|
3
|
-
* time in milliseconds. If the method is called again before
|
|
4
|
-
* the timeout expires, the previous call will be aborted.
|
|
5
|
-
*/
|
|
6
|
-
export interface DebouncedFunction<T extends Array<unknown>> {
|
|
7
|
-
(...args: T): void;
|
|
8
|
-
/** Clears the debounce timeout and omits calling the debounced function. */
|
|
9
|
-
clear(): void;
|
|
10
|
-
/** Clears the debounce timeout and calls the debounced function immediately. */
|
|
11
|
-
flush(): void;
|
|
12
|
-
/** Returns a boolean whether a debounce call is pending or not. */
|
|
13
|
-
readonly pending: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Creates a debounced function that delays the given `func`
|
|
17
|
-
* by a given `wait` time in milliseconds. If the method is called
|
|
18
|
-
* again before the timeout expires, the previous call will be
|
|
19
|
-
* aborted.
|
|
20
|
-
*
|
|
21
|
-
* @example Usage
|
|
22
|
-
* ```ts ignore
|
|
23
|
-
* import { debounce } from "@std/async/debounce";
|
|
24
|
-
*
|
|
25
|
-
* const log = debounce(
|
|
26
|
-
* (event: Deno.FsEvent) =>
|
|
27
|
-
* console.log("[%s] %s", event.kind, event.paths[0]),
|
|
28
|
-
* 200,
|
|
29
|
-
* );
|
|
30
|
-
*
|
|
31
|
-
* for await (const event of Deno.watchFs("./")) {
|
|
32
|
-
* log(event);
|
|
33
|
-
* }
|
|
34
|
-
* // wait 200ms ...
|
|
35
|
-
* // output: Function debounced after 200ms with baz
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @typeParam T The arguments of the provided function.
|
|
39
|
-
* @param fn The function to debounce.
|
|
40
|
-
* @param wait The time in milliseconds to delay the function.
|
|
41
|
-
* @returns The debounced function.
|
|
42
|
-
*/
|
|
43
|
-
export declare function debounce<T extends Array<any>>(fn: (this: DebouncedFunction<T>, ...args: T) => void, wait: number): DebouncedFunction<T>;
|
|
44
|
-
//# sourceMappingURL=debounce.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/debounce.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,KAAK,CAAC,OAAO,CAAC;IACzD,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACnB,4EAA4E;IAC5E,KAAK,IAAI,IAAI,CAAC;IACd,gFAAgF;IAChF,KAAK,IAAI,IAAI,CAAC;IACd,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAC3C,EAAE,EAAE,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EACpD,IAAI,EAAE,MAAM,GACX,iBAAiB,CAAC,CAAC,CAAC,CA8BtB"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
/**
|
|
4
|
-
* Creates a debounced function that delays the given `func`
|
|
5
|
-
* by a given `wait` time in milliseconds. If the method is called
|
|
6
|
-
* again before the timeout expires, the previous call will be
|
|
7
|
-
* aborted.
|
|
8
|
-
*
|
|
9
|
-
* @example Usage
|
|
10
|
-
* ```ts ignore
|
|
11
|
-
* import { debounce } from "@std/async/debounce";
|
|
12
|
-
*
|
|
13
|
-
* const log = debounce(
|
|
14
|
-
* (event: Deno.FsEvent) =>
|
|
15
|
-
* console.log("[%s] %s", event.kind, event.paths[0]),
|
|
16
|
-
* 200,
|
|
17
|
-
* );
|
|
18
|
-
*
|
|
19
|
-
* for await (const event of Deno.watchFs("./")) {
|
|
20
|
-
* log(event);
|
|
21
|
-
* }
|
|
22
|
-
* // wait 200ms ...
|
|
23
|
-
* // output: Function debounced after 200ms with baz
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @typeParam T The arguments of the provided function.
|
|
27
|
-
* @param fn The function to debounce.
|
|
28
|
-
* @param wait The time in milliseconds to delay the function.
|
|
29
|
-
* @returns The debounced function.
|
|
30
|
-
*/
|
|
31
|
-
// deno-lint-ignore no-explicit-any
|
|
32
|
-
export function debounce(fn, wait) {
|
|
33
|
-
let timeout = null;
|
|
34
|
-
let flush = null;
|
|
35
|
-
const debounced = ((...args) => {
|
|
36
|
-
debounced.clear();
|
|
37
|
-
flush = () => {
|
|
38
|
-
debounced.clear();
|
|
39
|
-
fn.call(debounced, ...args);
|
|
40
|
-
};
|
|
41
|
-
timeout = Number(setTimeout(flush, wait));
|
|
42
|
-
});
|
|
43
|
-
debounced.clear = () => {
|
|
44
|
-
if (typeof timeout === "number") {
|
|
45
|
-
clearTimeout(timeout);
|
|
46
|
-
timeout = null;
|
|
47
|
-
flush = null;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
debounced.flush = () => {
|
|
51
|
-
flush?.();
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(debounced, "pending", {
|
|
54
|
-
get: () => typeof timeout === "number",
|
|
55
|
-
});
|
|
56
|
-
return debounced;
|
|
57
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provide helpers with asynchronous tasks, like {@linkcode delay},
|
|
3
|
-
* {@linkcode debounce}, {@linkcode retry}, or
|
|
4
|
-
* {@linkcode pooledMap}.
|
|
5
|
-
*
|
|
6
|
-
* ```ts no-assert
|
|
7
|
-
* import { delay } from "@std/async/delay";
|
|
8
|
-
*
|
|
9
|
-
* await delay(100); // waits for 100 milliseconds
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
14
|
-
export * from "./abortable.js";
|
|
15
|
-
export * from "./deadline.js";
|
|
16
|
-
export * from "./debounce.js";
|
|
17
|
-
export * from "./delay.js";
|
|
18
|
-
export * from "./mux_async_iterator.js";
|
|
19
|
-
export * from "./pool.js";
|
|
20
|
-
export * from "./tee.js";
|
|
21
|
-
export * from "./retry.js";
|
|
22
|
-
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/mod.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
/**
|
|
4
|
-
* Provide helpers with asynchronous tasks, like {@linkcode delay},
|
|
5
|
-
* {@linkcode debounce}, {@linkcode retry}, or
|
|
6
|
-
* {@linkcode pooledMap}.
|
|
7
|
-
*
|
|
8
|
-
* ```ts no-assert
|
|
9
|
-
* import { delay } from "@std/async/delay";
|
|
10
|
-
*
|
|
11
|
-
* await delay(100); // waits for 100 milliseconds
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @module
|
|
15
|
-
*/
|
|
16
|
-
export * from "./abortable.js";
|
|
17
|
-
export * from "./deadline.js";
|
|
18
|
-
export * from "./debounce.js";
|
|
19
|
-
export * from "./delay.js";
|
|
20
|
-
export * from "./mux_async_iterator.js";
|
|
21
|
-
export * from "./pool.js";
|
|
22
|
-
export * from "./tee.js";
|
|
23
|
-
export * from "./retry.js";
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multiplexes multiple async iterators into a single stream. It currently
|
|
3
|
-
* makes an assumption that the final result (the value returned and not
|
|
4
|
-
* yielded from the iterator) does not matter; if there is any result, it is
|
|
5
|
-
* discarded.
|
|
6
|
-
*
|
|
7
|
-
* @example Usage
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
10
|
-
* import { assertEquals } from "@std/assert";
|
|
11
|
-
*
|
|
12
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
13
|
-
* yield 1;
|
|
14
|
-
* yield 2;
|
|
15
|
-
* yield 3;
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* async function* gen456(): AsyncIterableIterator<number> {
|
|
19
|
-
* yield 4;
|
|
20
|
-
* yield 5;
|
|
21
|
-
* yield 6;
|
|
22
|
-
* }
|
|
23
|
-
*
|
|
24
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
25
|
-
* mux.add(gen123());
|
|
26
|
-
* mux.add(gen456());
|
|
27
|
-
*
|
|
28
|
-
* const result = await Array.fromAsync(mux);
|
|
29
|
-
*
|
|
30
|
-
* assertEquals(result, [1, 4, 2, 5, 3, 6]);
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @typeParam T The type of the provided async iterables and generated async iterable.
|
|
34
|
-
*/
|
|
35
|
-
export declare class MuxAsyncIterator<T> implements AsyncIterable<T> {
|
|
36
|
-
#private;
|
|
37
|
-
/**
|
|
38
|
-
* Add an async iterable to the stream.
|
|
39
|
-
*
|
|
40
|
-
* @param iterable The async iterable to add.
|
|
41
|
-
*
|
|
42
|
-
* @example Usage
|
|
43
|
-
* ```ts
|
|
44
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
45
|
-
* import { assertEquals } from "@std/assert";
|
|
46
|
-
*
|
|
47
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
48
|
-
* yield 1;
|
|
49
|
-
* yield 2;
|
|
50
|
-
* yield 3;
|
|
51
|
-
* }
|
|
52
|
-
*
|
|
53
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
54
|
-
* mux.add(gen123());
|
|
55
|
-
*
|
|
56
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
57
|
-
*
|
|
58
|
-
* assertEquals(result, [1, 2, 3]);
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
add(iterable: AsyncIterable<T>): void;
|
|
62
|
-
/**
|
|
63
|
-
* Returns an async iterator of the stream.
|
|
64
|
-
* @returns the async iterator for all the added async iterables.
|
|
65
|
-
*
|
|
66
|
-
* @example Usage
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
69
|
-
* import { assertEquals } from "@std/assert";
|
|
70
|
-
*
|
|
71
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
72
|
-
* yield 1;
|
|
73
|
-
* yield 2;
|
|
74
|
-
* yield 3;
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
78
|
-
* mux.add(gen123());
|
|
79
|
-
*
|
|
80
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
81
|
-
*
|
|
82
|
-
* assertEquals(result, [1, 2, 3]);
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
iterate(): AsyncIterableIterator<T>;
|
|
86
|
-
/**
|
|
87
|
-
* Implements an async iterator for the stream.
|
|
88
|
-
* @returns the async iterator for all the added async iterables.
|
|
89
|
-
*
|
|
90
|
-
* @example Usage
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
93
|
-
* import { assertEquals } from "@std/assert";
|
|
94
|
-
*
|
|
95
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
96
|
-
* yield 1;
|
|
97
|
-
* yield 2;
|
|
98
|
-
* yield 3;
|
|
99
|
-
* }
|
|
100
|
-
*
|
|
101
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
102
|
-
* mux.add(gen123());
|
|
103
|
-
*
|
|
104
|
-
* const result = await Array.fromAsync(mux);
|
|
105
|
-
*
|
|
106
|
-
* assertEquals(result, [1, 2, 3]);
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=mux_async_iterator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mux_async_iterator.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,gBAAgB,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;;IAO1D;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;IAqB9B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACI,OAAO,IAAI,qBAAqB,CAAC,CAAC,CAAC;IAsB1C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAG3C"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
/**
|
|
4
|
-
* Multiplexes multiple async iterators into a single stream. It currently
|
|
5
|
-
* makes an assumption that the final result (the value returned and not
|
|
6
|
-
* yielded from the iterator) does not matter; if there is any result, it is
|
|
7
|
-
* discarded.
|
|
8
|
-
*
|
|
9
|
-
* @example Usage
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
12
|
-
* import { assertEquals } from "@std/assert";
|
|
13
|
-
*
|
|
14
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
15
|
-
* yield 1;
|
|
16
|
-
* yield 2;
|
|
17
|
-
* yield 3;
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* async function* gen456(): AsyncIterableIterator<number> {
|
|
21
|
-
* yield 4;
|
|
22
|
-
* yield 5;
|
|
23
|
-
* yield 6;
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
27
|
-
* mux.add(gen123());
|
|
28
|
-
* mux.add(gen456());
|
|
29
|
-
*
|
|
30
|
-
* const result = await Array.fromAsync(mux);
|
|
31
|
-
*
|
|
32
|
-
* assertEquals(result, [1, 4, 2, 5, 3, 6]);
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @typeParam T The type of the provided async iterables and generated async iterable.
|
|
36
|
-
*/
|
|
37
|
-
export class MuxAsyncIterator {
|
|
38
|
-
#iteratorCount = 0;
|
|
39
|
-
#yields = [];
|
|
40
|
-
// deno-lint-ignore no-explicit-any
|
|
41
|
-
#throws = [];
|
|
42
|
-
#signal = Promise.withResolvers();
|
|
43
|
-
/**
|
|
44
|
-
* Add an async iterable to the stream.
|
|
45
|
-
*
|
|
46
|
-
* @param iterable The async iterable to add.
|
|
47
|
-
*
|
|
48
|
-
* @example Usage
|
|
49
|
-
* ```ts
|
|
50
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
51
|
-
* import { assertEquals } from "@std/assert";
|
|
52
|
-
*
|
|
53
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
54
|
-
* yield 1;
|
|
55
|
-
* yield 2;
|
|
56
|
-
* yield 3;
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
60
|
-
* mux.add(gen123());
|
|
61
|
-
*
|
|
62
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
63
|
-
*
|
|
64
|
-
* assertEquals(result, [1, 2, 3]);
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
add(iterable) {
|
|
68
|
-
++this.#iteratorCount;
|
|
69
|
-
this.#callIteratorNext(iterable[Symbol.asyncIterator]());
|
|
70
|
-
}
|
|
71
|
-
async #callIteratorNext(iterator) {
|
|
72
|
-
try {
|
|
73
|
-
const { value, done } = await iterator.next();
|
|
74
|
-
if (done) {
|
|
75
|
-
--this.#iteratorCount;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this.#yields.push({ iterator, value });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
this.#throws.push(e);
|
|
83
|
-
}
|
|
84
|
-
this.#signal.resolve();
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Returns an async iterator of the stream.
|
|
88
|
-
* @returns the async iterator for all the added async iterables.
|
|
89
|
-
*
|
|
90
|
-
* @example Usage
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
93
|
-
* import { assertEquals } from "@std/assert";
|
|
94
|
-
*
|
|
95
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
96
|
-
* yield 1;
|
|
97
|
-
* yield 2;
|
|
98
|
-
* yield 3;
|
|
99
|
-
* }
|
|
100
|
-
*
|
|
101
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
102
|
-
* mux.add(gen123());
|
|
103
|
-
*
|
|
104
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
105
|
-
*
|
|
106
|
-
* assertEquals(result, [1, 2, 3]);
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
async *iterate() {
|
|
110
|
-
while (this.#iteratorCount > 0) {
|
|
111
|
-
// Sleep until any of the wrapped iterators yields.
|
|
112
|
-
await this.#signal.promise;
|
|
113
|
-
// Note that while we're looping over `yields`, new items may be added.
|
|
114
|
-
for (const { iterator, value } of this.#yields) {
|
|
115
|
-
yield value;
|
|
116
|
-
this.#callIteratorNext(iterator);
|
|
117
|
-
}
|
|
118
|
-
if (this.#throws.length) {
|
|
119
|
-
for (const e of this.#throws) {
|
|
120
|
-
throw e;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// Clear the `yields` list and reset the `signal` promise.
|
|
124
|
-
this.#yields.length = 0;
|
|
125
|
-
this.#signal = Promise.withResolvers();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Implements an async iterator for the stream.
|
|
130
|
-
* @returns the async iterator for all the added async iterables.
|
|
131
|
-
*
|
|
132
|
-
* @example Usage
|
|
133
|
-
* ```ts
|
|
134
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
135
|
-
* import { assertEquals } from "@std/assert";
|
|
136
|
-
*
|
|
137
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
138
|
-
* yield 1;
|
|
139
|
-
* yield 2;
|
|
140
|
-
* yield 3;
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
144
|
-
* mux.add(gen123());
|
|
145
|
-
*
|
|
146
|
-
* const result = await Array.fromAsync(mux);
|
|
147
|
-
*
|
|
148
|
-
* assertEquals(result, [1, 2, 3]);
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
[Symbol.asyncIterator]() {
|
|
152
|
-
return this.iterate();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown in {@linkcode retry} once the maximum number of failed attempts
|
|
3
|
-
* has been reached.
|
|
4
|
-
*
|
|
5
|
-
* @example Usage
|
|
6
|
-
* ```ts no-assert ignore
|
|
7
|
-
* import { RetryError } from "@std/async/retry";
|
|
8
|
-
*
|
|
9
|
-
* throw new RetryError({ foo: "bar" }, 3);
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export declare class RetryError extends Error {
|
|
13
|
-
/**
|
|
14
|
-
* Constructs a new {@linkcode RetryError} instance.
|
|
15
|
-
*
|
|
16
|
-
* @param cause the cause for this error.
|
|
17
|
-
* @param attempts the number of retry attempts made.
|
|
18
|
-
*/
|
|
19
|
-
constructor(cause: unknown, attempts: number);
|
|
20
|
-
}
|
|
21
|
-
/** Options for {@linkcode retry}. */
|
|
22
|
-
export interface RetryOptions {
|
|
23
|
-
/**
|
|
24
|
-
* How much to backoff after each retry.
|
|
25
|
-
*
|
|
26
|
-
* @default {2}
|
|
27
|
-
*/
|
|
28
|
-
multiplier?: number;
|
|
29
|
-
/**
|
|
30
|
-
* The maximum milliseconds between attempts.
|
|
31
|
-
*
|
|
32
|
-
* @default {60000}
|
|
33
|
-
*/
|
|
34
|
-
maxTimeout?: number;
|
|
35
|
-
/**
|
|
36
|
-
* The maximum amount of attempts until failure.
|
|
37
|
-
*
|
|
38
|
-
* @default {5}
|
|
39
|
-
*/
|
|
40
|
-
maxAttempts?: number;
|
|
41
|
-
/**
|
|
42
|
-
* The initial and minimum amount of milliseconds between attempts.
|
|
43
|
-
*
|
|
44
|
-
* @default {1000}
|
|
45
|
-
*/
|
|
46
|
-
minTimeout?: number;
|
|
47
|
-
/**
|
|
48
|
-
* Amount of jitter to introduce to the time between attempts. This is `1`
|
|
49
|
-
* for full jitter by default.
|
|
50
|
-
*
|
|
51
|
-
* @default {1}
|
|
52
|
-
*/
|
|
53
|
-
jitter?: number;
|
|
54
|
-
/**
|
|
55
|
-
* Callback to determine if an error or other thrown value is retriable.
|
|
56
|
-
*
|
|
57
|
-
* @default {() => true}
|
|
58
|
-
*
|
|
59
|
-
* @param err The thrown error or other value.
|
|
60
|
-
* @returns `true` if the error is retriable, `false` otherwise.
|
|
61
|
-
*/
|
|
62
|
-
isRetriable?: (err: unknown) => boolean;
|
|
63
|
-
/**
|
|
64
|
-
* An AbortSignal to cancel the retry operation.
|
|
65
|
-
*
|
|
66
|
-
* If the signal is aborted, the retry will stop and reject with the signal's
|
|
67
|
-
* reason. The signal is checked before each attempt and during the delay
|
|
68
|
-
* between attempts.
|
|
69
|
-
*
|
|
70
|
-
* @default {undefined}
|
|
71
|
-
*/
|
|
72
|
-
signal?: AbortSignal;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Calls the given (possibly asynchronous) function up to `maxAttempts` times.
|
|
76
|
-
* Retries as long as the given function throws. If the attempts are exhausted,
|
|
77
|
-
* throws a {@linkcode RetryError} with `cause` set to the inner exception.
|
|
78
|
-
*
|
|
79
|
-
* The backoff is calculated by multiplying `minTimeout` with `multiplier` to the power of the current attempt counter (starting at 0 up to `maxAttempts - 1`). It is capped at `maxTimeout` however.
|
|
80
|
-
* How long the actual delay is, depends on `jitter`.
|
|
81
|
-
*
|
|
82
|
-
* When `jitter` is the default value of `1`, waits between two attempts for a
|
|
83
|
-
* randomized amount between 0 and the backoff time. With the default options
|
|
84
|
-
* the maximal delay will be `15s = 1s + 2s + 4s + 8s`. If all five attempts
|
|
85
|
-
* are exhausted the mean delay will be `9.5s = ½(4s + 15s)`.
|
|
86
|
-
*
|
|
87
|
-
* When `jitter` is `0`, waits the full backoff time.
|
|
88
|
-
*
|
|
89
|
-
* @example Example configuration 1
|
|
90
|
-
* ```ts no-assert
|
|
91
|
-
* import { retry } from "@std/async/retry";
|
|
92
|
-
* const req = async () => {
|
|
93
|
-
* // some function that throws sometimes
|
|
94
|
-
* };
|
|
95
|
-
*
|
|
96
|
-
* // Below resolves to the first non-error result of `req`
|
|
97
|
-
* const retryPromise = await retry(req, {
|
|
98
|
-
* multiplier: 2,
|
|
99
|
-
* maxTimeout: 60000,
|
|
100
|
-
* maxAttempts: 5,
|
|
101
|
-
* minTimeout: 100,
|
|
102
|
-
* jitter: 1,
|
|
103
|
-
* });
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
* @example Example configuration 2
|
|
107
|
-
* ```ts no-assert
|
|
108
|
-
* import { retry } from "@std/async/retry";
|
|
109
|
-
* const req = async () => {
|
|
110
|
-
* // some function that throws sometimes
|
|
111
|
-
* };
|
|
112
|
-
*
|
|
113
|
-
* // Make sure we wait at least 1 minute, but at most 2 minutes
|
|
114
|
-
* const retryPromise = await retry(req, {
|
|
115
|
-
* multiplier: 2.34,
|
|
116
|
-
* maxTimeout: 80000,
|
|
117
|
-
* maxAttempts: 7,
|
|
118
|
-
* minTimeout: 1000,
|
|
119
|
-
* jitter: 0.5,
|
|
120
|
-
* });
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
* @example Only retry on specific error types
|
|
124
|
-
* ```ts no-assert
|
|
125
|
-
* import { retry } from "@std/async/retry";
|
|
126
|
-
*
|
|
127
|
-
* class HttpError extends Error {
|
|
128
|
-
* status: number;
|
|
129
|
-
* constructor(status: number) {
|
|
130
|
-
* super(`HTTP ${status}`);
|
|
131
|
-
* this.status = status;
|
|
132
|
-
* }
|
|
133
|
-
* }
|
|
134
|
-
*
|
|
135
|
-
* const req = async () => {
|
|
136
|
-
* // some function that throws HttpError
|
|
137
|
-
* };
|
|
138
|
-
*
|
|
139
|
-
* // Only retry on 429 (rate limit) or 5xx (server) errors
|
|
140
|
-
* const retryPromise = await retry(req, {
|
|
141
|
-
* isRetriable: (err) =>
|
|
142
|
-
* err instanceof HttpError && (err.status === 429 || err.status >= 500),
|
|
143
|
-
* });
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* @typeParam T The return type of the function to retry and returned promise.
|
|
147
|
-
* @param fn The function to retry.
|
|
148
|
-
* @param options Additional options.
|
|
149
|
-
* @returns The promise that resolves with the value returned by the function to retry.
|
|
150
|
-
* @throws {RetryError} If the function fails after `maxAttempts` attempts.
|
|
151
|
-
* @throws If the `signal` is aborted, throws the signal's reason.
|
|
152
|
-
* @throws If `isRetriable` returns `false` for an error, throws that error immediately.
|
|
153
|
-
*/
|
|
154
|
-
export declare function retry<T>(fn: (() => Promise<T>) | (() => T), options?: RetryOptions): Promise<T>;
|
|
155
|
-
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/retry.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACnC;;;;;OAKG;gBACS,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;CAK7C;AAED,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;IACxC;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,EAAE,EAAE,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,CAAC,CAoEZ"}
|