@mtkruto/browser 0.127.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.
Files changed (157) hide show
  1. package/esm/0_deps.d.ts +4 -3
  2. package/esm/0_deps.d.ts.map +1 -1
  3. package/esm/0_deps.js +4 -3
  4. package/esm/3_types.d.ts +7 -0
  5. package/esm/3_types.d.ts.map +1 -1
  6. package/esm/3_types.js +7 -0
  7. package/esm/client/0_params.d.ts +12 -0
  8. package/esm/client/0_params.d.ts.map +1 -1
  9. package/esm/client/1_client_generic.d.ts +96 -19
  10. package/esm/client/1_client_generic.d.ts.map +1 -1
  11. package/esm/client/2_account_manager.d.ts +8 -1
  12. package/esm/client/2_account_manager.d.ts.map +1 -1
  13. package/esm/client/2_account_manager.js +38 -1
  14. package/esm/client/3_message_manager.d.ts +5 -1
  15. package/esm/client/3_message_manager.d.ts.map +1 -1
  16. package/esm/client/3_message_manager.js +21 -1
  17. package/esm/client/4_chat_manager.d.ts +4 -3
  18. package/esm/client/4_chat_manager.d.ts.map +1 -1
  19. package/esm/client/4_chat_manager.js +11 -3
  20. package/esm/client/4_context.d.ts +2 -2
  21. package/esm/client/4_context.d.ts.map +1 -1
  22. package/esm/client/6_client.d.ts +95 -18
  23. package/esm/client/6_client.d.ts.map +1 -1
  24. package/esm/client/6_client.js +121 -20
  25. package/esm/client/6_client_dispatcher.d.ts +96 -19
  26. package/esm/client/6_client_dispatcher.d.ts.map +1 -1
  27. package/esm/client/6_client_dispatcher.js +122 -21
  28. package/esm/types/0_calling_code.d.ts +27 -0
  29. package/esm/types/0_calling_code.d.ts.map +1 -0
  30. package/esm/types/0_calling_code.js +26 -0
  31. package/esm/types/0_timezone.d.ts +31 -0
  32. package/esm/types/0_timezone.d.ts.map +1 -0
  33. package/esm/types/0_timezone.js +26 -0
  34. package/esm/types/1_available_reactions.d.ts +54 -0
  35. package/esm/types/1_available_reactions.d.ts.map +1 -0
  36. package/esm/types/1_available_reactions.js +30 -0
  37. package/esm/types/1_chat_p.d.ts +1 -1
  38. package/esm/types/1_chat_p.d.ts.map +1 -1
  39. package/esm/types/1_chat_p.js +1 -1
  40. package/esm/types/1_country.d.ts +30 -0
  41. package/esm/types/1_country.d.ts.map +1 -0
  42. package/esm/types/1_country.js +30 -0
  43. package/esm/types/2_user.d.ts +1 -1
  44. package/esm/types/2_user.d.ts.map +1 -1
  45. package/esm/types/2_user.js +2 -2
  46. package/esm/types/3_app_support.d.ts +27 -0
  47. package/esm/types/3_app_support.d.ts.map +1 -0
  48. package/esm/types/3_app_support.js +24 -0
  49. package/esm/types/3_blocked_user.d.ts +31 -0
  50. package/esm/types/3_blocked_user.d.ts.map +1 -0
  51. package/esm/types/3_blocked_user.js +33 -0
  52. package/esm/types/4_blocked_user_list.d.ts +31 -0
  53. package/esm/types/4_blocked_user_list.d.ts.map +1 -0
  54. package/esm/types/4_blocked_user_list.js +25 -0
  55. package/package.json +1 -1
  56. package/script/0_deps.d.ts +4 -3
  57. package/script/0_deps.d.ts.map +1 -1
  58. package/script/0_deps.js +13 -12
  59. package/script/3_types.d.ts +7 -0
  60. package/script/3_types.d.ts.map +1 -1
  61. package/script/3_types.js +7 -0
  62. package/script/client/0_params.d.ts +12 -0
  63. package/script/client/0_params.d.ts.map +1 -1
  64. package/script/client/1_client_generic.d.ts +96 -19
  65. package/script/client/1_client_generic.d.ts.map +1 -1
  66. package/script/client/2_account_manager.d.ts +8 -1
  67. package/script/client/2_account_manager.d.ts.map +1 -1
  68. package/script/client/2_account_manager.js +37 -0
  69. package/script/client/3_message_manager.d.ts +5 -1
  70. package/script/client/3_message_manager.d.ts.map +1 -1
  71. package/script/client/3_message_manager.js +20 -0
  72. package/script/client/4_chat_manager.d.ts +4 -3
  73. package/script/client/4_chat_manager.d.ts.map +1 -1
  74. package/script/client/4_chat_manager.js +9 -1
  75. package/script/client/4_context.d.ts +2 -2
  76. package/script/client/4_context.d.ts.map +1 -1
  77. package/script/client/6_client.d.ts +95 -18
  78. package/script/client/6_client.d.ts.map +1 -1
  79. package/script/client/6_client.js +121 -20
  80. package/script/client/6_client_dispatcher.d.ts +96 -19
  81. package/script/client/6_client_dispatcher.d.ts.map +1 -1
  82. package/script/client/6_client_dispatcher.js +122 -21
  83. package/script/types/0_calling_code.d.ts +27 -0
  84. package/script/types/0_calling_code.d.ts.map +1 -0
  85. package/script/types/0_calling_code.js +29 -0
  86. package/script/types/0_timezone.d.ts +31 -0
  87. package/script/types/0_timezone.d.ts.map +1 -0
  88. package/script/types/0_timezone.js +29 -0
  89. package/script/types/1_available_reactions.d.ts +54 -0
  90. package/script/types/1_available_reactions.d.ts.map +1 -0
  91. package/script/types/1_available_reactions.js +33 -0
  92. package/script/types/1_chat_p.d.ts +1 -1
  93. package/script/types/1_chat_p.d.ts.map +1 -1
  94. package/script/types/1_chat_p.js +1 -1
  95. package/script/types/1_country.d.ts +30 -0
  96. package/script/types/1_country.d.ts.map +1 -0
  97. package/script/types/1_country.js +33 -0
  98. package/script/types/2_user.d.ts +1 -1
  99. package/script/types/2_user.d.ts.map +1 -1
  100. package/script/types/2_user.js +2 -2
  101. package/script/types/3_app_support.d.ts +27 -0
  102. package/script/types/3_app_support.d.ts.map +1 -0
  103. package/script/types/3_app_support.js +27 -0
  104. package/script/types/3_blocked_user.d.ts +31 -0
  105. package/script/types/3_blocked_user.d.ts.map +1 -0
  106. package/script/types/3_blocked_user.js +36 -0
  107. package/script/types/4_blocked_user_list.d.ts +31 -0
  108. package/script/types/4_blocked_user_list.d.ts.map +1 -0
  109. package/script/types/4_blocked_user_list.js +28 -0
  110. package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
  111. package/esm/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
  112. package/esm/deps/jsr.io/@std/async/1.2.0/_util.js +0 -6
  113. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
  114. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
  115. package/esm/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -46
  116. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
  117. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
  118. package/esm/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -41
  119. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
  120. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
  121. package/esm/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -57
  122. package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
  123. package/esm/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
  124. package/esm/deps/jsr.io/@std/async/1.2.0/mod.js +0 -23
  125. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
  126. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
  127. package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -154
  128. package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
  129. package/esm/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
  130. package/esm/deps/jsr.io/@std/async/1.2.0/retry.js +0 -147
  131. package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
  132. package/esm/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
  133. package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +0 -79
  134. package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts +0 -2
  135. package/script/deps/jsr.io/@std/async/1.2.0/_util.d.ts.map +0 -1
  136. package/script/deps/jsr.io/@std/async/1.2.0/_util.js +0 -9
  137. package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts +0 -107
  138. package/script/deps/jsr.io/@std/async/1.2.0/abortable.d.ts.map +0 -1
  139. package/script/deps/jsr.io/@std/async/1.2.0/abortable.js +0 -49
  140. package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts +0 -37
  141. package/script/deps/jsr.io/@std/async/1.2.0/deadline.d.ts.map +0 -1
  142. package/script/deps/jsr.io/@std/async/1.2.0/deadline.js +0 -44
  143. package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts +0 -44
  144. package/script/deps/jsr.io/@std/async/1.2.0/debounce.d.ts.map +0 -1
  145. package/script/deps/jsr.io/@std/async/1.2.0/debounce.js +0 -60
  146. package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts +0 -22
  147. package/script/deps/jsr.io/@std/async/1.2.0/mod.d.ts.map +0 -1
  148. package/script/deps/jsr.io/@std/async/1.2.0/mod.js +0 -39
  149. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts +0 -111
  150. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.d.ts.map +0 -1
  151. package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +0 -158
  152. package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts +0 -155
  153. package/script/deps/jsr.io/@std/async/1.2.0/retry.d.ts.map +0 -1
  154. package/script/deps/jsr.io/@std/async/1.2.0/retry.js +0 -152
  155. package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts +0 -43
  156. package/script/deps/jsr.io/@std/async/1.2.0/tee.d.ts.map +0 -1
  157. package/script/deps/jsr.io/@std/async/1.2.0/tee.js +0 -82
