@procedures/client 0.1.0 → 0.2.1
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/CHANGELOG.md +32 -0
- package/README.md +5 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/server/transport.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.js +1 -0
- package/dist/adapters/http/server/transport.js.map +1 -1
- package/dist/browser.d.ts +6 -3
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +4 -1
- package/dist/browser.js.map +1 -1
- package/dist/client/client.d.ts +9 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +27 -6
- package/dist/client/client.js.map +1 -1
- package/dist/client/types.d.ts +9 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/procedures/capability.d.ts +111 -0
- package/dist/procedures/capability.d.ts.map +1 -0
- package/dist/procedures/capability.js +269 -0
- package/dist/procedures/capability.js.map +1 -0
- package/dist/procedures/cli/discover.d.ts +3 -3
- package/dist/procedures/cli/discover.js +3 -3
- package/dist/procedures/cli/index.js +5 -3
- package/dist/procedures/cli/index.js.map +1 -1
- package/dist/procedures/cli/init.js +1 -1
- package/dist/procedures/collection/procedures.d.ts.map +1 -1
- package/dist/procedures/collection/procedures.js +12 -0
- package/dist/procedures/collection/procedures.js.map +1 -1
- package/dist/procedures/core/array.d.ts.map +1 -1
- package/dist/procedures/core/array.js +3 -1
- package/dist/procedures/core/array.js.map +1 -1
- package/dist/procedures/core/comparison.d.ts.map +1 -1
- package/dist/procedures/core/comparison.js +3 -1
- package/dist/procedures/core/comparison.js.map +1 -1
- package/dist/procedures/core/index.d.ts.map +1 -1
- package/dist/procedures/core/index.js +5 -2
- package/dist/procedures/core/index.js.map +1 -1
- package/dist/procedures/core/math.d.ts.map +1 -1
- package/dist/procedures/core/math.js +3 -1
- package/dist/procedures/core/math.js.map +1 -1
- package/dist/procedures/core/meta.d.ts.map +1 -1
- package/dist/procedures/core/meta.js +11 -6
- package/dist/procedures/core/meta.js.map +1 -1
- package/dist/procedures/core/object.d.ts.map +1 -1
- package/dist/procedures/core/object.js +3 -1
- package/dist/procedures/core/object.js.map +1 -1
- package/dist/procedures/core/string.d.ts.map +1 -1
- package/dist/procedures/core/string.js +3 -1
- package/dist/procedures/core/string.js.map +1 -1
- package/dist/procedures/core/type.d.ts.map +1 -1
- package/dist/procedures/core/type.js +3 -1
- package/dist/procedures/core/type.js.map +1 -1
- package/dist/procedures/define-procedure.d.ts.map +1 -1
- package/dist/procedures/define-procedure.js +5 -4
- package/dist/procedures/define-procedure.js.map +1 -1
- package/dist/procedures/effects.d.ts +15 -0
- package/dist/procedures/effects.d.ts.map +1 -0
- package/dist/procedures/effects.js +18 -0
- package/dist/procedures/effects.js.map +1 -0
- package/dist/procedures/index.d.ts +5 -2
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +8 -23
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/interceptors.d.ts.map +1 -1
- package/dist/procedures/interceptors.js +2 -1
- package/dist/procedures/interceptors.js.map +1 -1
- package/dist/procedures/invoke.d.ts +36 -3
- package/dist/procedures/invoke.d.ts.map +1 -1
- package/dist/procedures/invoke.js +78 -12
- package/dist/procedures/invoke.js.map +1 -1
- package/dist/procedures/module.d.ts +13 -8
- package/dist/procedures/module.d.ts.map +1 -1
- package/dist/procedures/module.js +19 -9
- package/dist/procedures/module.js.map +1 -1
- package/dist/procedures/types.d.ts +100 -2
- package/dist/procedures/types.d.ts.map +1 -1
- package/dist/procedures/types.js.map +1 -1
- package/dist/register.d.ts +8 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +9 -0
- package/dist/register.js.map +1 -0
- package/dist/server/host-policy.d.ts +24 -2
- package/dist/server/host-policy.d.ts.map +1 -1
- package/dist/server/host-policy.js +22 -0
- package/dist/server/host-policy.js.map +1 -1
- package/dist/server/procedure-server.d.ts +16 -2
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +26 -1
- package/dist/server/procedure-server.js.map +1 -1
- package/package.json +6 -4
- package/src/adapters/http/server/transport.ts +1 -0
- package/src/browser.ts +29 -0
- package/src/client/client.ts +33 -6
- package/src/client/types.ts +11 -0
- package/src/procedures/capability.ts +333 -0
- package/src/procedures/cli/discover.ts +3 -3
- package/src/procedures/cli/index.ts +5 -3
- package/src/procedures/cli/init.ts +1 -1
- package/src/procedures/collection/procedures.ts +12 -0
- package/src/procedures/core/array.ts +3 -1
- package/src/procedures/core/comparison.ts +3 -1
- package/src/procedures/core/index.ts +5 -2
- package/src/procedures/core/math.ts +3 -1
- package/src/procedures/core/meta.ts +11 -6
- package/src/procedures/core/object.ts +3 -1
- package/src/procedures/core/string.ts +3 -1
- package/src/procedures/core/type.ts +3 -1
- package/src/procedures/define-procedure.ts +5 -4
- package/src/procedures/effects.ts +24 -0
- package/src/procedures/index.ts +33 -22
- package/src/procedures/interceptors.ts +2 -1
- package/src/procedures/invoke.ts +112 -13
- package/src/procedures/module.ts +19 -9
- package/src/procedures/types.ts +113 -2
- package/src/register.ts +10 -0
- package/src/server/host-policy.ts +44 -2
- package/src/server/procedure-server.ts +44 -2
- package/dist/client/middleware/batching.d.ts +0 -102
- package/dist/client/middleware/batching.d.ts.map +0 -1
- package/dist/client/middleware/batching.js +0 -245
- package/dist/client/middleware/batching.js.map +0 -1
- package/dist/collections/async/async-queue.d.ts +0 -144
- package/dist/collections/async/async-queue.d.ts.map +0 -1
- package/dist/collections/async/async-queue.js +0 -347
- package/dist/collections/async/async-queue.js.map +0 -1
- package/dist/collections/async/channels.d.ts +0 -188
- package/dist/collections/async/channels.d.ts.map +0 -1
- package/dist/collections/async/channels.js +0 -312
- package/dist/collections/async/channels.js.map +0 -1
- package/dist/collections/behaviors/bounded.d.ts +0 -79
- package/dist/collections/behaviors/bounded.d.ts.map +0 -1
- package/dist/collections/behaviors/bounded.js +0 -384
- package/dist/collections/behaviors/bounded.js.map +0 -1
- package/dist/collections/behaviors/evented.d.ts +0 -154
- package/dist/collections/behaviors/evented.d.ts.map +0 -1
- package/dist/collections/behaviors/evented.js +0 -299
- package/dist/collections/behaviors/evented.js.map +0 -1
- package/dist/collections/behaviors/lru.d.ts +0 -84
- package/dist/collections/behaviors/lru.d.ts.map +0 -1
- package/dist/collections/behaviors/lru.js +0 -330
- package/dist/collections/behaviors/lru.js.map +0 -1
- package/dist/collections/behaviors/readonly.d.ts +0 -73
- package/dist/collections/behaviors/readonly.d.ts.map +0 -1
- package/dist/collections/behaviors/readonly.js +0 -158
- package/dist/collections/behaviors/readonly.js.map +0 -1
- package/dist/collections/behaviors/safe.d.ts +0 -163
- package/dist/collections/behaviors/safe.d.ts.map +0 -1
- package/dist/collections/behaviors/safe.js +0 -172
- package/dist/collections/behaviors/safe.js.map +0 -1
- package/dist/collections/behaviors/synchronized.d.ts +0 -88
- package/dist/collections/behaviors/synchronized.d.ts.map +0 -1
- package/dist/collections/behaviors/synchronized.js +0 -294
- package/dist/collections/behaviors/synchronized.js.map +0 -1
- package/dist/collections/behaviors/ttl.d.ts +0 -118
- package/dist/collections/behaviors/ttl.d.ts.map +0 -1
- package/dist/collections/behaviors/ttl.js +0 -338
- package/dist/collections/behaviors/ttl.js.map +0 -1
- package/dist/collections/core/effects.d.ts +0 -176
- package/dist/collections/core/effects.d.ts.map +0 -1
- package/dist/collections/core/effects.js +0 -180
- package/dist/collections/core/effects.js.map +0 -1
- package/dist/collections/core/events.d.ts +0 -192
- package/dist/collections/core/events.d.ts.map +0 -1
- package/dist/collections/core/events.js +0 -291
- package/dist/collections/core/events.js.map +0 -1
- package/dist/collections/core/middleware.d.ts +0 -231
- package/dist/collections/core/middleware.d.ts.map +0 -1
- package/dist/collections/core/middleware.js +0 -161
- package/dist/collections/core/middleware.js.map +0 -1
- package/dist/collections/core/policies.d.ts +0 -220
- package/dist/collections/core/policies.d.ts.map +0 -1
- package/dist/collections/core/policies.js +0 -48
- package/dist/collections/core/policies.js.map +0 -1
- package/dist/collections/core/traits.d.ts +0 -142
- package/dist/collections/core/traits.d.ts.map +0 -1
- package/dist/collections/core/traits.js +0 -8
- package/dist/collections/core/traits.js.map +0 -1
- package/dist/collections/examples.d.ts +0 -13
- package/dist/collections/examples.d.ts.map +0 -1
- package/dist/collections/examples.js +0 -302
- package/dist/collections/examples.js.map +0 -1
- package/dist/collections/fx/collectors.d.ts +0 -190
- package/dist/collections/fx/collectors.d.ts.map +0 -1
- package/dist/collections/fx/collectors.js +0 -369
- package/dist/collections/fx/collectors.js.map +0 -1
- package/dist/collections/fx/iter.d.ts +0 -166
- package/dist/collections/fx/iter.d.ts.map +0 -1
- package/dist/collections/fx/iter.js +0 -421
- package/dist/collections/fx/iter.js.map +0 -1
- package/dist/collections/impl/array-deque.d.ts +0 -107
- package/dist/collections/impl/array-deque.d.ts.map +0 -1
- package/dist/collections/impl/array-deque.js +0 -381
- package/dist/collections/impl/array-deque.js.map +0 -1
- package/dist/collections/impl/array-list.d.ts +0 -101
- package/dist/collections/impl/array-list.d.ts.map +0 -1
- package/dist/collections/impl/array-list.js +0 -387
- package/dist/collections/impl/array-list.js.map +0 -1
- package/dist/collections/impl/hash-map.d.ts +0 -141
- package/dist/collections/impl/hash-map.d.ts.map +0 -1
- package/dist/collections/impl/hash-map.js +0 -450
- package/dist/collections/impl/hash-map.js.map +0 -1
- package/dist/collections/impl/hash-set.d.ts +0 -125
- package/dist/collections/impl/hash-set.d.ts.map +0 -1
- package/dist/collections/impl/hash-set.js +0 -264
- package/dist/collections/impl/hash-set.js.map +0 -1
- package/dist/collections/impl/linked-hash-map.d.ts +0 -141
- package/dist/collections/impl/linked-hash-map.d.ts.map +0 -1
- package/dist/collections/impl/linked-hash-map.js +0 -472
- package/dist/collections/impl/linked-hash-map.js.map +0 -1
- package/dist/collections/impl/linked-list.d.ts +0 -109
- package/dist/collections/impl/linked-list.d.ts.map +0 -1
- package/dist/collections/impl/linked-list.js +0 -491
- package/dist/collections/impl/linked-list.js.map +0 -1
- package/dist/collections/impl/priority-queue.d.ts +0 -134
- package/dist/collections/impl/priority-queue.d.ts.map +0 -1
- package/dist/collections/impl/priority-queue.js +0 -336
- package/dist/collections/impl/priority-queue.js.map +0 -1
- package/dist/collections/impl/tree-map.d.ts +0 -146
- package/dist/collections/impl/tree-map.d.ts.map +0 -1
- package/dist/collections/impl/tree-map.js +0 -781
- package/dist/collections/impl/tree-map.js.map +0 -1
- package/dist/collections/impl/tree-set.d.ts +0 -112
- package/dist/collections/impl/tree-set.d.ts.map +0 -1
- package/dist/collections/impl/tree-set.js +0 -374
- package/dist/collections/impl/tree-set.js.map +0 -1
- package/dist/collections/index.d.ts +0 -105
- package/dist/collections/index.d.ts.map +0 -1
- package/dist/collections/index.js +0 -135
- package/dist/collections/index.js.map +0 -1
- package/dist/collections/interfaces/collection.d.ts +0 -119
- package/dist/collections/interfaces/collection.d.ts.map +0 -1
- package/dist/collections/interfaces/collection.js +0 -8
- package/dist/collections/interfaces/collection.js.map +0 -1
- package/dist/collections/interfaces/list.d.ts +0 -247
- package/dist/collections/interfaces/list.d.ts.map +0 -1
- package/dist/collections/interfaces/list.js +0 -8
- package/dist/collections/interfaces/list.js.map +0 -1
- package/dist/collections/interfaces/map.d.ts +0 -344
- package/dist/collections/interfaces/map.d.ts.map +0 -1
- package/dist/collections/interfaces/map.js +0 -8
- package/dist/collections/interfaces/map.js.map +0 -1
- package/dist/collections/interfaces/queue.d.ts +0 -304
- package/dist/collections/interfaces/queue.d.ts.map +0 -1
- package/dist/collections/interfaces/queue.js +0 -8
- package/dist/collections/interfaces/queue.js.map +0 -1
- package/dist/collections/interfaces/set.d.ts +0 -137
- package/dist/collections/interfaces/set.d.ts.map +0 -1
- package/dist/collections/interfaces/set.js +0 -8
- package/dist/collections/interfaces/set.js.map +0 -1
- package/dist/collections/storage/api.d.ts +0 -109
- package/dist/collections/storage/api.d.ts.map +0 -1
- package/dist/collections/storage/api.js +0 -182
- package/dist/collections/storage/api.js.map +0 -1
- package/dist/collections/storage/hybrid.d.ts +0 -164
- package/dist/collections/storage/hybrid.d.ts.map +0 -1
- package/dist/collections/storage/hybrid.js +0 -416
- package/dist/collections/storage/hybrid.js.map +0 -1
- package/dist/collections/storage/index.d.ts +0 -16
- package/dist/collections/storage/index.d.ts.map +0 -1
- package/dist/collections/storage/index.js +0 -13
- package/dist/collections/storage/index.js.map +0 -1
- package/dist/collections/storage/interface.d.ts +0 -141
- package/dist/collections/storage/interface.d.ts.map +0 -1
- package/dist/collections/storage/interface.js +0 -23
- package/dist/collections/storage/interface.js.map +0 -1
- package/dist/collections/storage/memory.d.ts +0 -68
- package/dist/collections/storage/memory.d.ts.map +0 -1
- package/dist/collections/storage/memory.js +0 -154
- package/dist/collections/storage/memory.js.map +0 -1
- package/dist/collections/utils/defaults.d.ts +0 -135
- package/dist/collections/utils/defaults.d.ts.map +0 -1
- package/dist/collections/utils/defaults.js +0 -322
- package/dist/collections/utils/defaults.js.map +0 -1
- package/dist/collections/utils/factories.d.ts +0 -144
- package/dist/collections/utils/factories.d.ts.map +0 -1
- package/dist/collections/utils/factories.js +0 -293
- package/dist/collections/utils/factories.js.map +0 -1
- package/dist/collections/utils/helpers.d.ts +0 -137
- package/dist/collections/utils/helpers.d.ts.map +0 -1
- package/dist/collections/utils/helpers.js +0 -221
- package/dist/collections/utils/helpers.js.map +0 -1
- package/dist/collections.d.ts +0 -12
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -10
- package/dist/collections.js.map +0 -1
- package/dist/components/define.d.ts +0 -134
- package/dist/components/define.d.ts.map +0 -1
- package/dist/components/define.js +0 -486
- package/dist/components/define.js.map +0 -1
- package/dist/components/index.d.ts +0 -39
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -38
- package/dist/components/index.js.map +0 -1
- package/dist/components/types.d.ts +0 -264
- package/dist/components/types.d.ts.map +0 -1
- package/dist/components/types.js +0 -46
- package/dist/components/types.js.map +0 -1
- package/dist/procedures/storage/adapter.d.ts +0 -148
- package/dist/procedures/storage/adapter.d.ts.map +0 -1
- package/dist/procedures/storage/adapter.js +0 -214
- package/dist/procedures/storage/adapter.js.map +0 -1
- package/dist/procedures/storage/api.d.ts +0 -125
- package/dist/procedures/storage/api.d.ts.map +0 -1
- package/dist/procedures/storage/api.js +0 -220
- package/dist/procedures/storage/api.js.map +0 -1
- package/dist/procedures/storage/factory.d.ts +0 -134
- package/dist/procedures/storage/factory.d.ts.map +0 -1
- package/dist/procedures/storage/factory.js +0 -166
- package/dist/procedures/storage/factory.js.map +0 -1
- package/dist/procedures/storage/hybrid.d.ts +0 -193
- package/dist/procedures/storage/hybrid.d.ts.map +0 -1
- package/dist/procedures/storage/hybrid.js +0 -519
- package/dist/procedures/storage/hybrid.js.map +0 -1
- package/dist/procedures/storage/index.d.ts +0 -17
- package/dist/procedures/storage/index.d.ts.map +0 -1
- package/dist/procedures/storage/index.js +0 -17
- package/dist/procedures/storage/index.js.map +0 -1
- package/dist/procedures/storage/procedures.d.ts +0 -39
- package/dist/procedures/storage/procedures.d.ts.map +0 -1
- package/dist/procedures/storage/procedures.js +0 -261
- package/dist/procedures/storage/procedures.js.map +0 -1
- package/dist/procedures/storage/serialization.d.ts +0 -123
- package/dist/procedures/storage/serialization.d.ts.map +0 -1
- package/dist/procedures/storage/serialization.js +0 -216
- package/dist/procedures/storage/serialization.js.map +0 -1
- package/dist/procedures/storage/synced-registry.d.ts +0 -246
- package/dist/procedures/storage/synced-registry.d.ts.map +0 -1
- package/dist/procedures/storage/synced-registry.js +0 -575
- package/dist/procedures/storage/synced-registry.js.map +0 -1
- package/dist/procedures/storage/types.d.ts +0 -130
- package/dist/procedures/storage/types.d.ts.map +0 -1
- package/dist/procedures/storage/types.js +0 -8
- package/dist/procedures/storage/types.js.map +0 -1
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Go-style channels for CSP (Communicating Sequential Processes).
|
|
3
|
-
*
|
|
4
|
-
* Provides typed, bidirectional communication channels inspired by Go.
|
|
5
|
-
* Perfect for coordinating async operations and implementing concurrent patterns.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const ch = channel<number>()
|
|
9
|
-
*
|
|
10
|
-
* // Sender
|
|
11
|
-
* await ch.send(42)
|
|
12
|
-
*
|
|
13
|
-
* // Receiver
|
|
14
|
-
* const value = await ch.receive()
|
|
15
|
-
*
|
|
16
|
-
* // Select from multiple channels
|
|
17
|
-
* const result = await select(
|
|
18
|
-
* ch1.case((v) => console.log('ch1:', v)),
|
|
19
|
-
* ch2.case((v) => console.log('ch2:', v))
|
|
20
|
-
* )
|
|
21
|
-
*/
|
|
22
|
-
import { asyncQueue } from "./async-queue.js";
|
|
23
|
-
/**
|
|
24
|
-
* Channel<T> - Bidirectional communication channel.
|
|
25
|
-
*
|
|
26
|
-
* Inspired by Go channels. Provides send/receive operations
|
|
27
|
-
* that can block until the other side is ready.
|
|
28
|
-
*/
|
|
29
|
-
export class Channel {
|
|
30
|
-
queue;
|
|
31
|
-
_isClosed = false;
|
|
32
|
-
constructor(bufferSize = 0) {
|
|
33
|
-
this.queue = asyncQueue({ capacity: bufferSize || 1 });
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Sends a value through the channel.
|
|
37
|
-
* Blocks if channel buffer is full.
|
|
38
|
-
*
|
|
39
|
-
* @throws Error if channel is closed
|
|
40
|
-
*/
|
|
41
|
-
async send(value) {
|
|
42
|
-
if (this._isClosed) {
|
|
43
|
-
throw new Error("Cannot send on closed channel");
|
|
44
|
-
}
|
|
45
|
-
await this.queue.put(value);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Receives a value from the channel.
|
|
49
|
-
* Blocks if no value is available.
|
|
50
|
-
*
|
|
51
|
-
* @throws Error if channel is closed and empty
|
|
52
|
-
*/
|
|
53
|
-
async receive() {
|
|
54
|
-
return await this.queue.take();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Attempts to send without blocking.
|
|
58
|
-
* Returns false if channel is full.
|
|
59
|
-
*/
|
|
60
|
-
trySend(value) {
|
|
61
|
-
if (this._isClosed)
|
|
62
|
-
return false;
|
|
63
|
-
return this.queue.tryPut(value);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Attempts to receive without blocking.
|
|
67
|
-
* Returns undefined if no value is available.
|
|
68
|
-
*/
|
|
69
|
-
tryReceive() {
|
|
70
|
-
return this.queue.tryTake();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Closes the channel. No more values can be sent.
|
|
74
|
-
* Receivers can still drain remaining values.
|
|
75
|
-
*/
|
|
76
|
-
close() {
|
|
77
|
-
this._isClosed = true;
|
|
78
|
-
this.queue.close();
|
|
79
|
-
}
|
|
80
|
-
get isClosed() {
|
|
81
|
-
return this._isClosed;
|
|
82
|
-
}
|
|
83
|
-
get size() {
|
|
84
|
-
return this.queue.size;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Creates a select case for this channel.
|
|
88
|
-
* Used with the select() function for multiplexing.
|
|
89
|
-
*/
|
|
90
|
-
case(handler) {
|
|
91
|
-
return {
|
|
92
|
-
channel: this,
|
|
93
|
-
handler,
|
|
94
|
-
tryReceive: () => this.tryReceive(),
|
|
95
|
-
receive: () => this.receive(),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Async iteration over channel values.
|
|
100
|
-
* Stops when channel is closed and empty.
|
|
101
|
-
*/
|
|
102
|
-
async *[Symbol.asyncIterator]() {
|
|
103
|
-
while (true) {
|
|
104
|
-
try {
|
|
105
|
-
yield await this.receive();
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
// Channel closed
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Selects from multiple channels (like Go's select statement).
|
|
116
|
-
*
|
|
117
|
-
* Waits for the first channel to have a value available,
|
|
118
|
-
* then calls its handler and returns the result.
|
|
119
|
-
*
|
|
120
|
-
* @example
|
|
121
|
-
* const result = await select(
|
|
122
|
-
* ch1.case((v) => `ch1: ${v}`),
|
|
123
|
-
* ch2.case((v) => `ch2: ${v}`),
|
|
124
|
-
* timeout(1000).case(() => 'timeout')
|
|
125
|
-
* )
|
|
126
|
-
*/
|
|
127
|
-
export async function select(...cases) {
|
|
128
|
-
// First, try non-blocking receive on all channels
|
|
129
|
-
for (const c of cases) {
|
|
130
|
-
const value = c.tryReceive();
|
|
131
|
-
if (value !== undefined) {
|
|
132
|
-
return c.handler(value);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// If no immediate value, race all receive operations
|
|
136
|
-
const promises = cases.map((c, index) => c.receive().then((value) => ({ index, value })));
|
|
137
|
-
const { index, value } = await Promise.race(promises);
|
|
138
|
-
return cases[index].handler(value);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Creates a timeout channel that sends after the specified duration.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* const result = await select(
|
|
145
|
-
* dataChannel.case((v) => v),
|
|
146
|
-
* timeout(5000).case(() => 'timeout!')
|
|
147
|
-
* )
|
|
148
|
-
*/
|
|
149
|
-
export function timeout(ms) {
|
|
150
|
-
const ch = new Channel();
|
|
151
|
-
setTimeout(() => {
|
|
152
|
-
ch.send(undefined).catch(() => { }); // Ignore if closed
|
|
153
|
-
ch.close();
|
|
154
|
-
}, ms);
|
|
155
|
-
return ch;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Creates a ticker channel that sends at regular intervals.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const tick = ticker(1000) // Every second
|
|
162
|
-
* for await (const t of tick) {
|
|
163
|
-
* console.log('Tick:', t)
|
|
164
|
-
* }
|
|
165
|
-
*/
|
|
166
|
-
export function ticker(ms) {
|
|
167
|
-
const ch = new Channel(1);
|
|
168
|
-
let count = 0;
|
|
169
|
-
const intervalId = setInterval(() => {
|
|
170
|
-
ch.trySend(count++);
|
|
171
|
-
}, ms);
|
|
172
|
-
return Object.assign(ch, {
|
|
173
|
-
stop: () => {
|
|
174
|
-
clearInterval(intervalId);
|
|
175
|
-
ch.close();
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Pipeline: pipes values from input channel through transform to output channel.
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* const input = channel<number>()
|
|
184
|
-
* const output = pipeline(input, (x) => x * 2)
|
|
185
|
-
*
|
|
186
|
-
* await input.send(5)
|
|
187
|
-
* const result = await output.receive() // 10
|
|
188
|
-
*/
|
|
189
|
-
export function pipeline(input, transform, bufferSize = 0) {
|
|
190
|
-
const output = new Channel(bufferSize);
|
|
191
|
-
(async () => {
|
|
192
|
-
for await (const value of input) {
|
|
193
|
-
const transformed = await transform(value);
|
|
194
|
-
await output.send(transformed);
|
|
195
|
-
}
|
|
196
|
-
output.close();
|
|
197
|
-
})();
|
|
198
|
-
return output;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Fan-out: distributes values from one input channel to multiple output channels.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* const input = channel<number>()
|
|
205
|
-
* const [out1, out2, out3] = fanOut(input, 3)
|
|
206
|
-
*
|
|
207
|
-
* // Each output gets a copy of every input value
|
|
208
|
-
*/
|
|
209
|
-
export function fanOut(input, count, bufferSize = 0) {
|
|
210
|
-
const outputs = Array.from({ length: count }, () => new Channel(bufferSize));
|
|
211
|
-
(async () => {
|
|
212
|
-
for await (const value of input) {
|
|
213
|
-
await Promise.all(outputs.map((ch) => ch.send(value)));
|
|
214
|
-
}
|
|
215
|
-
outputs.forEach((ch) => ch.close());
|
|
216
|
-
})();
|
|
217
|
-
return outputs;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Fan-in: merges multiple input channels into one output channel.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* const ch1 = channel<number>()
|
|
224
|
-
* const ch2 = channel<number>()
|
|
225
|
-
* const merged = fanIn(ch1, ch2)
|
|
226
|
-
*
|
|
227
|
-
* // merged receives values from both ch1 and ch2
|
|
228
|
-
*/
|
|
229
|
-
export function fanIn(...inputs) {
|
|
230
|
-
const output = new Channel();
|
|
231
|
-
const workers = inputs.map(async (input) => {
|
|
232
|
-
for await (const value of input) {
|
|
233
|
-
await output.send(value);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
Promise.all(workers).then(() => output.close());
|
|
237
|
-
return output;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Merge: like fanIn but closes output when first input closes.
|
|
241
|
-
*/
|
|
242
|
-
export function merge(...inputs) {
|
|
243
|
-
const output = new Channel();
|
|
244
|
-
(async () => {
|
|
245
|
-
const iterators = inputs.map((ch) => ch[Symbol.asyncIterator]());
|
|
246
|
-
while (true) {
|
|
247
|
-
const results = await Promise.race(iterators.map(async (it, idx) => {
|
|
248
|
-
const result = await it.next();
|
|
249
|
-
return { idx, result };
|
|
250
|
-
}));
|
|
251
|
-
if (results.result.done) {
|
|
252
|
-
output.close();
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
await output.send(results.result.value);
|
|
256
|
-
}
|
|
257
|
-
})();
|
|
258
|
-
return output;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Buffered channel with specified capacity.
|
|
262
|
-
*/
|
|
263
|
-
export function buffered(capacity) {
|
|
264
|
-
return new Channel(capacity);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Unbuffered channel (rendezvous point).
|
|
268
|
-
* Sends block until receiver is ready.
|
|
269
|
-
*/
|
|
270
|
-
export function unbuffered() {
|
|
271
|
-
return new Channel(0);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Factory function to create a channel.
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* const ch = channel<number>()
|
|
278
|
-
* const bufferedCh = channel<string>(10)
|
|
279
|
-
*/
|
|
280
|
-
export function channel(bufferSize = 0) {
|
|
281
|
-
return new Channel(bufferSize);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* WorkerPool: distributes work across multiple workers.
|
|
285
|
-
*
|
|
286
|
-
* @example
|
|
287
|
-
* const pool = workerPool(
|
|
288
|
-
* jobChannel,
|
|
289
|
-
* async (job) => await processJob(job),
|
|
290
|
-
* { workers: 4 }
|
|
291
|
-
* )
|
|
292
|
-
*
|
|
293
|
-
* // 4 workers concurrently process jobs from jobChannel
|
|
294
|
-
*/
|
|
295
|
-
export function workerPool(jobs, worker, options = { workers: 1 }) {
|
|
296
|
-
const results = new Channel(options.bufferSize || 0);
|
|
297
|
-
const { workers: workerCount } = options;
|
|
298
|
-
const workers = Array.from({ length: workerCount }, async () => {
|
|
299
|
-
for await (const job of jobs) {
|
|
300
|
-
try {
|
|
301
|
-
const result = await worker(job);
|
|
302
|
-
await results.send(result);
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
console.error("Worker error:", error);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
Promise.all(workers).then(() => results.close());
|
|
310
|
-
return results;
|
|
311
|
-
}
|
|
312
|
-
//# sourceMappingURL=channels.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"channels.js","sourceRoot":"","sources":["../../../src/collections/async/channels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IACV,KAAK,CAAgB;IACrB,SAAS,GAAG,KAAK,CAAC;IAE1B,YAAY,aAAqB,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAI,EAAE,Q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I,IAAI,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC;gBACjC,MAAM,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IAEjD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bounded behavior - Enforces capacity limits on collections.
|
|
3
|
-
*
|
|
4
|
-
* Wraps collections to prevent them from exceeding a maximum size.
|
|
5
|
-
* Provides various overflow policies to handle full collections.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const list = compose(
|
|
9
|
-
* boundedList({ capacity: 100, policy: 'drop-oldest' })
|
|
10
|
-
* )(arrayList<number>())
|
|
11
|
-
*
|
|
12
|
-
* // Add 101 elements - first element will be dropped
|
|
13
|
-
* for (let i = 0; i < 101; i++) {
|
|
14
|
-
* list.add(i)
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
import type { Middleware } from "../core/middleware.js";
|
|
18
|
-
import type { List } from "../interfaces/list.js";
|
|
19
|
-
import type { Queue, Deque } from "../interfaces/queue.js";
|
|
20
|
-
import type { MapLike } from "../interfaces/map.js";
|
|
21
|
-
import type { Collection } from "../interfaces/collection.js";
|
|
22
|
-
import type { OverflowPolicy, OverflowHandler, OverflowContext } from "../core/policies.js";
|
|
23
|
-
/**
|
|
24
|
-
* Options for bounded behavior.
|
|
25
|
-
*/
|
|
26
|
-
export interface BoundedOptions<T> {
|
|
27
|
-
/**
|
|
28
|
-
* Maximum number of elements the collection can hold.
|
|
29
|
-
*/
|
|
30
|
-
capacity: number;
|
|
31
|
-
/**
|
|
32
|
-
* Policy for handling overflow when collection is full.
|
|
33
|
-
* @default 'throw'
|
|
34
|
-
*/
|
|
35
|
-
policy?: OverflowPolicy;
|
|
36
|
-
/**
|
|
37
|
-
* Optional callback invoked when overflow occurs.
|
|
38
|
-
* Called before the policy is applied.
|
|
39
|
-
*/
|
|
40
|
-
onOverflow?: OverflowHandler<T>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Marker interface for bounded collections.
|
|
44
|
-
*/
|
|
45
|
-
export interface BoundedCollection {
|
|
46
|
-
readonly capacity: number;
|
|
47
|
-
readonly isFull: boolean;
|
|
48
|
-
readonly remainingCapacity: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Creates a bounded List middleware.
|
|
52
|
-
*
|
|
53
|
-
* Intercepts add operations to enforce capacity limits.
|
|
54
|
-
* Supports multiple overflow policies.
|
|
55
|
-
*/
|
|
56
|
-
export declare function boundedList<T>(options: BoundedOptions<T>): Middleware<List<T>, List<T> & BoundedCollection>;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a bounded Queue middleware.
|
|
59
|
-
*/
|
|
60
|
-
export declare function boundedQueue<T>(options: BoundedOptions<T>): Middleware<Queue<T>, Queue<T> & BoundedCollection>;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a bounded Deque middleware.
|
|
63
|
-
*/
|
|
64
|
-
export declare function boundedDeque<T>(options: BoundedOptions<T>): Middleware<Deque<T>, Deque<T> & BoundedCollection>;
|
|
65
|
-
/**
|
|
66
|
-
* Creates a bounded Map middleware.
|
|
67
|
-
*/
|
|
68
|
-
export declare function boundedMap<K, V>(options: Omit<BoundedOptions<V>, "onOverflow"> & {
|
|
69
|
-
onOverflow?: (context: Omit<OverflowContext<V>, "newElement"> & {
|
|
70
|
-
key: K;
|
|
71
|
-
value: V;
|
|
72
|
-
}) => void;
|
|
73
|
-
}): Middleware<MapLike<K, V>, MapLike<K, V> & BoundedCollection>;
|
|
74
|
-
/**
|
|
75
|
-
* Generic bounded collection middleware.
|
|
76
|
-
* Works with any collection type.
|
|
77
|
-
*/
|
|
78
|
-
export declare function bounded<C extends Collection<any>>(options: BoundedOptions<any>): Middleware<C, C & BoundedCollection>;
|
|
79
|
-
//# sourceMappingURL=bounded.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bounded.d.ts","sourceRoot":"","sources":["../../../src/collections/behaviors/bounded.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IAExB;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,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