@procedures/collections 0.47.1 → 0.48.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 (238) hide show
  1. package/CHANGELOG.md +32 -8
  2. package/README.md +3 -1
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/index.d.ts +1 -59
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -95
  7. package/dist/index.js.map +1 -1
  8. package/dist/storage/index.d.ts +2 -2
  9. package/dist/storage/index.d.ts.map +1 -1
  10. package/dist/storage/index.js +1 -1
  11. package/dist/storage/index.js.map +1 -1
  12. package/dist/storage/memory.d.ts +1 -1
  13. package/dist/storage/memory.d.ts.map +1 -1
  14. package/dist/storage/memory.js +1 -1
  15. package/dist/storage/memory.js.map +1 -1
  16. package/dist/testing/index.d.ts +1 -1
  17. package/dist/testing/index.d.ts.map +1 -1
  18. package/dist/testing/index.js +1 -1
  19. package/dist/testing/index.js.map +1 -1
  20. package/dist/testing/storage-contract.js +1 -1
  21. package/dist/testing/storage-contract.js.map +1 -1
  22. package/dist/undo/index.d.ts +1 -1
  23. package/dist/undo/index.js +1 -1
  24. package/dist/undo/undo-log.d.ts +1 -1
  25. package/dist/undo/undo-log.js +1 -1
  26. package/package.json +5 -5
  27. package/src/index.ts +338 -214
  28. package/src/storage/index.ts +2 -2
  29. package/src/storage/memory.ts +1 -1
  30. package/src/testing/index.ts +1 -1
  31. package/src/testing/storage-contract.ts +1 -1
  32. package/src/undo/index.ts +1 -1
  33. package/src/undo/undo-log.ts +1 -1
  34. package/dist/async/async-queue.d.ts +0 -170
  35. package/dist/async/async-queue.d.ts.map +0 -1
  36. package/dist/async/async-queue.js +0 -404
  37. package/dist/async/async-queue.js.map +0 -1
  38. package/dist/async/channels.d.ts +0 -211
  39. package/dist/async/channels.d.ts.map +0 -1
  40. package/dist/async/channels.js +0 -393
  41. package/dist/async/channels.js.map +0 -1
  42. package/dist/async/settled.d.ts +0 -23
  43. package/dist/async/settled.d.ts.map +0 -1
  44. package/dist/async/settled.js +0 -32
  45. package/dist/async/settled.js.map +0 -1
  46. package/dist/behaviors/bounded.d.ts +0 -79
  47. package/dist/behaviors/bounded.d.ts.map +0 -1
  48. package/dist/behaviors/bounded.js +0 -393
  49. package/dist/behaviors/bounded.js.map +0 -1
  50. package/dist/behaviors/composite.d.ts +0 -17
  51. package/dist/behaviors/composite.d.ts.map +0 -1
  52. package/dist/behaviors/composite.js +0 -93
  53. package/dist/behaviors/composite.js.map +0 -1
  54. package/dist/behaviors/evented.d.ts +0 -154
  55. package/dist/behaviors/evented.d.ts.map +0 -1
  56. package/dist/behaviors/evented.js +0 -299
  57. package/dist/behaviors/evented.js.map +0 -1
  58. package/dist/behaviors/lru.d.ts +0 -84
  59. package/dist/behaviors/lru.d.ts.map +0 -1
  60. package/dist/behaviors/lru.js +0 -376
  61. package/dist/behaviors/lru.js.map +0 -1
  62. package/dist/behaviors/readonly.d.ts +0 -73
  63. package/dist/behaviors/readonly.d.ts.map +0 -1
  64. package/dist/behaviors/readonly.js +0 -189
  65. package/dist/behaviors/readonly.js.map +0 -1
  66. package/dist/behaviors/safe.d.ts +0 -163
  67. package/dist/behaviors/safe.d.ts.map +0 -1
  68. package/dist/behaviors/safe.js +0 -176
  69. package/dist/behaviors/safe.js.map +0 -1
  70. package/dist/behaviors/synchronized.d.ts +0 -88
  71. package/dist/behaviors/synchronized.d.ts.map +0 -1
  72. package/dist/behaviors/synchronized.js +0 -285
  73. package/dist/behaviors/synchronized.js.map +0 -1
  74. package/dist/behaviors/ttl.d.ts +0 -118
  75. package/dist/behaviors/ttl.d.ts.map +0 -1
  76. package/dist/behaviors/ttl.js +0 -354
  77. package/dist/behaviors/ttl.js.map +0 -1
  78. package/dist/contracts/model.d.ts +0 -29
  79. package/dist/contracts/model.d.ts.map +0 -1
  80. package/dist/contracts/model.js +0 -26
  81. package/dist/contracts/model.js.map +0 -1
  82. package/dist/core/effects.d.ts +0 -176
  83. package/dist/core/effects.d.ts.map +0 -1
  84. package/dist/core/effects.js +0 -180
  85. package/dist/core/effects.js.map +0 -1
  86. package/dist/core/events.d.ts +0 -192
  87. package/dist/core/events.d.ts.map +0 -1
  88. package/dist/core/events.js +0 -291
  89. package/dist/core/events.js.map +0 -1
  90. package/dist/core/middleware.d.ts +0 -231
  91. package/dist/core/middleware.d.ts.map +0 -1
  92. package/dist/core/middleware.js +0 -161
  93. package/dist/core/middleware.js.map +0 -1
  94. package/dist/core/policies.d.ts +0 -220
  95. package/dist/core/policies.d.ts.map +0 -1
  96. package/dist/core/policies.js +0 -48
  97. package/dist/core/policies.js.map +0 -1
  98. package/dist/core/traits.d.ts +0 -142
  99. package/dist/core/traits.d.ts.map +0 -1
  100. package/dist/core/traits.js +0 -8
  101. package/dist/core/traits.js.map +0 -1
  102. package/dist/fx/collectors.d.ts +0 -193
  103. package/dist/fx/collectors.d.ts.map +0 -1
  104. package/dist/fx/collectors.js +0 -375
  105. package/dist/fx/collectors.js.map +0 -1
  106. package/dist/fx/iter.d.ts +0 -166
  107. package/dist/fx/iter.d.ts.map +0 -1
  108. package/dist/fx/iter.js +0 -421
  109. package/dist/fx/iter.js.map +0 -1
  110. package/dist/impl/array-deque.d.ts +0 -112
  111. package/dist/impl/array-deque.d.ts.map +0 -1
  112. package/dist/impl/array-deque.js +0 -380
  113. package/dist/impl/array-deque.js.map +0 -1
  114. package/dist/impl/array-list.d.ts +0 -101
  115. package/dist/impl/array-list.d.ts.map +0 -1
  116. package/dist/impl/array-list.js +0 -387
  117. package/dist/impl/array-list.js.map +0 -1
  118. package/dist/impl/hash-map.d.ts +0 -149
  119. package/dist/impl/hash-map.d.ts.map +0 -1
  120. package/dist/impl/hash-map.js +0 -473
  121. package/dist/impl/hash-map.js.map +0 -1
  122. package/dist/impl/hash-set.d.ts +0 -125
  123. package/dist/impl/hash-set.d.ts.map +0 -1
  124. package/dist/impl/hash-set.js +0 -264
  125. package/dist/impl/hash-set.js.map +0 -1
  126. package/dist/impl/linked-hash-map.d.ts +0 -141
  127. package/dist/impl/linked-hash-map.d.ts.map +0 -1
  128. package/dist/impl/linked-hash-map.js +0 -442
  129. package/dist/impl/linked-hash-map.js.map +0 -1
  130. package/dist/impl/linked-list.d.ts +0 -109
  131. package/dist/impl/linked-list.d.ts.map +0 -1
  132. package/dist/impl/linked-list.js +0 -494
  133. package/dist/impl/linked-list.js.map +0 -1
  134. package/dist/impl/priority-queue.d.ts +0 -139
  135. package/dist/impl/priority-queue.d.ts.map +0 -1
  136. package/dist/impl/priority-queue.js +0 -343
  137. package/dist/impl/priority-queue.js.map +0 -1
  138. package/dist/impl/summary-tree.d.ts +0 -146
  139. package/dist/impl/summary-tree.d.ts.map +0 -1
  140. package/dist/impl/summary-tree.js +0 -524
  141. package/dist/impl/summary-tree.js.map +0 -1
  142. package/dist/impl/tree-map.d.ts +0 -153
  143. package/dist/impl/tree-map.d.ts.map +0 -1
  144. package/dist/impl/tree-map.js +0 -788
  145. package/dist/impl/tree-map.js.map +0 -1
  146. package/dist/impl/tree-set.d.ts +0 -112
  147. package/dist/impl/tree-set.d.ts.map +0 -1
  148. package/dist/impl/tree-set.js +0 -374
  149. package/dist/impl/tree-set.js.map +0 -1
  150. package/dist/interfaces/collection.d.ts +0 -119
  151. package/dist/interfaces/collection.d.ts.map +0 -1
  152. package/dist/interfaces/collection.js +0 -8
  153. package/dist/interfaces/collection.js.map +0 -1
  154. package/dist/interfaces/list.d.ts +0 -247
  155. package/dist/interfaces/list.d.ts.map +0 -1
  156. package/dist/interfaces/list.js +0 -8
  157. package/dist/interfaces/list.js.map +0 -1
  158. package/dist/interfaces/map.d.ts +0 -344
  159. package/dist/interfaces/map.d.ts.map +0 -1
  160. package/dist/interfaces/map.js +0 -8
  161. package/dist/interfaces/map.js.map +0 -1
  162. package/dist/interfaces/queue.d.ts +0 -304
  163. package/dist/interfaces/queue.d.ts.map +0 -1
  164. package/dist/interfaces/queue.js +0 -8
  165. package/dist/interfaces/queue.js.map +0 -1
  166. package/dist/interfaces/set.d.ts +0 -137
  167. package/dist/interfaces/set.d.ts.map +0 -1
  168. package/dist/interfaces/set.js +0 -8
  169. package/dist/interfaces/set.js.map +0 -1
  170. package/dist/order/index.d.ts +0 -7
  171. package/dist/order/index.d.ts.map +0 -1
  172. package/dist/order/index.js +0 -7
  173. package/dist/order/index.js.map +0 -1
  174. package/dist/order/rank.d.ts +0 -100
  175. package/dist/order/rank.d.ts.map +0 -1
  176. package/dist/order/rank.js +0 -286
  177. package/dist/order/rank.js.map +0 -1
  178. package/dist/storage/listeners.d.ts +0 -39
  179. package/dist/storage/listeners.d.ts.map +0 -1
  180. package/dist/storage/listeners.js +0 -65
  181. package/dist/storage/listeners.js.map +0 -1
  182. package/dist/testing/check.d.ts +0 -25
  183. package/dist/testing/check.d.ts.map +0 -1
  184. package/dist/testing/check.js +0 -85
  185. package/dist/testing/check.js.map +0 -1
  186. package/dist/utils/defaults.d.ts +0 -135
  187. package/dist/utils/defaults.d.ts.map +0 -1
  188. package/dist/utils/defaults.js +0 -322
  189. package/dist/utils/defaults.js.map +0 -1
  190. package/dist/utils/factories.d.ts +0 -144
  191. package/dist/utils/factories.d.ts.map +0 -1
  192. package/dist/utils/factories.js +0 -293
  193. package/dist/utils/factories.js.map +0 -1
  194. package/dist/utils/helpers.d.ts +0 -137
  195. package/dist/utils/helpers.d.ts.map +0 -1
  196. package/dist/utils/helpers.js +0 -221
  197. package/dist/utils/helpers.js.map +0 -1
  198. package/src/async/async-queue.ts +0 -481
  199. package/src/async/channels.ts +0 -450
  200. package/src/async/settled.ts +0 -41
  201. package/src/behaviors/bounded.ts +0 -485
  202. package/src/behaviors/composite.ts +0 -99
  203. package/src/behaviors/evented.ts +0 -464
  204. package/src/behaviors/lru.ts +0 -447
  205. package/src/behaviors/readonly.ts +0 -236
  206. package/src/behaviors/safe.ts +0 -372
  207. package/src/behaviors/synchronized.ts +0 -316
  208. package/src/behaviors/ttl.ts +0 -462
  209. package/src/contracts/model.ts +0 -44
  210. package/src/core/effects.ts +0 -323
  211. package/src/core/events.ts +0 -356
  212. package/src/core/middleware.ts +0 -415
  213. package/src/core/policies.ts +0 -316
  214. package/src/core/traits.ts +0 -164
  215. package/src/fx/collectors.ts +0 -500
  216. package/src/fx/iter.ts +0 -536
  217. package/src/impl/array-deque.ts +0 -463
  218. package/src/impl/array-list.ts +0 -490
  219. package/src/impl/hash-map.ts +0 -623
  220. package/src/impl/hash-set.ts +0 -342
  221. package/src/impl/linked-hash-map.ts +0 -572
  222. package/src/impl/linked-list.ts +0 -606
  223. package/src/impl/priority-queue.ts +0 -448
  224. package/src/impl/summary-tree.ts +0 -586
  225. package/src/impl/tree-map.ts +0 -912
  226. package/src/impl/tree-set.ts +0 -469
  227. package/src/interfaces/collection.ts +0 -141
  228. package/src/interfaces/list.ts +0 -281
  229. package/src/interfaces/map.ts +0 -405
  230. package/src/interfaces/queue.ts +0 -353
  231. package/src/interfaces/set.ts +0 -158
  232. package/src/order/index.ts +0 -6
  233. package/src/order/rank.ts +0 -271
  234. package/src/storage/listeners.ts +0 -72
  235. package/src/testing/check.ts +0 -81
  236. package/src/utils/defaults.ts +0 -345
  237. package/src/utils/factories.ts +0 -357
  238. package/src/utils/helpers.ts +0 -248