@@ -1,147 +0,0 @@
1
- // Copyright 2018-2026 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- import { delay } from "./delay.js";
4
- import { exponentialBackoffWithJitter } from "./_util.js";
5
- /**
6
- * Error thrown in {@linkcode retry} once the maximum number of failed attempts
7
- * has been reached.
8
- *
9
- * @example Usage
10
- * ```ts no-assert ignore
11
- * import { RetryError } from "@std/async/retry";
12
- *
13
- * throw new RetryError({ foo: "bar" }, 3);
14
- * ```
15
- */
16
- export class RetryError extends Error {
17
- /**
18
- * Constructs a new {@linkcode RetryError} instance.
19
- *
20
- * @param cause the cause for this error.
21
- * @param attempts the number of retry attempts made.
22
- */
23
- constructor(cause, attempts) {
24
- super(`Retrying exceeded the maxAttempts (${attempts}).`);
25
- this.name = "RetryError";
26
- this.cause = cause;
27
- }
28
- }
29
- /**
30
- * Calls the given (possibly asynchronous) function up to `maxAttempts` times.
31
- * Retries as long as the given function throws. If the attempts are exhausted,
32
- * throws a {@linkcode RetryError} with `cause` set to the inner exception.
33
- *
34
- * 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.
35
- * How long the actual delay is, depends on `jitter`.
36
- *
37
- * When `jitter` is the default value of `1`, waits between two attempts for a
38
- * randomized amount between 0 and the backoff time. With the default options
39
- * the maximal delay will be `15s = 1s + 2s + 4s + 8s`. If all five attempts
40
- * are exhausted the mean delay will be `9.5s = ½(4s + 15s)`.
41
- *
42
- * When `jitter` is `0`, waits the full backoff time.
43
- *
44
- * @example Example configuration 1
45
- * ```ts no-assert
46
- * import { retry } from "@std/async/retry";
47
- * const req = async () => {
48
- * // some function that throws sometimes
49
- * };
50
- *
51
- * // Below resolves to the first non-error result of `req`
52
- * const retryPromise = await retry(req, {
53
- * multiplier: 2,
54
- * maxTimeout: 60000,
55
- * maxAttempts: 5,
56
- * minTimeout: 100,
57
- * jitter: 1,
58
- * });
59
- * ```
60
- *
61
- * @example Example configuration 2
62
- * ```ts no-assert
63
- * import { retry } from "@std/async/retry";
64
- * const req = async () => {
65
- * // some function that throws sometimes
66
- * };
67
- *
68
- * // Make sure we wait at least 1 minute, but at most 2 minutes
69
- * const retryPromise = await retry(req, {
70
- * multiplier: 2.34,
71
- * maxTimeout: 80000,
72
- * maxAttempts: 7,
73
- * minTimeout: 1000,
74
- * jitter: 0.5,
75
- * });
76
- * ```
77
- *
78
- * @example Only retry on specific error types
79
- * ```ts no-assert
80
- * import { retry } from "@std/async/retry";
81
- *
82
- * class HttpError extends Error {
83
- * status: number;
84
- * constructor(status: number) {
85
- * super(`HTTP ${status}`);
86
- * this.status = status;
87
- * }
88
- * }
89
- *
90
- * const req = async () => {
91
- * // some function that throws HttpError
92
- * };
93
- *
94
- * // Only retry on 429 (rate limit) or 5xx (server) errors
95
- * const retryPromise = await retry(req, {
96
- * isRetriable: (err) =>
97
- * err instanceof HttpError && (err.status === 429 || err.status >= 500),
98
- * });
99
- * ```
100
- *
101
- * @typeParam T The return type of the function to retry and returned promise.
102
- * @param fn The function to retry.
103
- * @param options Additional options.
104
- * @returns The promise that resolves with the value returned by the function to retry.
105
- * @throws {RetryError} If the function fails after `maxAttempts` attempts.
106
- * @throws If the `signal` is aborted, throws the signal's reason.
107
- * @throws If `isRetriable` returns `false` for an error, throws that error immediately.
108
- */
109
- export async function retry(fn, options) {
110
- const { multiplier = 2, maxTimeout = 60000, maxAttempts = 5, minTimeout = 1000, jitter = 1, isRetriable = () => true, signal, } = options ?? {};
111
- if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {
112
- throw new RangeError(`Cannot retry as 'maxAttempts' must be a positive integer: current value is ${maxAttempts}`);
113
- }
114
- if (!Number.isFinite(multiplier) || multiplier < 1) {
115
- throw new RangeError(`Cannot retry as 'multiplier' must be a finite number >= 1: current value is ${multiplier}`);
116
- }
117
- if (Number.isNaN(maxTimeout) || maxTimeout <= 0) {
118
- throw new RangeError(`Cannot retry as 'maxTimeout' must be a positive number: current value is ${maxTimeout}`);
119
- }
120
- if (Number.isNaN(minTimeout) || minTimeout < 0) {
121
- throw new RangeError(`Cannot retry as 'minTimeout' must be >= 0: current value is ${minTimeout}`);
122
- }
123
- if (minTimeout > maxTimeout) {
124
- throw new RangeError(`Cannot retry as 'minTimeout' must be <= 'maxTimeout': current values 'minTimeout=${minTimeout}', 'maxTimeout=${maxTimeout}'`);
125
- }
126
- if (Number.isNaN(jitter) || jitter < 0 || jitter > 1) {
127
- throw new RangeError(`Cannot retry as 'jitter' must be between 0 and 1: current value is ${jitter}`);
128
- }
129
- let attempt = 0;
130
- while (true) {
131
- signal?.throwIfAborted();
132
- try {
133
- return await fn();
134
- }
135
- catch (error) {
136
- if (!isRetriable(error)) {
137
- throw error;
138
- }
139
- if (attempt + 1 >= maxAttempts) {
140
- throw new RetryError(error, maxAttempts);
141
- }
142
- const timeout = exponentialBackoffWithJitter(maxTimeout, minTimeout, attempt, multiplier, jitter);
143
- await delay(timeout, signal ? { signal } : undefined);
144
- }
145
- attempt++;
146
- }
147
- }
@@ -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"}
@@ -1,79 +0,0 @@
1
- // Copyright 2018-2026 the Deno authors. MIT license.
2
- // This module is browser compatible.
3
- class Queue {
4
- #source;
5
- #queue;
6
- head;
7
- done;
8
- constructor(iterable) {
9
- this.#source = iterable[Symbol.asyncIterator]();
10
- this.#queue = {
11
- value: undefined,
12
- next: undefined,
13
- };
14
- this.head = this.#queue;
15
- this.done = false;
16
- }
17
- async next() {
18
- const result = await this.#source.next();
19
- if (!result.done) {
20
- const nextNode = {
21
- value: result.value,
22
- next: undefined,
23
- };
24
- this.#queue.next = nextNode;
25
- this.#queue = nextNode;
26
- }
27
- else {
28
- this.done = true;
29
- }
30
- }
31
- }
32
- /**
33
- * Branches the given async iterable into the `n` branches.
34
- *
35
- * @example Usage
36
- * ```ts
37
- * import { tee } from "@std/async/tee";
38
- * import { assertEquals } from "@std/assert";
39
- *
40
- * const gen = async function* gen() {
41
- * yield 1;
42
- * yield 2;
43
- * yield 3;
44
- * };
45
- *
46
- * const [branch1, branch2] = tee(gen());
47
- *
48
- * const result1 = await Array.fromAsync(branch1);
49
- * assertEquals(result1, [1, 2, 3]);
50
- *
51
- * const result2 = await Array.fromAsync(branch2);
52
- * assertEquals(result2, [1, 2, 3]);
53
- * ```
54
- *
55
- * @typeParam T The type of the provided async iterable and the returned async iterables.
56
- * @typeParam N The amount of branches to tee into.
57
- * @param iterable The iterable to tee.
58
- * @param n The amount of branches to tee into.
59
- * @returns The tuple where each element is an async iterable.
60
- */
61
- export function tee(iterable, n = 2) {
62
- const queue = new Queue(iterable);
63
- async function* generator() {
64
- let buffer = queue.head;
65
- while (true) {
66
- if (buffer.next) {
67
- buffer = buffer.next;
68
- yield buffer.value;
69
- }
70
- else if (queue.done) {
71
- return;
72
- }
73
- else {
74
- await queue.next();
75
- }
76
- }
77
- }
78
- return Array.from({ length: n }).map(() => generator());
79
- }
@@ -1,2 +0,0 @@
1
- export declare function exponentialBackoffWithJitter(cap: number, base: number, attempt: number, multiplier: number, jitter: number): number;
2
- //# sourceMappingURL=_util.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_util.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/_util.ts"],"names":[],"mappings":"AAGA,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,UAIf"}
@@ -1,9 +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.exponentialBackoffWithJitter = exponentialBackoffWithJitter;
6
- function exponentialBackoffWithJitter(cap, base, attempt, multiplier, jitter) {
7
- const exp = Math.min(cap, base * multiplier ** attempt);
8
- return (1 - jitter * Math.random()) * exp;
9
- }
@@ -1,107 +0,0 @@
1
- /**
2
- * Make a {@linkcode Promise} abortable with the given signal.
3
- *
4
- * @throws {DOMException} If the signal is already aborted and `signal.reason`
5
- * is undefined. Otherwise, throws `signal.reason`.
6
- * @typeParam T The type of the provided and returned promise.
7
- * @param p The promise to make abortable.
8
- * @param signal The signal to abort the promise with.
9
- * @returns A promise that can be aborted.
10
- *
11
- * @example Error-handling a timeout
12
- * ```ts ignore
13
- * import { abortable, delay } from "@std/async";
14
- * import { assertRejects, assertEquals } from "@std/assert";
15
- *
16
- * const promise = delay(1_000);
17
- *
18
- * // Rejects with `DOMException` after 100 ms
19
- * await assertRejects(
20
- * () => abortable(promise, AbortSignal.timeout(100)),
21
- * DOMException,
22
- * "Signal timed out."
23
- * );
24
- * ```
25
- *
26
- * @example Error-handling an abort
27
- * ```ts ignore
28
- * import { abortable, delay } from "@std/async";
29
- * import { assertRejects, assertEquals } from "@std/assert";
30
- *
31
- * const promise = delay(1_000);
32
- * const controller = new AbortController();
33
- * controller.abort(new Error("This is my reason"));
34
- *
35
- * // Rejects with `DOMException` immediately
36
- * await assertRejects(
37
- * () => abortable(promise, controller.signal),
38
- * Error,
39
- * "This is my reason"
40
- * );
41
- * ```
42
- */
43
- export declare function abortable<T>(p: Promise<T>, signal: AbortSignal): Promise<T>;
44
- /**
45
- * Make an {@linkcode AsyncIterable} abortable with the given signal.
46
- *
47
- * @throws {DOMException} If the signal is already aborted and `signal.reason`
48
- * is undefined. Otherwise, throws `signal.reason`.
49
- * @typeParam T The type of the provided and returned async iterable.
50
- * @param p The async iterable to make abortable.
51
- * @param signal The signal to abort the promise with.
52
- * @returns An async iterable that can be aborted.
53
- *
54
- * @example Error-handling a timeout
55
- * ```ts
56
- * import { abortable, delay } from "@std/async";
57
- * import { assertRejects, assertEquals } from "@std/assert";
58
- *
59
- * const asyncIter = async function* () {
60
- * yield "Hello";
61
- * await delay(1_000);
62
- * yield "World";
63
- * };
64
- *
65
- * const items: string[] = [];
66
- * // Below throws `DOMException` after 100 ms and items become `["Hello"]`
67
- * await assertRejects(
68
- * async () => {
69
- * for await (const item of abortable(asyncIter(), AbortSignal.timeout(100))) {
70
- * items.push(item);
71
- * }
72
- * },
73
- * DOMException,
74
- * "Signal timed out."
75
- * );
76
- * assertEquals(items, ["Hello"]);
77
- * ```
78
- *
79
- * @example Error-handling an abort
80
- * ```ts
81
- * import { abortable, delay } from "@std/async";
82
- * import { assertRejects, assertEquals } from "@std/assert";
83
- *
84
- * const asyncIter = async function* () {
85
- * yield "Hello";
86
- * await delay(1_000);
87
- * yield "World";
88
- * };
89
- * const controller = new AbortController();
90
- * controller.abort(new Error("This is my reason"));
91
- *
92
- * const items: string[] = [];
93
- * // Below throws `DOMException` immediately
94
- * await assertRejects(
95
- * async () => {
96
- * for await (const item of abortable(asyncIter(), controller.signal)) {
97
- * items.push(item);
98
- * }
99
- * },
100
- * Error,
101
- * "This is my reason"
102
- * );
103
- * assertEquals(items, []);
104
- * ```
105
- */
106
- export declare function abortable<T>(p: AsyncIterable<T>, signal: AbortSignal): AsyncGenerator<T>;
107
- //# sourceMappingURL=abortable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abortable.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/async/1.2.0/abortable.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EACzB,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC"}
@@ -1,49 +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.abortable = abortable;
6
- function abortable(p, signal) {
7
- if (p instanceof Promise) {
8
- return abortablePromise(p, signal);
9
- }
10
- else {
11
- return abortableAsyncIterable(p, signal);
12
- }
13
- }
14
- function abortablePromise(p, signal) {
15
- const { promise, reject } = Promise.withResolvers();
16
- const abort = () => reject(signal.reason);
17
- if (signal.aborted)
18
- abort();
19
- signal.addEventListener("abort", abort, { once: true });
20
- return Promise.race([promise, p]).finally(() => {
21
- signal.removeEventListener("abort", abort);
22
- });
23
- }
24
- async function* abortableAsyncIterable(p, signal) {
25
- signal.throwIfAborted();
26
- const { promise, reject } = Promise.withResolvers();
27
- const abort = () => reject(signal.reason);
28
- signal.addEventListener("abort", abort, { once: true });
29
- const it = p[Symbol.asyncIterator]();
30
- try {
31
- while (true) {
32
- const race = Promise.race([promise, it.next()]);
33
- race.catch(() => {
34
- signal.removeEventListener("abort", abort);
35
- });
36
- const { done, value } = await race;
37
- if (done) {
38
- signal.removeEventListener("abort", abort);
39
- const result = await it.return?.(value);
40
- return result?.value;
41
- }
42
- yield value;
43
- }
44
- }
45
- catch (e) {
46
- await it.return?.();
47
- throw e;
48
- }
49
- }
@@ -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,44 +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.deadline = deadline;
6
- const abortable_js_1 = require("./abortable.js");
7
- /**
8
- * Create a promise which will be rejected with {@linkcode DOMException} when
9
- * a given delay is exceeded.
10
- *
11
- * Note: Prefer to use {@linkcode AbortSignal.timeout} instead for the APIs
12
- * that accept {@linkcode AbortSignal}.
13
- *
14
- * @throws {DOMException & { name: "TimeoutError" }} If the provided duration
15
- * runs out before resolving.
16
- * @throws {DOMException & { name: "AbortError" }} If the optional signal is
17
- * aborted with the default `reason` before resolving or timing out.
18
- * @throws {AbortSignal["reason"]} If the optional signal is aborted with a
19
- * custom `reason` before resolving or timing out.
20
- * @typeParam T The type of the provided and returned promise.
21
- * @param p The promise to make rejectable.
22
- * @param ms Duration in milliseconds for when the promise should time out. If
23
- * greater than `Number.MAX_SAFE_INTEGER`, the deadline will never expire.
24
- * @param options Additional options.
25
- * @returns A promise that will reject if the provided duration runs out before resolving.
26
- *
27
- * @example Usage
28
- * ```ts ignore
29
- * import { deadline } from "@std/async/deadline";
30
- * import { delay } from "@std/async/delay";
31
- *
32
- * const delayedPromise = delay(1_000);
33
- * // Below throws `DOMException` after 10 ms
34
- * const result = await deadline(delayedPromise, 10);
35
- * ```
36
- */
37
- async function deadline(p, ms, options = {}) {
38
- const signals = [];
39
- if (ms < Number.MAX_SAFE_INTEGER)
40
- signals.push(AbortSignal.timeout(ms));
41
- if (options.signal)
42
- signals.push(options.signal);
43
- return await (0, abortable_js_1.abortable)(p, AbortSignal.any(signals));
44
- }
@@ -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,60 +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.debounce = debounce;
6
- /**
7
- * Creates a debounced function that delays the given `func`
8
- * by a given `wait` time in milliseconds. If the method is called
9
- * again before the timeout expires, the previous call will be
10
- * aborted.
11
- *
12
- * @example Usage
13
- * ```ts ignore
14
- * import { debounce } from "@std/async/debounce";
15
- *
16
- * const log = debounce(
17
- * (event: Deno.FsEvent) =>
18
- * console.log("[%s] %s", event.kind, event.paths[0]),
19
- * 200,
20
- * );
21
- *
22
- * for await (const event of Deno.watchFs("./")) {
23
- * log(event);
24
- * }
25
- * // wait 200ms ...
26
- * // output: Function debounced after 200ms with baz
27
- * ```
28
- *
29
- * @typeParam T The arguments of the provided function.
30
- * @param fn The function to debounce.
31
- * @param wait The time in milliseconds to delay the function.
32
- * @returns The debounced function.
33
- */
34
- // deno-lint-ignore no-explicit-any
35
- function debounce(fn, wait) {
36
- let timeout = null;
37
- let flush = null;
38
- const debounced = ((...args) => {
39
- debounced.clear();
40
- flush = () => {
41
- debounced.clear();
42
- fn.call(debounced, ...args);
43
- };
44
- timeout = Number(setTimeout(flush, wait));
45
- });
46
- debounced.clear = () => {
47
- if (typeof timeout === "number") {
48
- clearTimeout(timeout);
49
- timeout = null;
50
- flush = null;
51
- }
52
- };
53
- debounced.flush = () => {
54
- flush?.();
55
- };
56
- Object.defineProperty(debounced, "pending", {
57
- get: () => typeof timeout === "number",
58
- });
59
- return debounced;
60
- }
@@ -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"}