effect 4.0.0-beta.17 → 4.0.0-beta.19
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/dist/Array.d.ts +127 -299
- package/dist/Array.d.ts.map +1 -1
- package/dist/Array.js +102 -62
- package/dist/Array.js.map +1 -1
- package/dist/Cache.d.ts.map +1 -1
- package/dist/Cache.js +5 -4
- package/dist/Cache.js.map +1 -1
- package/dist/Channel.d.ts +97 -11
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js +72 -29
- package/dist/Channel.js.map +1 -1
- package/dist/Chunk.d.ts +54 -247
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Chunk.js +36 -67
- package/dist/Chunk.js.map +1 -1
- package/dist/Effect.d.ts +337 -437
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +118 -134
- package/dist/Effect.js.map +1 -1
- package/dist/Filter.d.ts +0 -33
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +0 -13
- package/dist/Filter.js.map +1 -1
- package/dist/HashMap.d.ts +15 -14
- package/dist/HashMap.d.ts.map +1 -1
- package/dist/HashMap.js +4 -4
- package/dist/HashMap.js.map +1 -1
- package/dist/Iterable.d.ts +40 -39
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +94 -22
- package/dist/Iterable.js.map +1 -1
- package/dist/Option.d.ts +22 -15
- package/dist/Option.d.ts.map +1 -1
- package/dist/Option.js +14 -7
- package/dist/Option.js.map +1 -1
- package/dist/Pull.d.ts.map +1 -1
- package/dist/Pull.js +1 -1
- package/dist/Pull.js.map +1 -1
- package/dist/Record.d.ts +24 -120
- package/dist/Record.d.ts.map +1 -1
- package/dist/Record.js +21 -41
- package/dist/Record.js.map +1 -1
- package/dist/Sink.d.ts +11 -11
- package/dist/Sink.d.ts.map +1 -1
- package/dist/Sink.js +53 -6
- package/dist/Sink.js.map +1 -1
- package/dist/Stream.d.ts +198 -386
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +103 -59
- package/dist/Stream.js.map +1 -1
- package/dist/Trie.d.ts +18 -17
- package/dist/Trie.d.ts.map +1 -1
- package/dist/Trie.js +5 -5
- package/dist/Trie.js.map +1 -1
- package/dist/TxChunk.d.ts +37 -37
- package/dist/TxChunk.d.ts.map +1 -1
- package/dist/TxChunk.js +3 -3
- package/dist/TxChunk.js.map +1 -1
- package/dist/TxDeferred.d.ts +328 -0
- package/dist/TxDeferred.d.ts.map +1 -0
- package/dist/TxDeferred.js +196 -0
- package/dist/TxDeferred.js.map +1 -0
- package/dist/TxHashMap.d.ts +84 -83
- package/dist/TxHashMap.d.ts.map +1 -1
- package/dist/TxHashMap.js +24 -24
- package/dist/TxHashMap.js.map +1 -1
- package/dist/TxHashSet.d.ts +35 -35
- package/dist/TxHashSet.d.ts.map +1 -1
- package/dist/TxHashSet.js +14 -14
- package/dist/TxHashSet.js.map +1 -1
- package/dist/TxPriorityQueue.d.ts +609 -0
- package/dist/TxPriorityQueue.d.ts.map +1 -0
- package/dist/TxPriorityQueue.js +415 -0
- package/dist/TxPriorityQueue.js.map +1 -0
- package/dist/TxPubSub.d.ts +585 -0
- package/dist/TxPubSub.d.ts.map +1 -0
- package/dist/TxPubSub.js +521 -0
- package/dist/TxPubSub.js.map +1 -0
- package/dist/TxQueue.d.ts +32 -32
- package/dist/TxQueue.d.ts.map +1 -1
- package/dist/TxQueue.js +26 -26
- package/dist/TxQueue.js.map +1 -1
- package/dist/TxReentrantLock.d.ts +523 -0
- package/dist/TxReentrantLock.d.ts.map +1 -0
- package/dist/TxReentrantLock.js +504 -0
- package/dist/TxReentrantLock.js.map +1 -0
- package/dist/TxRef.d.ts +34 -34
- package/dist/TxRef.d.ts.map +1 -1
- package/dist/TxRef.js +21 -14
- package/dist/TxRef.js.map +1 -1
- package/dist/TxSemaphore.d.ts +8 -8
- package/dist/TxSemaphore.d.ts.map +1 -1
- package/dist/TxSemaphore.js +7 -7
- package/dist/TxSemaphore.js.map +1 -1
- package/dist/TxSubscriptionRef.d.ts +508 -0
- package/dist/TxSubscriptionRef.d.ts.map +1 -0
- package/dist/TxSubscriptionRef.js +293 -0
- package/dist/TxSubscriptionRef.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +99 -42
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/hashMap.js +3 -2
- package/dist/internal/hashMap.js.map +1 -1
- package/dist/internal/trie.js +5 -4
- package/dist/internal/trie.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +0 -9
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +1 -1
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +1 -1
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cluster/K8sHttpClient.js +4 -4
- package/dist/unstable/cluster/K8sHttpClient.js.map +1 -1
- package/dist/unstable/cluster/Sharding.js +1 -1
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/encoding/Sse.js +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +1 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/socket/Socket.d.ts.map +1 -1
- package/dist/unstable/socket/Socket.js +3 -3
- package/dist/unstable/socket/Socket.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +190 -342
- package/src/Cache.ts +6 -5
- package/src/Channel.ts +506 -102
- package/src/Chunk.ts +81 -268
- package/src/Effect.ts +437 -518
- package/src/Filter.ts +0 -57
- package/src/HashMap.ts +15 -14
- package/src/Iterable.ts +105 -50
- package/src/Option.ts +30 -20
- package/src/Pull.ts +1 -1
- package/src/Record.ts +43 -152
- package/src/Sink.ts +75 -23
- package/src/Stream.ts +442 -502
- package/src/Trie.ts +18 -17
- package/src/TxChunk.ts +72 -53
- package/src/TxDeferred.ts +394 -0
- package/src/TxHashMap.ts +332 -285
- package/src/TxHashSet.ts +111 -116
- package/src/TxPriorityQueue.ts +767 -0
- package/src/TxPubSub.ts +789 -0
- package/src/TxQueue.ts +241 -251
- package/src/TxReentrantLock.ts +753 -0
- package/src/TxRef.ts +50 -38
- package/src/TxSemaphore.ts +29 -32
- package/src/TxSubscriptionRef.ts +639 -0
- package/src/index.ts +45 -0
- package/src/internal/effect.ts +368 -163
- package/src/internal/hashMap.ts +7 -5
- package/src/internal/trie.ts +16 -9
- package/src/unstable/ai/Tool.ts +0 -9
- package/src/unstable/cli/Command.ts +6 -4
- package/src/unstable/cluster/K8sHttpClient.ts +4 -4
- package/src/unstable/cluster/Sharding.ts +1 -1
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/rpc/RpcServer.ts +1 -7
- package/src/unstable/socket/Socket.ts +9 -11
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A transactional deferred value — a write-once cell that can be read within transactions.
|
|
3
|
+
* Readers retry until a value is set; once set, the value is immutable.
|
|
4
|
+
*
|
|
5
|
+
* @since 4.0.0
|
|
6
|
+
*/
|
|
7
|
+
import * as Effect from "./Effect.ts";
|
|
8
|
+
import type { Inspectable } from "./Inspectable.ts";
|
|
9
|
+
import type { Option } from "./Option.ts";
|
|
10
|
+
import type { Pipeable } from "./Pipeable.ts";
|
|
11
|
+
import type { Result } from "./Result.ts";
|
|
12
|
+
import * as TxRef from "./TxRef.ts";
|
|
13
|
+
declare const TypeId = "~effect/transactions/TxDeferred";
|
|
14
|
+
/**
|
|
15
|
+
* A transactional deferred — a write-once cell readable within transactions.
|
|
16
|
+
*
|
|
17
|
+
* Readers block (retry the transaction) until a value is committed.
|
|
18
|
+
* Writers succeed only on the first call; subsequent writes return `false`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { Effect, TxDeferred } from "effect"
|
|
23
|
+
*
|
|
24
|
+
* const program = Effect.gen(function*() {
|
|
25
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
26
|
+
*
|
|
27
|
+
* // Complete the deferred
|
|
28
|
+
* const first = yield* TxDeferred.succeed(deferred, 42)
|
|
29
|
+
* console.log(first) // true
|
|
30
|
+
*
|
|
31
|
+
* // Second write is a no-op
|
|
32
|
+
* const second = yield* TxDeferred.succeed(deferred, 99)
|
|
33
|
+
* console.log(second) // false
|
|
34
|
+
*
|
|
35
|
+
* // Read the value
|
|
36
|
+
* const value = yield* TxDeferred.await(deferred)
|
|
37
|
+
* console.log(value) // 42
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @since 4.0.0
|
|
42
|
+
* @category models
|
|
43
|
+
*/
|
|
44
|
+
export interface TxDeferred<in out A, in out E = never> extends Inspectable, Pipeable {
|
|
45
|
+
readonly [TypeId]: typeof TypeId;
|
|
46
|
+
readonly ref: TxRef.TxRef<Option<Result<A, E>>>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new empty `TxDeferred`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { Effect, Option, TxDeferred } from "effect"
|
|
54
|
+
*
|
|
55
|
+
* const program = Effect.gen(function*() {
|
|
56
|
+
* const deferred = yield* TxDeferred.make<string, Error>()
|
|
57
|
+
* const state = yield* TxDeferred.poll(deferred)
|
|
58
|
+
* console.log(Option.isNone(state)) // true
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @since 4.0.0
|
|
63
|
+
* @category constructors
|
|
64
|
+
*/
|
|
65
|
+
export declare const make: <A, E = never>() => Effect.Effect<TxDeferred<A, E>, never, Effect.Transaction>;
|
|
66
|
+
/**
|
|
67
|
+
* Reads the deferred value. Retries the transaction if the deferred has not
|
|
68
|
+
* been completed yet.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { Effect, TxDeferred } from "effect"
|
|
73
|
+
*
|
|
74
|
+
* const program = Effect.gen(function*() {
|
|
75
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
76
|
+
* yield* TxDeferred.succeed(deferred, 42)
|
|
77
|
+
* const value = yield* TxDeferred.await(deferred)
|
|
78
|
+
* console.log(value) // 42
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
* @category getters
|
|
84
|
+
*/
|
|
85
|
+
declare const await_: <A, E>(self: TxDeferred<A, E>) => Effect.Effect<A, E, Effect.Transaction>;
|
|
86
|
+
export {
|
|
87
|
+
/**
|
|
88
|
+
* Reads the deferred value. Retries the transaction if the deferred has not
|
|
89
|
+
* been completed yet.
|
|
90
|
+
*
|
|
91
|
+
* @since 4.0.0
|
|
92
|
+
* @category getters
|
|
93
|
+
*/
|
|
94
|
+
await_ as await };
|
|
95
|
+
/**
|
|
96
|
+
* Reads the current state of the deferred without retrying. Returns `None` if
|
|
97
|
+
* not yet completed.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Effect, Option, Result, TxDeferred } from "effect"
|
|
102
|
+
*
|
|
103
|
+
* const program = Effect.gen(function*() {
|
|
104
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
105
|
+
* const before = yield* TxDeferred.poll(deferred)
|
|
106
|
+
* console.log(Option.isNone(before)) // true
|
|
107
|
+
*
|
|
108
|
+
* yield* TxDeferred.succeed(deferred, 42)
|
|
109
|
+
* const after = yield* TxDeferred.poll(deferred)
|
|
110
|
+
* console.log(after) // Some(Success(42))
|
|
111
|
+
* })
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @since 4.0.0
|
|
115
|
+
* @category getters
|
|
116
|
+
*/
|
|
117
|
+
export declare const poll: <A, E>(self: TxDeferred<A, E>) => Effect.Effect<Option<Result<A, E>>, never, Effect.Transaction>;
|
|
118
|
+
/**
|
|
119
|
+
* Completes the deferred with a `Result`. Returns `true` if this was the first
|
|
120
|
+
* completion, `false` if already completed.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { Effect, Result, TxDeferred } from "effect"
|
|
125
|
+
*
|
|
126
|
+
* const program = Effect.gen(function*() {
|
|
127
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
128
|
+
* const first = yield* TxDeferred.done(deferred, Result.succeed(42))
|
|
129
|
+
* console.log(first) // true
|
|
130
|
+
* const second = yield* TxDeferred.done(deferred, Result.succeed(99))
|
|
131
|
+
* console.log(second) // false
|
|
132
|
+
* })
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @since 4.0.0
|
|
136
|
+
* @category mutations
|
|
137
|
+
*/
|
|
138
|
+
export declare const done: {
|
|
139
|
+
/**
|
|
140
|
+
* Completes the deferred with a `Result`. Returns `true` if this was the first
|
|
141
|
+
* completion, `false` if already completed.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { Effect, Result, TxDeferred } from "effect"
|
|
146
|
+
*
|
|
147
|
+
* const program = Effect.gen(function*() {
|
|
148
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
149
|
+
* const first = yield* TxDeferred.done(deferred, Result.succeed(42))
|
|
150
|
+
* console.log(first) // true
|
|
151
|
+
* const second = yield* TxDeferred.done(deferred, Result.succeed(99))
|
|
152
|
+
* console.log(second) // false
|
|
153
|
+
* })
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @since 4.0.0
|
|
157
|
+
* @category mutations
|
|
158
|
+
*/
|
|
159
|
+
<A, E>(result: Result<A, E>): (self: TxDeferred<A, E>) => Effect.Effect<boolean, never, Effect.Transaction>;
|
|
160
|
+
/**
|
|
161
|
+
* Completes the deferred with a `Result`. Returns `true` if this was the first
|
|
162
|
+
* completion, `false` if already completed.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { Effect, Result, TxDeferred } from "effect"
|
|
167
|
+
*
|
|
168
|
+
* const program = Effect.gen(function*() {
|
|
169
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
170
|
+
* const first = yield* TxDeferred.done(deferred, Result.succeed(42))
|
|
171
|
+
* console.log(first) // true
|
|
172
|
+
* const second = yield* TxDeferred.done(deferred, Result.succeed(99))
|
|
173
|
+
* console.log(second) // false
|
|
174
|
+
* })
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @since 4.0.0
|
|
178
|
+
* @category mutations
|
|
179
|
+
*/
|
|
180
|
+
<A, E>(self: TxDeferred<A, E>, result: Result<A, E>): Effect.Effect<boolean, never, Effect.Transaction>;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Completes the deferred with a success value. Returns `true` if this was the
|
|
184
|
+
* first completion, `false` if already completed.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { Effect, TxDeferred } from "effect"
|
|
189
|
+
*
|
|
190
|
+
* const program = Effect.gen(function*() {
|
|
191
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
192
|
+
* const first = yield* TxDeferred.succeed(deferred, 42)
|
|
193
|
+
* console.log(first) // true
|
|
194
|
+
* const second = yield* TxDeferred.succeed(deferred, 99)
|
|
195
|
+
* console.log(second) // false
|
|
196
|
+
* })
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @since 4.0.0
|
|
200
|
+
* @category mutations
|
|
201
|
+
*/
|
|
202
|
+
export declare const succeed: {
|
|
203
|
+
/**
|
|
204
|
+
* Completes the deferred with a success value. Returns `true` if this was the
|
|
205
|
+
* first completion, `false` if already completed.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { Effect, TxDeferred } from "effect"
|
|
210
|
+
*
|
|
211
|
+
* const program = Effect.gen(function*() {
|
|
212
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
213
|
+
* const first = yield* TxDeferred.succeed(deferred, 42)
|
|
214
|
+
* console.log(first) // true
|
|
215
|
+
* const second = yield* TxDeferred.succeed(deferred, 99)
|
|
216
|
+
* console.log(second) // false
|
|
217
|
+
* })
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @since 4.0.0
|
|
221
|
+
* @category mutations
|
|
222
|
+
*/
|
|
223
|
+
<A>(value: A): <E>(self: TxDeferred<A, E>) => Effect.Effect<boolean, never, Effect.Transaction>;
|
|
224
|
+
/**
|
|
225
|
+
* Completes the deferred with a success value. Returns `true` if this was the
|
|
226
|
+
* first completion, `false` if already completed.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* import { Effect, TxDeferred } from "effect"
|
|
231
|
+
*
|
|
232
|
+
* const program = Effect.gen(function*() {
|
|
233
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
234
|
+
* const first = yield* TxDeferred.succeed(deferred, 42)
|
|
235
|
+
* console.log(first) // true
|
|
236
|
+
* const second = yield* TxDeferred.succeed(deferred, 99)
|
|
237
|
+
* console.log(second) // false
|
|
238
|
+
* })
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @since 4.0.0
|
|
242
|
+
* @category mutations
|
|
243
|
+
*/
|
|
244
|
+
<A, E>(self: TxDeferred<A, E>, value: A): Effect.Effect<boolean, never, Effect.Transaction>;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Completes the deferred with a failure. Returns `true` if this was the first
|
|
248
|
+
* completion, `false` if already completed.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { Effect, TxDeferred } from "effect"
|
|
253
|
+
*
|
|
254
|
+
* const program = Effect.gen(function*() {
|
|
255
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
256
|
+
* const first = yield* TxDeferred.fail(deferred, "boom")
|
|
257
|
+
* console.log(first) // true
|
|
258
|
+
* const second = yield* TxDeferred.fail(deferred, "boom2")
|
|
259
|
+
* console.log(second) // false
|
|
260
|
+
* })
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @since 4.0.0
|
|
264
|
+
* @category mutations
|
|
265
|
+
*/
|
|
266
|
+
export declare const fail: {
|
|
267
|
+
/**
|
|
268
|
+
* Completes the deferred with a failure. Returns `true` if this was the first
|
|
269
|
+
* completion, `false` if already completed.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```ts
|
|
273
|
+
* import { Effect, TxDeferred } from "effect"
|
|
274
|
+
*
|
|
275
|
+
* const program = Effect.gen(function*() {
|
|
276
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
277
|
+
* const first = yield* TxDeferred.fail(deferred, "boom")
|
|
278
|
+
* console.log(first) // true
|
|
279
|
+
* const second = yield* TxDeferred.fail(deferred, "boom2")
|
|
280
|
+
* console.log(second) // false
|
|
281
|
+
* })
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @since 4.0.0
|
|
285
|
+
* @category mutations
|
|
286
|
+
*/
|
|
287
|
+
<E>(error: E): <A>(self: TxDeferred<A, E>) => Effect.Effect<boolean, never, Effect.Transaction>;
|
|
288
|
+
/**
|
|
289
|
+
* Completes the deferred with a failure. Returns `true` if this was the first
|
|
290
|
+
* completion, `false` if already completed.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* import { Effect, TxDeferred } from "effect"
|
|
295
|
+
*
|
|
296
|
+
* const program = Effect.gen(function*() {
|
|
297
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
298
|
+
* const first = yield* TxDeferred.fail(deferred, "boom")
|
|
299
|
+
* console.log(first) // true
|
|
300
|
+
* const second = yield* TxDeferred.fail(deferred, "boom2")
|
|
301
|
+
* console.log(second) // false
|
|
302
|
+
* })
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @since 4.0.0
|
|
306
|
+
* @category mutations
|
|
307
|
+
*/
|
|
308
|
+
<A, E>(self: TxDeferred<A, E>, error: E): Effect.Effect<boolean, never, Effect.Transaction>;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Determines if the provided value is a `TxDeferred`.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* import { Effect, TxDeferred } from "effect"
|
|
316
|
+
*
|
|
317
|
+
* const program = Effect.gen(function*() {
|
|
318
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
319
|
+
* console.log(TxDeferred.isTxDeferred(deferred)) // true
|
|
320
|
+
* console.log(TxDeferred.isTxDeferred("not a deferred")) // false
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @since 4.0.0
|
|
325
|
+
* @category guards
|
|
326
|
+
*/
|
|
327
|
+
export declare const isTxDeferred: (u: unknown) => u is TxDeferred<unknown, unknown>;
|
|
328
|
+
//# sourceMappingURL=TxDeferred.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TxDeferred.d.ts","sourceRoot":"","sources":["../src/TxDeferred.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,KAAK,MAAM,YAAY,CA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AAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;IAC/F;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAA;CAK5F,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CACtB,CAAA"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A transactional deferred value — a write-once cell that can be read within transactions.
|
|
3
|
+
* Readers retry until a value is set; once set, the value is immutable.
|
|
4
|
+
*
|
|
5
|
+
* @since 4.0.0
|
|
6
|
+
*/
|
|
7
|
+
import * as Effect from "./Effect.js";
|
|
8
|
+
import { dual } from "./Function.js";
|
|
9
|
+
import { NodeInspectSymbol, toJson } from "./Inspectable.js";
|
|
10
|
+
import * as O from "./Option.js";
|
|
11
|
+
import { pipeArguments } from "./Pipeable.js";
|
|
12
|
+
import * as Res from "./Result.js";
|
|
13
|
+
import * as TxRef from "./TxRef.js";
|
|
14
|
+
const TypeId = "~effect/transactions/TxDeferred";
|
|
15
|
+
const TxDeferredProto = {
|
|
16
|
+
[NodeInspectSymbol]() {
|
|
17
|
+
return toJson(this);
|
|
18
|
+
},
|
|
19
|
+
toJSON() {
|
|
20
|
+
return {
|
|
21
|
+
_id: "TxDeferred"
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
pipe() {
|
|
25
|
+
return pipeArguments(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const makeTxDeferred = ref => {
|
|
29
|
+
const self = Object.create(TxDeferredProto);
|
|
30
|
+
self[TypeId] = TypeId;
|
|
31
|
+
self.ref = ref;
|
|
32
|
+
return self;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new empty `TxDeferred`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { Effect, Option, TxDeferred } from "effect"
|
|
40
|
+
*
|
|
41
|
+
* const program = Effect.gen(function*() {
|
|
42
|
+
* const deferred = yield* TxDeferred.make<string, Error>()
|
|
43
|
+
* const state = yield* TxDeferred.poll(deferred)
|
|
44
|
+
* console.log(Option.isNone(state)) // true
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @since 4.0.0
|
|
49
|
+
* @category constructors
|
|
50
|
+
*/
|
|
51
|
+
export const make = () => Effect.map(TxRef.make(O.none()), makeTxDeferred);
|
|
52
|
+
/**
|
|
53
|
+
* Reads the deferred value. Retries the transaction if the deferred has not
|
|
54
|
+
* been completed yet.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { Effect, TxDeferred } from "effect"
|
|
59
|
+
*
|
|
60
|
+
* const program = Effect.gen(function*() {
|
|
61
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
62
|
+
* yield* TxDeferred.succeed(deferred, 42)
|
|
63
|
+
* const value = yield* TxDeferred.await(deferred)
|
|
64
|
+
* console.log(value) // 42
|
|
65
|
+
* })
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @since 4.0.0
|
|
69
|
+
* @category getters
|
|
70
|
+
*/
|
|
71
|
+
const await_ = self => Effect.gen(function* () {
|
|
72
|
+
const option = yield* TxRef.get(self.ref);
|
|
73
|
+
if (O.isNone(option)) {
|
|
74
|
+
return yield* Effect.retryTransaction;
|
|
75
|
+
}
|
|
76
|
+
return Res.isSuccess(option.value) ? option.value.success : yield* Effect.fail(option.value.failure);
|
|
77
|
+
});
|
|
78
|
+
export {
|
|
79
|
+
/**
|
|
80
|
+
* Reads the deferred value. Retries the transaction if the deferred has not
|
|
81
|
+
* been completed yet.
|
|
82
|
+
*
|
|
83
|
+
* @since 4.0.0
|
|
84
|
+
* @category getters
|
|
85
|
+
*/
|
|
86
|
+
await_ as await };
|
|
87
|
+
/**
|
|
88
|
+
* Reads the current state of the deferred without retrying. Returns `None` if
|
|
89
|
+
* not yet completed.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { Effect, Option, Result, TxDeferred } from "effect"
|
|
94
|
+
*
|
|
95
|
+
* const program = Effect.gen(function*() {
|
|
96
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
97
|
+
* const before = yield* TxDeferred.poll(deferred)
|
|
98
|
+
* console.log(Option.isNone(before)) // true
|
|
99
|
+
*
|
|
100
|
+
* yield* TxDeferred.succeed(deferred, 42)
|
|
101
|
+
* const after = yield* TxDeferred.poll(deferred)
|
|
102
|
+
* console.log(after) // Some(Success(42))
|
|
103
|
+
* })
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @since 4.0.0
|
|
107
|
+
* @category getters
|
|
108
|
+
*/
|
|
109
|
+
export const poll = self => TxRef.get(self.ref);
|
|
110
|
+
/**
|
|
111
|
+
* Completes the deferred with a `Result`. Returns `true` if this was the first
|
|
112
|
+
* completion, `false` if already completed.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { Effect, Result, TxDeferred } from "effect"
|
|
117
|
+
*
|
|
118
|
+
* const program = Effect.gen(function*() {
|
|
119
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
120
|
+
* const first = yield* TxDeferred.done(deferred, Result.succeed(42))
|
|
121
|
+
* console.log(first) // true
|
|
122
|
+
* const second = yield* TxDeferred.done(deferred, Result.succeed(99))
|
|
123
|
+
* console.log(second) // false
|
|
124
|
+
* })
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @since 4.0.0
|
|
128
|
+
* @category mutations
|
|
129
|
+
*/
|
|
130
|
+
export const done = /*#__PURE__*/dual(2, (self, result) => TxRef.modify(self.ref, current => {
|
|
131
|
+
if (O.isSome(current)) {
|
|
132
|
+
return [false, current];
|
|
133
|
+
}
|
|
134
|
+
return [true, O.some(result)];
|
|
135
|
+
}));
|
|
136
|
+
/**
|
|
137
|
+
* Completes the deferred with a success value. Returns `true` if this was the
|
|
138
|
+
* first completion, `false` if already completed.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { Effect, TxDeferred } from "effect"
|
|
143
|
+
*
|
|
144
|
+
* const program = Effect.gen(function*() {
|
|
145
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
146
|
+
* const first = yield* TxDeferred.succeed(deferred, 42)
|
|
147
|
+
* console.log(first) // true
|
|
148
|
+
* const second = yield* TxDeferred.succeed(deferred, 99)
|
|
149
|
+
* console.log(second) // false
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @since 4.0.0
|
|
154
|
+
* @category mutations
|
|
155
|
+
*/
|
|
156
|
+
export const succeed = /*#__PURE__*/dual(2, (self, value) => done(self, Res.succeed(value)));
|
|
157
|
+
/**
|
|
158
|
+
* Completes the deferred with a failure. Returns `true` if this was the first
|
|
159
|
+
* completion, `false` if already completed.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { Effect, TxDeferred } from "effect"
|
|
164
|
+
*
|
|
165
|
+
* const program = Effect.gen(function*() {
|
|
166
|
+
* const deferred = yield* TxDeferred.make<number, string>()
|
|
167
|
+
* const first = yield* TxDeferred.fail(deferred, "boom")
|
|
168
|
+
* console.log(first) // true
|
|
169
|
+
* const second = yield* TxDeferred.fail(deferred, "boom2")
|
|
170
|
+
* console.log(second) // false
|
|
171
|
+
* })
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @since 4.0.0
|
|
175
|
+
* @category mutations
|
|
176
|
+
*/
|
|
177
|
+
export const fail = /*#__PURE__*/dual(2, (self, error) => done(self, Res.fail(error)));
|
|
178
|
+
/**
|
|
179
|
+
* Determines if the provided value is a `TxDeferred`.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { Effect, TxDeferred } from "effect"
|
|
184
|
+
*
|
|
185
|
+
* const program = Effect.gen(function*() {
|
|
186
|
+
* const deferred = yield* TxDeferred.make<number>()
|
|
187
|
+
* console.log(TxDeferred.isTxDeferred(deferred)) // true
|
|
188
|
+
* console.log(TxDeferred.isTxDeferred("not a deferred")) // false
|
|
189
|
+
* })
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @since 4.0.0
|
|
193
|
+
* @category guards
|
|
194
|
+
*/
|
|
195
|
+
export const isTxDeferred = u => typeof u === "object" && u !== null && TypeId in u;
|
|
196
|
+
//# sourceMappingURL=TxDeferred.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TxDeferred.js","names":["Effect","dual","NodeInspectSymbol","toJson","O","pipeArguments","Res","TxRef","TypeId","TxDeferredProto","toJSON","_id","pipe","arguments","makeTxDeferred","ref","self","Object","create","make","map","none","await_","gen","option","get","isNone","retryTransaction","isSuccess","value","success","fail","failure","await","poll","done","result","modify","current","isSome","some","succeed","error","isTxDeferred","u"],"sources":["../src/TxDeferred.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;AAOA,OAAO,KAAKA,MAAM,MAAM,aAAa;AACrC,SAASC,IAAI,QAAQ,eAAe;AAEpC,SAASC,iBAAiB,EAAEC,MAAM,QAAQ,kBAAkB;AAE5D,OAAO,KAAKC,CAAC,MAAM,aAAa;AAEhC,SAASC,aAAa,QAAQ,eAAe;AAE7C,OAAO,KAAKC,GAAG,MAAM,aAAa;A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