@@ -1,170 +0,0 @@
1
- /**
2
- * AsyncQueue - An async iterable queue with backpressure support.
3
- *
4
- * Designed for producer-consumer patterns where producers can wait when
5
- * the queue is full and consumers can wait when the queue is empty.
6
- * Implements AsyncIterable for use with for-await-of loops.
7
- *
8
- * @example
9
- * const queue = asyncQueue<number>({ capacity: 10 })
10
- *
11
- * // Producer
12
- * await queue.put(42) // Waits if queue is full
13
- *
14
- * // Consumer
15
- * const value = await queue.take() // Waits if queue is empty
16
- *
17
- * // Async iteration
18
- * for await (const value of queue) {
19
- * console.log(value)
20
- * }
21
- */
22
- import type { AsyncQueue as IAsyncQueue } from "../interfaces/queue.js";
23
- /**
24
- * Options for creating an AsyncQueue.
25
- */
26
- export interface AsyncQueueOptions {
27
- /**
28
- * Maximum capacity. Infinity for unbounded queue.
29
- * @default Infinity
30
- */
31
- capacity?: number;
32
- /**
33
- * Timeout for put/take operations in milliseconds.
34
- * @default undefined (no timeout)
35
- */
36
- timeout?: number;
37
- }
38
- /**
39
- * AsyncQueue<T> - Thread-safe async queue with backpressure.
40
- *
41
- * Features:
42
- * - Blocking put() when full (backpressure)
43
- * - Blocking take() when empty
44
- * - AsyncIterable support
45
- * - Graceful closing
46
- * - Timeouts
47
- *
48
- * Perfect for:
49
- * - Producer-consumer patterns
50
- * - Rate limiting
51
- * - Task queues
52
- * - Stream processing
53
- */
54
- export declare class AsyncQueue<T> implements IAsyncQueue<T> {
55
- private buffer;
56
- private putters;
57
- private takers;
58
- /** The calls of `peek` that wait: they see the next element, but they do not take it. */
59
- private peekers;
60
- private _isClosed;
61
- private readonly capacity;
62
- private readonly defaultTimeout?;
63
- constructor(options?: AsyncQueueOptions);
64
- get size(): number;
65
- get isEmpty(): boolean;
66
- get isFull(): boolean;
67
- get isClosed(): boolean;
68
- get remainingCapacity(): number;
69
- /**
70
- * Adds an element to the queue.
71
- * If the queue is full, waits until space is available. With a capacity of 0, it waits until
72
- * a taker takes the element (a rendezvous).
73
- *
74
- * @throws Error if queue is closed
75
- * @throws Error if timeout expires
76
- */
77
- put(element: T, timeout?: number): Promise<void>;
78
- /**
79
- * Removes and returns an element from the queue.
80
- * If the queue is empty, waits until an element is available.
81
- *
82
- * @throws Error if queue is closed and empty
83
- * @throws Error if timeout expires
84
- */
85
- take(timeout?: number): Promise<T>;
86
- /**
87
- * This method waits for the next element, as `take` does, but it gives the element to
88
- * `onElement` and the closure of the queue to `onClosed`. These calls are synchronous: they
89
- * occur in the call that adds the element or closes the queue. The method has no timeout.
90
- *
91
- * The function that it returns withdraws the wait. A withdrawn wait gets no element, so no
92
- * element goes to a taker that left. `select` races its cases with this method.
93
- *
94
- * @returns A function that withdraws the wait. It returns true when the wait had no element yet.
95
- */
96
- waitTake(onElement: (element: T) => void, onClosed: (error: Error) => void): () => boolean;
97
- /**
98
- * Attempts to add an element without waiting.
99
- * Returns false if queue is full (with a capacity of 0: if no taker waits).
100
- */
101
- tryPut(element: T): boolean;
102
- /**
103
- * Attempts to remove an element without waiting.
104
- * Returns undefined if queue is empty.
105
- */
106
- tryTake(): T | undefined;
107
- /** Gives the element to a waiting taker, or puts it in the buffer when there is space. */
108
- private tryPutNow;
109
- /** Each waiting peek gets the element, which stays where it is. */
110
- private wakePeekers;
111
- /**
112
- * Takes the next element: from the buffer (then a waiting putter moves its element into the
113
- * buffer), or directly from a waiting putter (a capacity of 0). (Before, the direct path
114
- * released the putter but never gave its element to the taker, so the taker waited forever:
115
- * BUGS-2026-07 C11.)
116
- */
117
- private takeNow;
118
- /**
119
- * Returns the next element without removing it.
120
- * Waits if queue is empty.
121
- */
122
- peek(): Promise<T>;
123
- /**
124
- * Returns the next element without waiting.
125
- * Returns undefined if queue is empty.
126
- */
127
- tryPeek(): T | undefined;
128
- /**
129
- * Closes the queue. No more elements can be added.
130
- * Existing elements can still be consumed.
131
- */
132
- close(): void;
133
- /**
134
- * Drains all elements into an array.
135
- * Returns immediately with current elements.
136
- */
137
- drain(): T[];
138
- /**
139
- * Async iterator that yields elements as they become available.
140
- * Stops when queue is closed and empty.
141
- */
142
- [Symbol.asyncIterator](): AsyncIterator<T>;
143
- /** When the buffer has space, the first waiting putter moves its element into it. */
144
- private admitPutter;
145
- private clearTimeout;
146
- /**
147
- * Returns statistics about the queue.
148
- */
149
- getStats(): {
150
- size: number;
151
- capacity: number;
152
- isEmpty: boolean;
153
- isFull: boolean;
154
- isClosed: boolean;
155
- waitingPutters: number;
156
- waitingTakers: number;
157
- remainingCapacity: number;
158
- };
159
- toString(): string;
160
- }
161
- /**
162
- * Factory function to create an AsyncQueue.
163
- *
164
- * @example
165
- * const queue = asyncQueue<number>({ capacity: 100 })
166
- * await queue.put(42)
167
- * const value = await queue.take()
168
- */
169
- export declare function asyncQueue<T>(options?: AsyncQueueOptions): AsyncQueue<T>;
170
- //# sourceMappingURL=async-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-queue.d.ts","sourceRoot":"","sources":["../../src/async/async-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAgBD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,MAAM,CAAqB;IACnC,yFAAyF;IACzF,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAS;IAEzC,YAAY,OAAO,GAAE,iBAAsB,EAK1C;IAMD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAMD;;;;;;;OAOG;IACG,GAAG,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BrD;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CA0BvC;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,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- *
4
- * Designed for producer-consumer patterns where producers can wait when
5
- * the queue is full and consumers can wait when the queue is empty.
6
- * Implements AsyncIterable for use with for-await-of loops.
7
- *
8
- * @example
9
- * const queue = asyncQueue<number>({ capacity: 10 })
10
- *
11
- * // Producer
12
- * await queue.put(42) // Waits if queue is full
13
- *
14
- * // Consumer
15
- * const value = await queue.take() // Waits if queue is empty
16
- *
17
- * // Async iteration
18
- * for await (const value of queue) {
19
- * console.log(value)
20
- * }
21
- */
22
- /**
23
- * AsyncQueue<T> - Thread-safe async queue with backpressure.
24
- *
25
- * Features:
26
- * - Blocking put() when full (backpressure)
27
- * - Blocking take() when empty
28
- * - AsyncIterable support
29
- * - Graceful closing
30
- * - Timeouts
31
- *
32
- * Perfect for:
33
- * - Producer-consumer patterns
34
- * - Rate limiting
35
- * - Task queues
36
- * - Stream processing
37
- */
38
- export class AsyncQueue {
39
- buffer = [];
40
- putters = [];
41
- takers = [];
42
- /** The calls of `peek` that wait: they see the next element, but they do not take it. */
43
- peekers = [];
44
- _isClosed = false;
45
- capacity;
46
- defaultTimeout;
47
- constructor(options = {}) {
48
- this.capacity = options.capacity ?? Infinity;
49
- if (options.timeout !== undefined) {
50
- this.defaultTimeout = options.timeout;
51
- }
52
- }
53
- // ========================================================================
54
- // Size and state
55
- // ========================================================================
56
- get size() {
57
- return this.buffer.length;
58
- }
59
- get isEmpty() {
60
- return this.buffer.length === 0;
61
- }
62
- get isFull() {
63
- return this.buffer.length >= this.capacity;
64
- }
65
- get isClosed() {
66
- return this._isClosed;
67
- }
68
- get remainingCapacity() {
69
- return this.capacity === Infinity ? Infinity : this.capacity - this.buffer.length;
70
- }
71
- // ========================================================================
72
- // Blocking operations
73
- // ========================================================================
74
- /**
75
- * Adds an element to the queue.
76
- * If the queue is full, waits until space is available. With a capacity of 0, it waits until
77
- * a taker takes the element (a rendezvous).
78
- *
79
- * @throws Error if queue is closed
80
- * @throws Error if timeout expires
81
- */
82
- async put(element, timeout) {
83
- if (this._isClosed) {
84
- throw new Error("Queue is closed");
85
- }
86
- if (this.tryPutNow(element)) {
87
- return;
88
- }
89
- // A waiting peek sees the element of a waiting put (a capacity of 0)
90
- this.wakePeekers(element);
91
- // Queue is full: wait with the element. (Before, a waiting putter kept only its resolve
92
- // function, so its element was dropped when space came: BUGS-2026-07 C11.)
93
- return new Promise((resolve, reject) => {
94
- const putter = { element, resolve, reject };
95
- const timeoutMs = timeout ?? this.defaultTimeout;
96
- if (timeoutMs !== undefined) {
97
- putter.timeoutId = setTimeout(() => {
98
- const index = this.putters.indexOf(putter);
99
- if (index !== -1) {
100
- this.putters.splice(index, 1);
101
- }
102
- reject(new Error(`Put timeout after ${timeoutMs}ms`));
103
- }, timeoutMs);
104
- }
105
- this.putters.push(putter);
106
- });
107
- }
108
- /**
109
- * Removes and returns an element from the queue.
110
- * If the queue is empty, waits until an element is available.
111
- *
112
- * @throws Error if queue is closed and empty
113
- * @throws Error if timeout expires
114
- */
115
- async take(timeout) {
116
- const next = this.takeNow();
117
- if (next.found) {
118
- return next.element;
119
- }
120
- // If closed and empty, throw
121
- if (this._isClosed) {
122
- throw new Error("Queue is closed and empty");
123
- }
124
- // Wait for an element
125
- return new Promise((resolve, reject) => {
126
- const taker = { resolve, reject };
127
- const timeoutMs = timeout ?? this.defaultTimeout;
128
- if (timeoutMs !== undefined) {
129
- taker.timeoutId = setTimeout(() => {
130
- const index = this.takers.indexOf(taker);
131
- if (index !== -1) {
132
- this.takers.splice(index, 1);
133
- }
134
- reject(new Error(`Take timeout after ${timeoutMs}ms`));
135
- }, timeoutMs);
136
- }
137
- this.takers.push(taker);
138
- });
139
- }
140
- /**
141
- * This method waits for the next element, as `take` does, but it gives the element to
142
- * `onElement` and the closure of the queue to `onClosed`. These calls are synchronous: they
143
- * occur in the call that adds the element or closes the queue. The method has no timeout.
144
- *
145
- * The function that it returns withdraws the wait. A withdrawn wait gets no element, so no
146
- * element goes to a taker that left. `select` races its cases with this method.
147
- *
148
- * @returns A function that withdraws the wait. It returns true when the wait had no element yet.
149
- */
150
- waitTake(onElement, onClosed) {
151
- const next = this.takeNow();
152
- if (next.found) {
153
- onElement(next.element);
154
- return () => false;
155
- }
156
- if (this._isClosed) {
157
- onClosed(new Error("Queue is closed and empty"));
158
- return () => false;
159
- }
160
- const taker = { resolve: onElement, reject: onClosed };
161
- this.takers.push(taker);
162
- return () => {
163
- const index = this.takers.indexOf(taker);
164
- if (index === -1)
165
- return false;
166
- this.takers.splice(index, 1);
167
- return true;
168
- };
169
- }
170
- // ========================================================================
171
- // Non-blocking operations
172
- // ========================================================================
173
- /**
174
- * Attempts to add an element without waiting.
175
- * Returns false if queue is full (with a capacity of 0: if no taker waits).
176
- */
177
- tryPut(element) {
178
- if (this._isClosed) {
179
- return false;
180
- }
181
- return this.tryPutNow(element);
182
- }
183
- /**
184
- * Attempts to remove an element without waiting.
185
- * Returns undefined if queue is empty.
186
- */
187
- tryTake() {
188
- const next = this.takeNow();
189
- return next.found ? next.element : undefined;
190
- }
191
- /** Gives the element to a waiting taker, or puts it in the buffer when there is space. */
192
- tryPutNow(element) {
193
- // A waiting taker gets the element directly (the buffer is empty when a taker waits)
194
- const taker = this.takers.shift();
195
- if (taker) {
196
- this.wakePeekers(element);
197
- this.clearTimeout(taker);
198
- taker.resolve(element);
199
- return true;
200
- }
201
- if (this.buffer.length < this.capacity) {
202
- this.buffer.push(element);
203
- this.wakePeekers(element);
204
- return true;
205
- }
206
- return false;
207
- }
208
- /** Each waiting peek gets the element, which stays where it is. */
209
- wakePeekers(element) {
210
- const peekers = this.peekers;
211
- this.peekers = [];
212
- for (const peeker of peekers) {
213
- this.clearTimeout(peeker);
214
- peeker.resolve(element);
215
- }
216
- }
217
- /**
218
- * Takes the next element: from the buffer (then a waiting putter moves its element into the
219
- * buffer), or directly from a waiting putter (a capacity of 0). (Before, the direct path
220
- * released the putter but never gave its element to the taker, so the taker waited forever:
221
- * BUGS-2026-07 C11.)
222
- */
223
- takeNow() {
224
- if (this.buffer.length > 0) {
225
- const element = this.buffer.shift();
226
- this.admitPutter();
227
- return { found: true, element };
228
- }
229
- const putter = this.putters.shift();
230
- if (putter) {
231
- this.clearTimeout(putter);
232
- putter.resolve();
233
- return { found: true, element: putter.element };
234
- }
235
- return { found: false };
236
- }
237
- // ========================================================================
238
- // Peeking
239
- // ========================================================================
240
- /**
241
- * Returns the next element without removing it.
242
- * Waits if queue is empty.
243
- */
244
- async peek() {
245
- if (this.buffer.length > 0) {
246
- return this.buffer[0];
247
- }
248
- if (this.putters.length > 0) {
249
- return this.putters[0].element;
250
- }
251
- if (this._isClosed) {
252
- throw new Error("Queue is closed and empty");
253
- }
254
- // Wait for the next element without a take. (Before, peek took the element and put it back
255
- // at the front: a take that waited after it kept waiting, and the order changed: audit pass 2.)
256
- return new Promise((resolve, reject) => {
257
- const peeker = { resolve, reject };
258
- const timeoutMs = this.defaultTimeout;
259
- if (timeoutMs !== undefined) {
260
- peeker.timeoutId = setTimeout(() => {
261
- const index = this.peekers.indexOf(peeker);
262
- if (index !== -1) {
263
- this.peekers.splice(index, 1);
264
- }
265
- reject(new Error(`Peek timeout after ${timeoutMs}ms`));
266
- }, timeoutMs);
267
- }
268
- this.peekers.push(peeker);
269
- });
270
- }
271
- /**
272
- * Returns the next element without waiting.
273
- * Returns undefined if queue is empty.
274
- */
275
- tryPeek() {
276
- return this.buffer.length > 0 ? this.buffer[0] : this.putters[0]?.element;
277
- }
278
- // ========================================================================
279
- // Closing and draining
280
- // ========================================================================
281
- /**
282
- * Closes the queue. No more elements can be added.
283
- * Existing elements can still be consumed.
284
- */
285
- close() {
286
- this._isClosed = true;
287
- // Reject all waiting putters
288
- for (const putter of this.putters) {
289
- this.clearTimeout(putter);
290
- putter.reject(new Error("Queue closed"));
291
- }
292
- this.putters = [];
293
- // Wake up takers if queue is empty
294
- if (this.buffer.length === 0) {
295
- for (const taker of this.takers) {
296
- this.clearTimeout(taker);
297
- taker.reject(new Error("Queue closed and empty"));
298
- }
299
- this.takers = [];
300
- for (const peeker of this.peekers) {
301
- this.clearTimeout(peeker);
302
- peeker.reject(new Error("Queue closed and empty"));
303
- }
304
- this.peekers = [];
305
- }
306
- }
307
- /**
308
- * Drains all elements into an array.
309
- * Returns immediately with current elements.
310
- */
311
- drain() {
312
- // The buffer, then the elements of the waiting putters, in order. (Before, the waiting
313
- // putters were released but their elements were dropped.)
314
- const elements = this.buffer.slice();
315
- this.buffer = [];
316
- for (const putter of this.putters.splice(0)) {
317
- this.clearTimeout(putter);
318
- putter.resolve();
319
- elements.push(putter.element);
320
- }
321
- return elements;
322
- }
323
- // ========================================================================
324
- // Async iteration
325
- // ========================================================================
326
- /**
327
- * Async iterator that yields elements as they become available.
328
- * Stops when queue is closed and empty.
329
- */
330
- async *[Symbol.asyncIterator]() {
331
- while (true) {
332
- const next = this.takeNow();
333
- if (next.found) {
334
- yield next.element;
335
- }
336
- else if (this._isClosed) {
337
- break;
338
- }
339
- else {
340
- let element;
341
- try {
342
- element = await this.take();
343
- }
344
- catch (error) {
345
- // The queue was closed while the iterator waited
346
- if (this._isClosed)
347
- break;
348
- throw error;
349
- }
350
- yield element;
351
- }
352
- }
353
- }
354
- // ========================================================================
355
- // Private helpers
356
- // ========================================================================
357
- /** When the buffer has space, the first waiting putter moves its element into it. */
358
- admitPutter() {
359
- if (this.putters.length > 0 && this.buffer.length < this.capacity) {
360
- const putter = this.putters.shift();
361
- this.clearTimeout(putter);
362
- this.buffer.push(putter.element);
363
- putter.resolve();
364
- }
365
- }
366
- clearTimeout(resolver) {
367
- if (resolver.timeoutId) {
368
- clearTimeout(resolver.timeoutId);
369
- }
370
- }
371
- // ========================================================================
372
- // Utility methods
373
- // ========================================================================
374
- /**
375
- * Returns statistics about the queue.
376
- */
377
- getStats() {
378
- return {
379
- size: this.size,
380
- capacity: this.capacity,
381
- isEmpty: this.isEmpty,
382
- isFull: this.isFull,
383
- isClosed: this._isClosed,
384
- waitingPutters: this.putters.length,
385
- waitingTakers: this.takers.length,
386
- remainingCapacity: this.remainingCapacity,
387
- };
388
- }
389
- toString() {
390
- return `AsyncQueue[size=${this.size}, capacity=${this.capacity}, closed=${this._isClosed}]`;
391
- }
392
- }
393
- /**
394
- * Factory function to create an AsyncQueue.
395
- *
396
- * @example
397
- * const queue = asyncQueue<number>({ capacity: 100 })
398
- * await queue.put(42)
399
- * const value = await queue.take()
400
- */
401
- export function asyncQueue(options) {
402
- return new AsyncQueue(options);
403
- }
404
- //# sourceMappingURL=async-queue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-queue.js","sourceRoot":"","sources":["../../src/async/async-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAmCH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,GAAQ,EAAE,CAAC;IACjB,OAAO,GAAgB,EAAE,CAAC;IAC1B,MAAM,GAAkB,EAAE,CAAC;IACnC,yFAAyF;IACjF,OAAO,GAAkB,EAAE,CAAC;IAC5B,SAAS,GAAG,KAAK,CAAC;IACT,QAAQ,CAAS;IACjB,cAAc,CAAU;IAEzC,YAAY,OAAO,GAAsB,EAAE;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC;QAC7C,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;QACxC,CAAC;IACH,CAAC;IAED,2EAA2E;IAC3E,iBAAiB;IACjB,2EAA2E;IAE3E,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC;IAC7C,CAAC;IAED,IAAI,QAAQ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