@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,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
-
if (k2 === undefined) k2 = k;
|
|
6
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
/**
|
|
20
|
-
* Provide helpers with asynchronous tasks, like {@linkcode delay},
|
|
21
|
-
* {@linkcode debounce}, {@linkcode retry}, or
|
|
22
|
-
* {@linkcode pooledMap}.
|
|
23
|
-
*
|
|
24
|
-
* ```ts no-assert
|
|
25
|
-
* import { delay } from "@std/async/delay";
|
|
26
|
-
*
|
|
27
|
-
* await delay(100); // waits for 100 milliseconds
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @module
|
|
31
|
-
*/
|
|
32
|
-
__exportStar(require("./abortable.js"), exports);
|
|
33
|
-
__exportStar(require("./deadline.js"), exports);
|
|
34
|
-
__exportStar(require("./debounce.js"), exports);
|
|
35
|
-
__exportStar(require("./delay.js"), exports);
|
|
36
|
-
__exportStar(require("./mux_async_iterator.js"), exports);
|
|
37
|
-
__exportStar(require("./pool.js"), exports);
|
|
38
|
-
__exportStar(require("./tee.js"), exports);
|
|
39
|
-
__exportStar(require("./retry.js"), exports);
|
|
@@ -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,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
3
|
-
// This module is browser compatible.
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.MuxAsyncIterator = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Multiplexes multiple async iterators into a single stream. It currently
|
|
8
|
-
* makes an assumption that the final result (the value returned and not
|
|
9
|
-
* yielded from the iterator) does not matter; if there is any result, it is
|
|
10
|
-
* discarded.
|
|
11
|
-
*
|
|
12
|
-
* @example Usage
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
15
|
-
* import { assertEquals } from "@std/assert";
|
|
16
|
-
*
|
|
17
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
18
|
-
* yield 1;
|
|
19
|
-
* yield 2;
|
|
20
|
-
* yield 3;
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* async function* gen456(): AsyncIterableIterator<number> {
|
|
24
|
-
* yield 4;
|
|
25
|
-
* yield 5;
|
|
26
|
-
* yield 6;
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
30
|
-
* mux.add(gen123());
|
|
31
|
-
* mux.add(gen456());
|
|
32
|
-
*
|
|
33
|
-
* const result = await Array.fromAsync(mux);
|
|
34
|
-
*
|
|
35
|
-
* assertEquals(result, [1, 4, 2, 5, 3, 6]);
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @typeParam T The type of the provided async iterables and generated async iterable.
|
|
39
|
-
*/
|
|
40
|
-
class MuxAsyncIterator {
|
|
41
|
-
#iteratorCount = 0;
|
|
42
|
-
#yields = [];
|
|
43
|
-
// deno-lint-ignore no-explicit-any
|
|
44
|
-
#throws = [];
|
|
45
|
-
#signal = Promise.withResolvers();
|
|
46
|
-
/**
|
|
47
|
-
* Add an async iterable to the stream.
|
|
48
|
-
*
|
|
49
|
-
* @param iterable The async iterable to add.
|
|
50
|
-
*
|
|
51
|
-
* @example Usage
|
|
52
|
-
* ```ts
|
|
53
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
54
|
-
* import { assertEquals } from "@std/assert";
|
|
55
|
-
*
|
|
56
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
57
|
-
* yield 1;
|
|
58
|
-
* yield 2;
|
|
59
|
-
* yield 3;
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
63
|
-
* mux.add(gen123());
|
|
64
|
-
*
|
|
65
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
66
|
-
*
|
|
67
|
-
* assertEquals(result, [1, 2, 3]);
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
add(iterable) {
|
|
71
|
-
++this.#iteratorCount;
|
|
72
|
-
this.#callIteratorNext(iterable[Symbol.asyncIterator]());
|
|
73
|
-
}
|
|
74
|
-
async #callIteratorNext(iterator) {
|
|
75
|
-
try {
|
|
76
|
-
const { value, done } = await iterator.next();
|
|
77
|
-
if (done) {
|
|
78
|
-
--this.#iteratorCount;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this.#yields.push({ iterator, value });
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
this.#throws.push(e);
|
|
86
|
-
}
|
|
87
|
-
this.#signal.resolve();
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns an async iterator of the stream.
|
|
91
|
-
* @returns the async iterator for all the added async iterables.
|
|
92
|
-
*
|
|
93
|
-
* @example Usage
|
|
94
|
-
* ```ts
|
|
95
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
96
|
-
* import { assertEquals } from "@std/assert";
|
|
97
|
-
*
|
|
98
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
99
|
-
* yield 1;
|
|
100
|
-
* yield 2;
|
|
101
|
-
* yield 3;
|
|
102
|
-
* }
|
|
103
|
-
*
|
|
104
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
105
|
-
* mux.add(gen123());
|
|
106
|
-
*
|
|
107
|
-
* const result = await Array.fromAsync(mux.iterate());
|
|
108
|
-
*
|
|
109
|
-
* assertEquals(result, [1, 2, 3]);
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
async *iterate() {
|
|
113
|
-
while (this.#iteratorCount > 0) {
|
|
114
|
-
// Sleep until any of the wrapped iterators yields.
|
|
115
|
-
await this.#signal.promise;
|
|
116
|
-
// Note that while we're looping over `yields`, new items may be added.
|
|
117
|
-
for (const { iterator, value } of this.#yields) {
|
|
118
|
-
yield value;
|
|
119
|
-
this.#callIteratorNext(iterator);
|
|
120
|
-
}
|
|
121
|
-
if (this.#throws.length) {
|
|
122
|
-
for (const e of this.#throws) {
|
|
123
|
-
throw e;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// Clear the `yields` list and reset the `signal` promise.
|
|
127
|
-
this.#yields.length = 0;
|
|
128
|
-
this.#signal = Promise.withResolvers();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Implements an async iterator for the stream.
|
|
133
|
-
* @returns the async iterator for all the added async iterables.
|
|
134
|
-
*
|
|
135
|
-
* @example Usage
|
|
136
|
-
* ```ts
|
|
137
|
-
* import { MuxAsyncIterator } from "@std/async/mux-async-iterator";
|
|
138
|
-
* import { assertEquals } from "@std/assert";
|
|
139
|
-
*
|
|
140
|
-
* async function* gen123(): AsyncIterableIterator<number> {
|
|
141
|
-
* yield 1;
|
|
142
|
-
* yield 2;
|
|
143
|
-
* yield 3;
|
|
144
|
-
* }
|
|
145
|
-
*
|
|
146
|
-
* const mux = new MuxAsyncIterator<number>();
|
|
147
|
-
* mux.add(gen123());
|
|
148
|
-
*
|
|
149
|
-
* const result = await Array.fromAsync(mux);
|
|
150
|
-
*
|
|
151
|
-
* assertEquals(result, [1, 2, 3]);
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
[Symbol.asyncIterator]() {
|
|
155
|
-
return this.iterate();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.MuxAsyncIterator = MuxAsyncIterator;
|
|
@@ -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"}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RetryError = void 0;
|
|
4
|
-
exports.retry = retry;
|
|
5
|
-
// Copyright 2018-2026 the Deno authors. MIT license.
|
|
6
|
-
// This module is browser compatible.
|
|
7
|
-
const delay_js_1 = require("./delay.js");
|
|
8
|
-
const _util_js_1 = require("./_util.js");
|
|
9
|
-
/**
|
|
10
|
-
* Error thrown in {@linkcode retry} once the maximum number of failed attempts
|
|
11
|
-
* has been reached.
|
|
12
|
-
*
|
|
13
|
-
* @example Usage
|
|
14
|
-
* ```ts no-assert ignore
|
|
15
|
-
* import { RetryError } from "@std/async/retry";
|
|
16
|
-
*
|
|
17
|
-
* throw new RetryError({ foo: "bar" }, 3);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
class RetryError extends Error {
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new {@linkcode RetryError} instance.
|
|
23
|
-
*
|
|
24
|
-
* @param cause the cause for this error.
|
|
25
|
-
* @param attempts the number of retry attempts made.
|
|
26
|
-
*/
|
|
27
|
-
constructor(cause, attempts) {
|
|
28
|
-
super(`Retrying exceeded the maxAttempts (${attempts}).`);
|
|
29
|
-
this.name = "RetryError";
|
|
30
|
-
this.cause = cause;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.RetryError = RetryError;
|
|
34
|
-
/**
|
|
35
|
-
* Calls the given (possibly asynchronous) function up to `maxAttempts` times.
|
|
36
|
-
* Retries as long as the given function throws. If the attempts are exhausted,
|
|
37
|
-
* throws a {@linkcode RetryError} with `cause` set to the inner exception.
|
|
38
|
-
*
|
|
39
|
-
* 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.
|
|
40
|
-
* How long the actual delay is, depends on `jitter`.
|
|
41
|
-
*
|
|
42
|
-
* When `jitter` is the default value of `1`, waits between two attempts for a
|
|
43
|
-
* randomized amount between 0 and the backoff time. With the default options
|
|
44
|
-
* the maximal delay will be `15s = 1s + 2s + 4s + 8s`. If all five attempts
|
|
45
|
-
* are exhausted the mean delay will be `9.5s = ½(4s + 15s)`.
|
|
46
|
-
*
|
|
47
|
-
* When `jitter` is `0`, waits the full backoff time.
|
|
48
|
-
*
|
|
49
|
-
* @example Example configuration 1
|
|
50
|
-
* ```ts no-assert
|
|
51
|
-
* import { retry } from "@std/async/retry";
|
|
52
|
-
* const req = async () => {
|
|
53
|
-
* // some function that throws sometimes
|
|
54
|
-
* };
|
|
55
|
-
*
|
|
56
|
-
* // Below resolves to the first non-error result of `req`
|
|
57
|
-
* const retryPromise = await retry(req, {
|
|
58
|
-
* multiplier: 2,
|
|
59
|
-
* maxTimeout: 60000,
|
|
60
|
-
* maxAttempts: 5,
|
|
61
|
-
* minTimeout: 100,
|
|
62
|
-
* jitter: 1,
|
|
63
|
-
* });
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @example Example configuration 2
|
|
67
|
-
* ```ts no-assert
|
|
68
|
-
* import { retry } from "@std/async/retry";
|
|
69
|
-
* const req = async () => {
|
|
70
|
-
* // some function that throws sometimes
|
|
71
|
-
* };
|
|
72
|
-
*
|
|
73
|
-
* // Make sure we wait at least 1 minute, but at most 2 minutes
|
|
74
|
-
* const retryPromise = await retry(req, {
|
|
75
|
-
* multiplier: 2.34,
|
|
76
|
-
* maxTimeout: 80000,
|
|
77
|
-
* maxAttempts: 7,
|
|
78
|
-
* minTimeout: 1000,
|
|
79
|
-
* jitter: 0.5,
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @example Only retry on specific error types
|
|
84
|
-
* ```ts no-assert
|
|
85
|
-
* import { retry } from "@std/async/retry";
|
|
86
|
-
*
|
|
87
|
-
* class HttpError extends Error {
|
|
88
|
-
* status: number;
|
|
89
|
-
* constructor(status: number) {
|
|
90
|
-
* super(`HTTP ${status}`);
|
|
91
|
-
* this.status = status;
|
|
92
|
-
* }
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* const req = async () => {
|
|
96
|
-
* // some function that throws HttpError
|
|
97
|
-
* };
|
|
98
|
-
*
|
|
99
|
-
* // Only retry on 429 (rate limit) or 5xx (server) errors
|
|
100
|
-
* const retryPromise = await retry(req, {
|
|
101
|
-
* isRetriable: (err) =>
|
|
102
|
-
* err instanceof HttpError && (err.status === 429 || err.status >= 500),
|
|
103
|
-
* });
|
|
104
|
-
* ```
|
|
105
|
-
*
|
|
106
|
-
* @typeParam T The return type of the function to retry and returned promise.
|
|
107
|
-
* @param fn The function to retry.
|
|
108
|
-
* @param options Additional options.
|
|
109
|
-
* @returns The promise that resolves with the value returned by the function to retry.
|
|
110
|
-
* @throws {RetryError} If the function fails after `maxAttempts` attempts.
|
|
111
|
-
* @throws If the `signal` is aborted, throws the signal's reason.
|
|
112
|
-
* @throws If `isRetriable` returns `false` for an error, throws that error immediately.
|
|
113
|
-
*/
|
|
114
|
-
async function retry(fn, options) {
|
|
115
|
-
const { multiplier = 2, maxTimeout = 60000, maxAttempts = 5, minTimeout = 1000, jitter = 1, isRetriable = () => true, signal, } = options ?? {};
|
|
116
|
-
if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {
|
|
117
|
-
throw new RangeError(`Cannot retry as 'maxAttempts' must be a positive integer: current value is ${maxAttempts}`);
|
|
118
|
-
}
|
|
119
|
-
if (!Number.isFinite(multiplier) || multiplier < 1) {
|
|
120
|
-
throw new RangeError(`Cannot retry as 'multiplier' must be a finite number >= 1: current value is ${multiplier}`);
|
|
121
|
-
}
|
|
122
|
-
if (Number.isNaN(maxTimeout) || maxTimeout <= 0) {
|
|
123
|
-
throw new RangeError(`Cannot retry as 'maxTimeout' must be a positive number: current value is ${maxTimeout}`);
|
|
124
|
-
}
|
|
125
|
-
if (Number.isNaN(minTimeout) || minTimeout < 0) {
|
|
126
|
-
throw new RangeError(`Cannot retry as 'minTimeout' must be >= 0: current value is ${minTimeout}`);
|
|
127
|
-
}
|
|
128
|
-
if (minTimeout > maxTimeout) {
|
|
129
|
-
throw new RangeError(`Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=${minTimeout}', 'maxTimeout=${maxTimeout}'`);
|
|
130
|
-
}
|
|
131
|
-
if (Number.isNaN(jitter) || jitter < 0 || jitter > 1) {
|
|
132
|
-
throw new RangeError(`Cannot retry as 'jitter' must be between 0 and 1: current value is ${jitter}`);
|
|
133
|
-
}
|
|
134
|
-
let attempt = 0;
|
|
135
|
-
while (true) {
|
|
136
|
-
signal?.throwIfAborted();
|
|
137
|
-
try {
|
|
138
|
-
return await fn();
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
if (!isRetriable(error)) {
|
|
142
|
-
throw error;
|
|
143
|
-
}
|
|
144
|
-
if (attempt + 1 >= maxAttempts) {
|
|
145
|
-
throw new RetryError(error, maxAttempts);
|
|
146
|
-
}
|
|
147
|
-
const timeout = (0, _util_js_1.exponentialBackoffWithJitter)(maxTimeout, minTimeout, attempt, multiplier, jitter);
|
|
148
|
-
await (0, delay_js_1.delay)(timeout, signal ? { signal } : undefined);
|
|
149
|
-
}
|
|
150
|
-
attempt++;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility for representing n-tuple. Used in {@linkcode tee}.
|
|
3
|
-
*
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export type Tuple<T, N extends number> = N extends N ? number extends N ? T[] : TupleOf<T, N, []> : never;
|
|
7
|
-
/**
|
|
8
|
-
* Utility for representing n-tuple of. Used in {@linkcode Tuple}.
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export type TupleOf<T, N extends number, R extends unknown[]> = R["length"] extends N ? R : TupleOf<T, N, [T, ...R]>;
|
|
13
|
-
/**
|
|
14
|
-
* Branches the given async iterable into the `n` branches.
|
|
15
|
-
*
|
|
16
|
-
* @example Usage
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { tee } from "@std/async/tee";
|
|
19
|
-
* import { assertEquals } from "@std/assert";
|
|
20
|
-
*
|
|
21
|
-
* const gen = async function* gen() {
|
|
22
|
-
* yield 1;
|
|
23
|
-
* yield 2;
|
|
24
|
-
* yield 3;
|
|
25
|
-
* };
|
|
26
|
-
*
|
|
27
|
-
* const [branch1, branch2] = tee(gen());
|
|
28
|
-
*
|
|
29
|
-
* const result1 = await Array.fromAsync(branch1);
|
|
30
|
-
* assertEquals(result1, [1, 2, 3]);
|
|
31
|
-
*
|
|
32
|
-
* const result2 = await Array.fromAsync(branch2);
|
|
33
|
-
* assertEquals(result2, [1, 2, 3]);
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @typeParam T The type of the provided async iterable and the returned async iterables.
|
|
37
|
-
* @typeParam N The amount of branches to tee into.
|
|
38
|
-
* @param iterable The iterable to tee.
|
|
39
|
-
* @param n The amount of branches to tee into.
|
|
40
|
-
* @returns The tuple where each element is an async iterable.
|
|
41
|
-
*/
|
|
42
|
-
export declare function tee<T, N extends number = 2>(iterable: AsyncIterable<T>, n?: N): Tuple<AsyncIterable<T>, N>;
|
|
43
|
-
//# sourceMappingURL=tee.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tee.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/tee.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,GAChD,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAC1C,KAAK,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,IAC1D,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AAuC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,CAAC,EACzC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,CAAC,GAAE,CAAU,GACZ,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAuB5B"}
|