effect 3.4.9 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RcMap/package.json +6 -0
- package/RcRef/package.json +6 -0
- package/dist/cjs/Cause.js +22 -1
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Console.js.map +1 -1
- package/dist/cjs/Data.js +3 -1
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/Duration.js +23 -2
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Logger.js +11 -1
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/PubSub.js.map +1 -1
- package/dist/cjs/Random.js +9 -1
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/RcMap.js +52 -0
- package/dist/cjs/RcMap.js.map +1 -0
- package/dist/cjs/RcRef.js +51 -0
- package/dist/cjs/RcRef.js.map +1 -0
- package/dist/cjs/Stream.js +29 -2
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +21 -5
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +0 -5
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +15 -10
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/defaultServices.js +1 -1
- package/dist/cjs/internal/defaultServices.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +3 -1
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +128 -27
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/pubsub.js +216 -36
- package/dist/cjs/internal/pubsub.js.map +1 -1
- package/dist/cjs/internal/random.js +2 -1
- package/dist/cjs/internal/random.js.map +1 -1
- package/dist/cjs/internal/rcMap.js +129 -0
- package/dist/cjs/internal/rcMap.js.map +1 -0
- package/dist/cjs/internal/rcRef.js +122 -0
- package/dist/cjs/internal/rcRef.js.map +1 -0
- package/dist/cjs/internal/stream.js +57 -11
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Cause.d.ts +40 -1
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +3 -3
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +5 -0
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Console.d.ts +2 -4
- package/dist/dts/Console.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +5 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +15 -0
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/PubSub.d.ts +15 -4
- package/dist/dts/PubSub.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +8 -0
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +93 -0
- package/dist/dts/RcMap.d.ts.map +1 -0
- package/dist/dts/RcRef.d.ts +83 -0
- package/dist/dts/RcRef.d.ts.map +1 -0
- package/dist/dts/Stream.d.ts +64 -26
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/index.d.ts +8 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/logger.d.ts.map +1 -1
- package/dist/dts/internal/random.d.ts +1 -1
- package/dist/dts/internal/random.d.ts.map +1 -1
- package/dist/dts/internal/rcMap.d.ts +2 -0
- package/dist/dts/internal/rcMap.d.ts.map +1 -0
- package/dist/dts/internal/rcRef.d.ts +2 -0
- package/dist/dts/internal/rcRef.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Cause.js +21 -0
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Console.js.map +1 -1
- package/dist/esm/Data.js +3 -1
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/Duration.js +20 -0
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Logger.js +10 -0
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/PubSub.js.map +1 -1
- package/dist/esm/Random.js +8 -0
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/RcMap.js +44 -0
- package/dist/esm/RcMap.js.map +1 -0
- package/dist/esm/RcRef.js +43 -0
- package/dist/esm/RcRef.js.map +1 -0
- package/dist/esm/Stream.js +27 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +21 -5
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/core-effect.js +0 -5
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +11 -7
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/defaultServices.js +1 -1
- package/dist/esm/internal/defaultServices.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +2 -0
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +126 -26
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/pubsub.js +216 -36
- package/dist/esm/internal/pubsub.js.map +1 -1
- package/dist/esm/internal/random.js +2 -1
- package/dist/esm/internal/random.js.map +1 -1
- package/dist/esm/internal/rcMap.js +120 -0
- package/dist/esm/internal/rcMap.js.map +1 -0
- package/dist/esm/internal/rcRef.js +112 -0
- package/dist/esm/internal/rcRef.js.map +1 -0
- package/dist/esm/internal/stream.js +53 -8
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +17 -1
- package/src/Cause.ts +47 -1
- package/src/Channel.ts +3 -3
- package/src/Config.ts +6 -0
- package/src/Console.ts +2 -4
- package/src/Data.ts +1 -1
- package/src/Duration.ts +18 -0
- package/src/Logger.ts +19 -0
- package/src/PubSub.ts +11 -4
- package/src/Random.ts +9 -0
- package/src/RcMap.ts +103 -0
- package/src/RcRef.ts +91 -0
- package/src/Stream.ts +83 -26
- package/src/index.ts +10 -0
- package/src/internal/cause.ts +26 -5
- package/src/internal/channel/channelExecutor.ts +1 -1
- package/src/internal/channel.ts +4 -3
- package/src/internal/core-effect.ts +0 -5
- package/src/internal/core.ts +19 -9
- package/src/internal/defaultServices.ts +1 -1
- package/src/internal/fiberRuntime.ts +6 -0
- package/src/internal/logger.ts +133 -27
- package/src/internal/pubsub.ts +249 -58
- package/src/internal/random.ts +2 -1
- package/src/internal/rcMap.ts +213 -0
- package/src/internal/rcRef.ts +172 -0
- package/src/internal/stream.ts +325 -111
- package/src/internal/version.ts +1 -1
|
@@ -28,13 +28,25 @@ const removeSubscribers = (subscription, pollers) => subscribers => {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
/** @internal */
|
|
31
|
-
export const bounded =
|
|
31
|
+
export const bounded = capacity => core.suspend(() => {
|
|
32
|
+
const pubsub = makeBoundedPubSub(capacity);
|
|
33
|
+
return makePubSub(pubsub, new BackPressureStrategy());
|
|
34
|
+
});
|
|
32
35
|
/** @internal */
|
|
33
|
-
export const dropping =
|
|
36
|
+
export const dropping = capacity => core.suspend(() => {
|
|
37
|
+
const pubsub = makeBoundedPubSub(capacity);
|
|
38
|
+
return makePubSub(pubsub, new DroppingStrategy());
|
|
39
|
+
});
|
|
34
40
|
/** @internal */
|
|
35
|
-
export const sliding =
|
|
41
|
+
export const sliding = capacity => core.suspend(() => {
|
|
42
|
+
const pubsub = makeBoundedPubSub(capacity);
|
|
43
|
+
return makePubSub(pubsub, new SlidingStrategy());
|
|
44
|
+
});
|
|
36
45
|
/** @internal */
|
|
37
|
-
export const unbounded =
|
|
46
|
+
export const unbounded = options => core.suspend(() => {
|
|
47
|
+
const pubsub = makeUnboundedPubSub(options);
|
|
48
|
+
return makePubSub(pubsub, new DroppingStrategy());
|
|
49
|
+
});
|
|
38
50
|
/** @internal */
|
|
39
51
|
export const capacity = self => self.capacity();
|
|
40
52
|
/** @internal */
|
|
@@ -56,42 +68,47 @@ export const publishAll = /*#__PURE__*/dual(2, (self, elements) => self.publishA
|
|
|
56
68
|
/** @internal */
|
|
57
69
|
export const subscribe = self => self.subscribe;
|
|
58
70
|
/** @internal */
|
|
59
|
-
const makeBoundedPubSub =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
const makeBoundedPubSub = capacity => {
|
|
72
|
+
const options = typeof capacity === "number" ? {
|
|
73
|
+
capacity
|
|
74
|
+
} : capacity;
|
|
75
|
+
ensureCapacity(options.capacity);
|
|
76
|
+
const replayBuffer = options.replay && options.replay > 0 ? new ReplayBuffer(Math.ceil(options.replay)) : undefined;
|
|
77
|
+
if (options.capacity === 1) {
|
|
78
|
+
return new BoundedPubSubSingle(replayBuffer);
|
|
79
|
+
} else if (nextPow2(options.capacity) === options.capacity) {
|
|
80
|
+
return new BoundedPubSubPow2(options.capacity, replayBuffer);
|
|
65
81
|
} else {
|
|
66
|
-
return new BoundedPubSubArb(
|
|
82
|
+
return new BoundedPubSubArb(options.capacity, replayBuffer);
|
|
67
83
|
}
|
|
68
84
|
};
|
|
69
85
|
/** @internal */
|
|
70
|
-
const makeUnboundedPubSub = ()
|
|
71
|
-
return new UnboundedPubSub();
|
|
72
|
-
};
|
|
86
|
+
const makeUnboundedPubSub = options => new UnboundedPubSub(options?.replay ? new ReplayBuffer(options.replay) : undefined);
|
|
73
87
|
/** @internal */
|
|
74
88
|
const makeSubscription = (pubsub, subscribers, strategy) => core.map(core.deferredMake(), deferred => unsafeMakeSubscription(pubsub, subscribers, pubsub.subscribe(), MutableQueue.unbounded(), deferred, MutableRef.make(false), strategy));
|
|
75
89
|
/** @internal */
|
|
76
|
-
export const unsafeMakeSubscription = (pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy) =>
|
|
77
|
-
return new SubscriptionImpl(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy);
|
|
78
|
-
};
|
|
90
|
+
export const unsafeMakeSubscription = (pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy) => new SubscriptionImpl(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy, pubsub.replayWindow());
|
|
79
91
|
/** @internal */
|
|
80
92
|
class BoundedPubSubArb {
|
|
93
|
+
capacity;
|
|
94
|
+
replayBuffer;
|
|
81
95
|
array;
|
|
82
96
|
publisherIndex = 0;
|
|
83
97
|
subscribers;
|
|
84
98
|
subscriberCount = 0;
|
|
85
99
|
subscribersIndex = 0;
|
|
86
|
-
capacity
|
|
87
|
-
|
|
100
|
+
constructor(capacity, replayBuffer) {
|
|
101
|
+
this.capacity = capacity;
|
|
102
|
+
this.replayBuffer = replayBuffer;
|
|
88
103
|
this.array = Array.from({
|
|
89
|
-
length:
|
|
104
|
+
length: capacity
|
|
90
105
|
});
|
|
91
106
|
this.subscribers = Array.from({
|
|
92
|
-
length:
|
|
107
|
+
length: capacity
|
|
93
108
|
});
|
|
94
|
-
|
|
109
|
+
}
|
|
110
|
+
replayWindow() {
|
|
111
|
+
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
95
112
|
}
|
|
96
113
|
isEmpty() {
|
|
97
114
|
return this.publisherIndex === this.subscribersIndex;
|
|
@@ -112,10 +129,16 @@ class BoundedPubSubArb {
|
|
|
112
129
|
this.subscribers[index] = this.subscriberCount;
|
|
113
130
|
this.publisherIndex += 1;
|
|
114
131
|
}
|
|
132
|
+
if (this.replayBuffer) {
|
|
133
|
+
this.replayBuffer.offer(value);
|
|
134
|
+
}
|
|
115
135
|
return true;
|
|
116
136
|
}
|
|
117
137
|
publishAll(elements) {
|
|
118
138
|
if (this.subscriberCount === 0) {
|
|
139
|
+
if (this.replayBuffer) {
|
|
140
|
+
this.replayBuffer.offerAll(elements);
|
|
141
|
+
}
|
|
119
142
|
return Chunk.empty();
|
|
120
143
|
}
|
|
121
144
|
const chunk = Chunk.fromIterable(elements);
|
|
@@ -134,6 +157,9 @@ class BoundedPubSubArb {
|
|
|
134
157
|
this.array[index] = a;
|
|
135
158
|
this.subscribers[index] = this.subscriberCount;
|
|
136
159
|
this.publisherIndex += 1;
|
|
160
|
+
if (this.replayBuffer) {
|
|
161
|
+
this.replayBuffer.offer(a);
|
|
162
|
+
}
|
|
137
163
|
}
|
|
138
164
|
return Chunk.drop(chunk, iteratorIndex);
|
|
139
165
|
}
|
|
@@ -144,6 +170,9 @@ class BoundedPubSubArb {
|
|
|
144
170
|
this.subscribers[index] = 0;
|
|
145
171
|
this.subscribersIndex += 1;
|
|
146
172
|
}
|
|
173
|
+
if (this.replayBuffer) {
|
|
174
|
+
this.replayBuffer.slide();
|
|
175
|
+
}
|
|
147
176
|
}
|
|
148
177
|
subscribe() {
|
|
149
178
|
this.subscriberCount += 1;
|
|
@@ -230,22 +259,27 @@ class BoundedPubSubArbSubscription {
|
|
|
230
259
|
}
|
|
231
260
|
/** @internal */
|
|
232
261
|
class BoundedPubSubPow2 {
|
|
262
|
+
capacity;
|
|
263
|
+
replayBuffer;
|
|
233
264
|
array;
|
|
234
265
|
mask;
|
|
235
266
|
publisherIndex = 0;
|
|
236
267
|
subscribers;
|
|
237
268
|
subscriberCount = 0;
|
|
238
269
|
subscribersIndex = 0;
|
|
239
|
-
capacity
|
|
240
|
-
|
|
270
|
+
constructor(capacity, replayBuffer) {
|
|
271
|
+
this.capacity = capacity;
|
|
272
|
+
this.replayBuffer = replayBuffer;
|
|
241
273
|
this.array = Array.from({
|
|
242
|
-
length:
|
|
274
|
+
length: capacity
|
|
243
275
|
});
|
|
244
|
-
this.mask =
|
|
276
|
+
this.mask = capacity - 1;
|
|
245
277
|
this.subscribers = Array.from({
|
|
246
|
-
length:
|
|
278
|
+
length: capacity
|
|
247
279
|
});
|
|
248
|
-
|
|
280
|
+
}
|
|
281
|
+
replayWindow() {
|
|
282
|
+
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
249
283
|
}
|
|
250
284
|
isEmpty() {
|
|
251
285
|
return this.publisherIndex === this.subscribersIndex;
|
|
@@ -266,10 +300,16 @@ class BoundedPubSubPow2 {
|
|
|
266
300
|
this.subscribers[index] = this.subscriberCount;
|
|
267
301
|
this.publisherIndex += 1;
|
|
268
302
|
}
|
|
303
|
+
if (this.replayBuffer) {
|
|
304
|
+
this.replayBuffer.offer(value);
|
|
305
|
+
}
|
|
269
306
|
return true;
|
|
270
307
|
}
|
|
271
308
|
publishAll(elements) {
|
|
272
309
|
if (this.subscriberCount === 0) {
|
|
310
|
+
if (this.replayBuffer) {
|
|
311
|
+
this.replayBuffer.offerAll(elements);
|
|
312
|
+
}
|
|
273
313
|
return Chunk.empty();
|
|
274
314
|
}
|
|
275
315
|
const chunk = Chunk.fromIterable(elements);
|
|
@@ -288,6 +328,9 @@ class BoundedPubSubPow2 {
|
|
|
288
328
|
this.array[index] = elem;
|
|
289
329
|
this.subscribers[index] = this.subscriberCount;
|
|
290
330
|
this.publisherIndex += 1;
|
|
331
|
+
if (this.replayBuffer) {
|
|
332
|
+
this.replayBuffer.offer(elem);
|
|
333
|
+
}
|
|
291
334
|
}
|
|
292
335
|
return Chunk.drop(chunk, iteratorIndex);
|
|
293
336
|
}
|
|
@@ -298,6 +341,9 @@ class BoundedPubSubPow2 {
|
|
|
298
341
|
this.subscribers[index] = 0;
|
|
299
342
|
this.subscribersIndex += 1;
|
|
300
343
|
}
|
|
344
|
+
if (this.replayBuffer) {
|
|
345
|
+
this.replayBuffer.slide();
|
|
346
|
+
}
|
|
301
347
|
}
|
|
302
348
|
subscribe() {
|
|
303
349
|
this.subscriberCount += 1;
|
|
@@ -385,11 +431,18 @@ class BoundedPubSubPow2Subscription {
|
|
|
385
431
|
}
|
|
386
432
|
/** @internal */
|
|
387
433
|
class BoundedPubSubSingle {
|
|
434
|
+
replayBuffer;
|
|
388
435
|
publisherIndex = 0;
|
|
389
436
|
subscriberCount = 0;
|
|
390
437
|
subscribers = 0;
|
|
391
438
|
value = AbsentValue;
|
|
392
439
|
capacity = 1;
|
|
440
|
+
constructor(replayBuffer) {
|
|
441
|
+
this.replayBuffer = replayBuffer;
|
|
442
|
+
}
|
|
443
|
+
replayWindow() {
|
|
444
|
+
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
445
|
+
}
|
|
393
446
|
pipe() {
|
|
394
447
|
return pipeArguments(this, arguments);
|
|
395
448
|
}
|
|
@@ -411,10 +464,16 @@ class BoundedPubSubSingle {
|
|
|
411
464
|
this.subscribers = this.subscriberCount;
|
|
412
465
|
this.publisherIndex += 1;
|
|
413
466
|
}
|
|
467
|
+
if (this.replayBuffer) {
|
|
468
|
+
this.replayBuffer.offer(value);
|
|
469
|
+
}
|
|
414
470
|
return true;
|
|
415
471
|
}
|
|
416
472
|
publishAll(elements) {
|
|
417
473
|
if (this.subscriberCount === 0) {
|
|
474
|
+
if (this.replayBuffer) {
|
|
475
|
+
this.replayBuffer.offerAll(elements);
|
|
476
|
+
}
|
|
418
477
|
return Chunk.empty();
|
|
419
478
|
}
|
|
420
479
|
const chunk = Chunk.fromIterable(elements);
|
|
@@ -432,6 +491,9 @@ class BoundedPubSubSingle {
|
|
|
432
491
|
this.subscribers = 0;
|
|
433
492
|
this.value = AbsentValue;
|
|
434
493
|
}
|
|
494
|
+
if (this.replayBuffer) {
|
|
495
|
+
this.replayBuffer.slide();
|
|
496
|
+
}
|
|
435
497
|
}
|
|
436
498
|
subscribe() {
|
|
437
499
|
this.subscriberCount += 1;
|
|
@@ -493,6 +555,7 @@ class BoundedPubSubSingleSubscription {
|
|
|
493
555
|
}
|
|
494
556
|
/** @internal */
|
|
495
557
|
class UnboundedPubSub {
|
|
558
|
+
replayBuffer;
|
|
496
559
|
publisherHead = {
|
|
497
560
|
value: AbsentValue,
|
|
498
561
|
subscribers: 0,
|
|
@@ -502,6 +565,12 @@ class UnboundedPubSub {
|
|
|
502
565
|
publisherIndex = 0;
|
|
503
566
|
subscribersIndex = 0;
|
|
504
567
|
capacity = Number.MAX_SAFE_INTEGER;
|
|
568
|
+
constructor(replayBuffer) {
|
|
569
|
+
this.replayBuffer = replayBuffer;
|
|
570
|
+
}
|
|
571
|
+
replayWindow() {
|
|
572
|
+
return this.replayBuffer ? new ReplayWindowImpl(this.replayBuffer) : emptyReplayWindow;
|
|
573
|
+
}
|
|
505
574
|
isEmpty() {
|
|
506
575
|
return this.publisherHead === this.publisherTail;
|
|
507
576
|
}
|
|
@@ -522,6 +591,9 @@ class UnboundedPubSub {
|
|
|
522
591
|
this.publisherTail = this.publisherTail.next;
|
|
523
592
|
this.publisherIndex += 1;
|
|
524
593
|
}
|
|
594
|
+
if (this.replayBuffer) {
|
|
595
|
+
this.replayBuffer.offer(value);
|
|
596
|
+
}
|
|
525
597
|
return true;
|
|
526
598
|
}
|
|
527
599
|
publishAll(elements) {
|
|
@@ -529,6 +601,8 @@ class UnboundedPubSub {
|
|
|
529
601
|
for (const a of elements) {
|
|
530
602
|
this.publish(a);
|
|
531
603
|
}
|
|
604
|
+
} else if (this.replayBuffer) {
|
|
605
|
+
this.replayBuffer.offerAll(elements);
|
|
532
606
|
}
|
|
533
607
|
return Chunk.empty();
|
|
534
608
|
}
|
|
@@ -538,6 +612,9 @@ class UnboundedPubSub {
|
|
|
538
612
|
this.publisherHead.value = AbsentValue;
|
|
539
613
|
this.subscribersIndex += 1;
|
|
540
614
|
}
|
|
615
|
+
if (this.replayBuffer) {
|
|
616
|
+
this.replayBuffer.slide();
|
|
617
|
+
}
|
|
541
618
|
}
|
|
542
619
|
subscribe() {
|
|
543
620
|
this.publisherTail.subscribers += 1;
|
|
@@ -652,8 +729,9 @@ class SubscriptionImpl {
|
|
|
652
729
|
shutdownHook;
|
|
653
730
|
shutdownFlag;
|
|
654
731
|
strategy;
|
|
732
|
+
replayWindow;
|
|
655
733
|
[queue.DequeueTypeId] = queue.dequeueVariance;
|
|
656
|
-
constructor(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy) {
|
|
734
|
+
constructor(pubsub, subscribers, subscription, pollers, shutdownHook, shutdownFlag, strategy, replayWindow) {
|
|
657
735
|
this.pubsub = pubsub;
|
|
658
736
|
this.subscribers = subscribers;
|
|
659
737
|
this.subscription = subscription;
|
|
@@ -661,6 +739,7 @@ class SubscriptionImpl {
|
|
|
661
739
|
this.shutdownHook = shutdownHook;
|
|
662
740
|
this.shutdownFlag = shutdownFlag;
|
|
663
741
|
this.strategy = strategy;
|
|
742
|
+
this.replayWindow = replayWindow;
|
|
664
743
|
}
|
|
665
744
|
pipe() {
|
|
666
745
|
return pipeArguments(this, arguments);
|
|
@@ -672,16 +751,16 @@ class SubscriptionImpl {
|
|
|
672
751
|
return !MutableRef.get(this.shutdownFlag);
|
|
673
752
|
}
|
|
674
753
|
get size() {
|
|
675
|
-
return core.suspend(() => MutableRef.get(this.shutdownFlag) ? core.interrupt : core.succeed(this.subscription.size()));
|
|
754
|
+
return core.suspend(() => MutableRef.get(this.shutdownFlag) ? core.interrupt : core.succeed(this.subscription.size() + this.replayWindow.remaining));
|
|
676
755
|
}
|
|
677
756
|
unsafeSize() {
|
|
678
757
|
if (MutableRef.get(this.shutdownFlag)) {
|
|
679
758
|
return Option.none();
|
|
680
759
|
}
|
|
681
|
-
return Option.some(this.subscription.size());
|
|
760
|
+
return Option.some(this.subscription.size() + this.replayWindow.remaining);
|
|
682
761
|
}
|
|
683
762
|
get isFull() {
|
|
684
|
-
return core.
|
|
763
|
+
return core.suspend(() => MutableRef.get(this.shutdownFlag) ? core.interrupt : core.succeed(this.subscription.size() === this.capacity()));
|
|
685
764
|
}
|
|
686
765
|
get isEmpty() {
|
|
687
766
|
return core.map(this.size, size => size === 0);
|
|
@@ -707,6 +786,10 @@ class SubscriptionImpl {
|
|
|
707
786
|
if (MutableRef.get(this.shutdownFlag)) {
|
|
708
787
|
return core.interrupt;
|
|
709
788
|
}
|
|
789
|
+
if (this.replayWindow.remaining > 0) {
|
|
790
|
+
const message = this.replayWindow.take();
|
|
791
|
+
return core.succeed(message);
|
|
792
|
+
}
|
|
710
793
|
const message = MutableQueue.isEmpty(this.pollers) ? this.subscription.poll(MutableQueue.EmptyMutableQueue) : MutableQueue.EmptyMutableQueue;
|
|
711
794
|
if (message === MutableQueue.EmptyMutableQueue) {
|
|
712
795
|
const deferred = core.deferredUnsafeMake(state.id());
|
|
@@ -729,6 +812,9 @@ class SubscriptionImpl {
|
|
|
729
812
|
}
|
|
730
813
|
const as = MutableQueue.isEmpty(this.pollers) ? unsafePollAllSubscription(this.subscription) : Chunk.empty();
|
|
731
814
|
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
815
|
+
if (this.replayWindow.remaining > 0) {
|
|
816
|
+
return core.succeed(Chunk.appendAll(this.replayWindow.takeAll(), as));
|
|
817
|
+
}
|
|
732
818
|
return core.succeed(as);
|
|
733
819
|
});
|
|
734
820
|
}
|
|
@@ -737,9 +823,17 @@ class SubscriptionImpl {
|
|
|
737
823
|
if (MutableRef.get(this.shutdownFlag)) {
|
|
738
824
|
return core.interrupt;
|
|
739
825
|
}
|
|
826
|
+
let replay = undefined;
|
|
827
|
+
if (this.replayWindow.remaining >= max) {
|
|
828
|
+
const as = this.replayWindow.takeN(max);
|
|
829
|
+
return core.succeed(as);
|
|
830
|
+
} else if (this.replayWindow.remaining > 0) {
|
|
831
|
+
replay = this.replayWindow.takeAll();
|
|
832
|
+
max = max - replay.length;
|
|
833
|
+
}
|
|
740
834
|
const as = MutableQueue.isEmpty(this.pollers) ? unsafePollN(this.subscription, max) : Chunk.empty();
|
|
741
835
|
this.strategy.unsafeOnPubSubEmptySpace(this.pubsub, this.subscribers);
|
|
742
|
-
return core.succeed(as);
|
|
836
|
+
return replay ? core.succeed(Chunk.appendAll(replay, as)) : core.succeed(as);
|
|
743
837
|
});
|
|
744
838
|
}
|
|
745
839
|
takeBetween(min, max) {
|
|
@@ -865,9 +959,7 @@ class PubSubImpl {
|
|
|
865
959
|
/** @internal */
|
|
866
960
|
export const makePubSub = (pubsub, strategy) => core.flatMap(fiberRuntime.scopeMake(), scope => core.map(core.deferredMake(), deferred => unsafeMakePubSub(pubsub, new Map(), scope, deferred, MutableRef.make(false), strategy)));
|
|
867
961
|
/** @internal */
|
|
868
|
-
export const unsafeMakePubSub = (pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy) =>
|
|
869
|
-
return new PubSubImpl(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy);
|
|
870
|
-
};
|
|
962
|
+
export const unsafeMakePubSub = (pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy) => new PubSubImpl(pubsub, subscribers, scope, shutdownHook, shutdownFlag, strategy);
|
|
871
963
|
/** @internal */
|
|
872
964
|
const ensureCapacity = capacity => {
|
|
873
965
|
if (capacity <= 0) {
|
|
@@ -1075,4 +1167,92 @@ const unsafeStrategyCompleteSubscribers = (strategy, pubsub, subscribers) => {
|
|
|
1075
1167
|
}
|
|
1076
1168
|
}
|
|
1077
1169
|
};
|
|
1170
|
+
class ReplayBuffer {
|
|
1171
|
+
capacity;
|
|
1172
|
+
constructor(capacity) {
|
|
1173
|
+
this.capacity = capacity;
|
|
1174
|
+
}
|
|
1175
|
+
head = {
|
|
1176
|
+
value: AbsentValue,
|
|
1177
|
+
next: null
|
|
1178
|
+
};
|
|
1179
|
+
tail = this.head;
|
|
1180
|
+
size = 0;
|
|
1181
|
+
index = 0;
|
|
1182
|
+
slide() {
|
|
1183
|
+
this.index++;
|
|
1184
|
+
}
|
|
1185
|
+
offer(a) {
|
|
1186
|
+
this.tail.value = a;
|
|
1187
|
+
this.tail.next = {
|
|
1188
|
+
value: AbsentValue,
|
|
1189
|
+
next: null
|
|
1190
|
+
};
|
|
1191
|
+
this.tail = this.tail.next;
|
|
1192
|
+
if (this.size === this.capacity) {
|
|
1193
|
+
this.head = this.head.next;
|
|
1194
|
+
} else {
|
|
1195
|
+
this.size += 1;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
offerAll(as) {
|
|
1199
|
+
for (const a of as) {
|
|
1200
|
+
this.offer(a);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
class ReplayWindowImpl {
|
|
1205
|
+
buffer;
|
|
1206
|
+
head;
|
|
1207
|
+
index;
|
|
1208
|
+
remaining;
|
|
1209
|
+
constructor(buffer) {
|
|
1210
|
+
this.buffer = buffer;
|
|
1211
|
+
this.index = buffer.index;
|
|
1212
|
+
this.remaining = buffer.size;
|
|
1213
|
+
this.head = buffer.head;
|
|
1214
|
+
}
|
|
1215
|
+
fastForward() {
|
|
1216
|
+
while (this.index < this.buffer.index) {
|
|
1217
|
+
this.head = this.head.next;
|
|
1218
|
+
this.index++;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
take() {
|
|
1222
|
+
if (this.remaining === 0) {
|
|
1223
|
+
return undefined;
|
|
1224
|
+
} else if (this.index < this.buffer.index) {
|
|
1225
|
+
this.fastForward();
|
|
1226
|
+
}
|
|
1227
|
+
this.remaining--;
|
|
1228
|
+
const value = this.head.value;
|
|
1229
|
+
this.head = this.head.next;
|
|
1230
|
+
return value;
|
|
1231
|
+
}
|
|
1232
|
+
takeN(n) {
|
|
1233
|
+
if (this.remaining === 0) {
|
|
1234
|
+
return Chunk.empty();
|
|
1235
|
+
} else if (this.index < this.buffer.index) {
|
|
1236
|
+
this.fastForward();
|
|
1237
|
+
}
|
|
1238
|
+
const len = Math.min(n, this.remaining);
|
|
1239
|
+
const items = new Array(len);
|
|
1240
|
+
for (let i = 0; i < len; i++) {
|
|
1241
|
+
const value = this.head.value;
|
|
1242
|
+
this.head = this.head.next;
|
|
1243
|
+
items[i] = value;
|
|
1244
|
+
}
|
|
1245
|
+
this.remaining -= len;
|
|
1246
|
+
return Chunk.unsafeFromArray(items);
|
|
1247
|
+
}
|
|
1248
|
+
takeAll() {
|
|
1249
|
+
return this.takeN(this.remaining);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const emptyReplayWindow = {
|
|
1253
|
+
remaining: 0,
|
|
1254
|
+
take: () => undefined,
|
|
1255
|
+
takeN: () => Chunk.empty(),
|
|
1256
|
+
takeAll: () => Chunk.empty()
|
|
1257
|
+
};
|
|
1078
1258
|
//# sourceMappingURL=pubsub.js.map
|