effect 2.0.0-next.46 → 2.0.0-next.47

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 (72) hide show
  1. package/Channel/dist/effect-Channel.cjs.dev.js +3 -3
  2. package/Channel/dist/effect-Channel.cjs.prod.js +3 -3
  3. package/GroupBy/dist/effect-GroupBy.cjs.dev.js +4 -4
  4. package/GroupBy/dist/effect-GroupBy.cjs.prod.js +4 -4
  5. package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +2 -2
  6. package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +2 -2
  7. package/Pool/dist/effect-Pool.cjs.dev.js +2 -2
  8. package/Pool/dist/effect-Pool.cjs.prod.js +2 -2
  9. package/PubSub/dist/effect-PubSub.cjs.dev.js +1 -1
  10. package/PubSub/dist/effect-PubSub.cjs.prod.js +1 -1
  11. package/Queue/dist/effect-Queue.cjs.dev.js +1 -1
  12. package/Queue/dist/effect-Queue.cjs.prod.js +1 -1
  13. package/STM/dist/effect-STM.cjs.dev.js +6 -6
  14. package/STM/dist/effect-STM.cjs.prod.js +6 -6
  15. package/Sink/dist/effect-Sink.cjs.dev.js +2 -2
  16. package/Sink/dist/effect-Sink.cjs.prod.js +2 -2
  17. package/Stream/dist/effect-Stream.cjs.dev.js +4 -4
  18. package/Stream/dist/effect-Stream.cjs.prod.js +4 -4
  19. package/Streamable/dist/effect-Streamable.cjs.dev.js +4 -4
  20. package/Streamable/dist/effect-Streamable.cjs.prod.js +4 -4
  21. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +3 -3
  22. package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +3 -3
  23. package/TArray/dist/effect-TArray.cjs.dev.js +8 -8
  24. package/TArray/dist/effect-TArray.cjs.prod.js +8 -8
  25. package/TDeferred/dist/effect-TDeferred.cjs.dev.js +7 -7
  26. package/TDeferred/dist/effect-TDeferred.cjs.prod.js +7 -7
  27. package/TMap/dist/effect-TMap.cjs.dev.js +9 -9
  28. package/TMap/dist/effect-TMap.cjs.prod.js +9 -9
  29. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +6 -6
  30. package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +6 -6
  31. package/TPubSub/dist/effect-TPubSub.cjs.dev.js +8 -8
  32. package/TPubSub/dist/effect-TPubSub.cjs.prod.js +8 -8
  33. package/TQueue/dist/effect-TQueue.cjs.dev.js +8 -8
  34. package/TQueue/dist/effect-TQueue.cjs.prod.js +8 -8
  35. package/TRandom/dist/effect-TRandom.cjs.dev.js +8 -8
  36. package/TRandom/dist/effect-TRandom.cjs.prod.js +8 -8
  37. package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +6 -6
  38. package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +6 -6
  39. package/TRef/dist/effect-TRef.cjs.dev.js +6 -6
  40. package/TRef/dist/effect-TRef.cjs.prod.js +6 -6
  41. package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +7 -7
  42. package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +7 -7
  43. package/TSet/dist/effect-TSet.cjs.dev.js +9 -9
  44. package/TSet/dist/effect-TSet.cjs.prod.js +9 -9
  45. package/dist/{core-7411d1e1.cjs.prod.js → core-84e608f0.cjs.prod.js} +1 -1
  46. package/dist/{core-c5747f88.cjs.dev.js → core-c01fd1d8.cjs.dev.js} +1 -1
  47. package/dist/declarations/src/Queue.d.ts +5 -0
  48. package/dist/declarations/src/Queue.d.ts.map +1 -1
  49. package/dist/{groupBy-724f64ef.cjs.prod.js → groupBy-5fb5d639.cjs.prod.js} +2 -2
  50. package/dist/{groupBy-862cc2da.cjs.dev.js → groupBy-70c6dc0d.cjs.dev.js} +2 -2
  51. package/dist/{pool-f77d7705.cjs.prod.js → pool-042cc42b.cjs.prod.js} +1 -1
  52. package/dist/{pool-3211287f.cjs.dev.js → pool-59df8b4d.cjs.dev.js} +1 -1
  53. package/dist/{queue-315ea45d.cjs.prod.js → queue-425b92f6.cjs.prod.js} +21 -11
  54. package/dist/{queue-7a223c44.cjs.dev.js → queue-e4c59627.cjs.dev.js} +21 -11
  55. package/dist/{stm-8aca0022.cjs.dev.js → stm-5264610b.cjs.dev.js} +1 -1
  56. package/dist/{stm-f250b596.cjs.prod.js → stm-9dd6be88.cjs.prod.js} +1 -1
  57. package/dist/{stream-34d80d2c.cjs.dev.js → stream-5e2ed3a9.cjs.dev.js} +1 -1
  58. package/dist/{stream-ea4f4d44.cjs.prod.js → stream-c9c522f2.cjs.prod.js} +1 -1
  59. package/dist/{tArray-17f078f2.cjs.dev.js → tArray-77a2ae3c.cjs.dev.js} +3 -3
  60. package/dist/{tArray-d184e22f.cjs.prod.js → tArray-cac66af4.cjs.prod.js} +3 -3
  61. package/dist/{tMap-e219f30e.cjs.prod.js → tMap-5ac8ec9c.cjs.prod.js} +4 -4
  62. package/dist/{tMap-1a5aa78b.cjs.dev.js → tMap-73bbf062.cjs.dev.js} +4 -4
  63. package/dist/{tQueue-0a4fc773.cjs.dev.js → tQueue-2b1cd0c4.cjs.dev.js} +3 -3
  64. package/dist/{tQueue-47129ad0.cjs.prod.js → tQueue-dded9b2d.cjs.prod.js} +3 -3
  65. package/dist/{tRef-ab4c5713.cjs.prod.js → tRef-73c3549e.cjs.prod.js} +1 -1
  66. package/dist/{tRef-b860ef05.cjs.dev.js → tRef-90f0872b.cjs.dev.js} +1 -1
  67. package/internal/queue.esm.js +24 -14
  68. package/package.json +1 -1
  69. package/src/Queue.ts +8 -0
  70. package/src/internal/queue.ts +26 -11
  71. /package/dist/{sink-8d3427e7.cjs.dev.js → sink-17e02d40.cjs.dev.js} +0 -0
  72. /package/dist/{sink-572d8981.cjs.prod.js → sink-b2fcb569.cjs.prod.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var Function_dist_effectFunction = require('../Function/dist/effect-Function.cjs.dev.js');
4
- var core = require('./core-c5747f88.cjs.dev.js');
4
+ var core = require('./core-c01fd1d8.cjs.dev.js');
5
5
  var Option_dist_effectOption = require('../Option/dist/effect-Option.cjs.dev.js');
6
6
 
7
7
  /** @internal */
@@ -1,8 +1,8 @@
1
- import { head, prepend, filter, isEmpty as isEmpty$1, fromIterable as fromIterable$1, appendAll, append, empty as empty$1 } from '../Chunk/dist/effect-Chunk.esm.js';
1
+ import { head, prepend, filter, isEmpty as isEmpty$2, fromIterable as fromIterable$1, appendAll, append, empty as empty$1 } from '../Chunk/dist/effect-Chunk.esm.js';
2
2
  import { pipe, dual } from '../Function/dist/effect-Function.esm.js';
3
3
  import { flatMap, sync, map, deferredMake, fiberId, withFiberRuntime, unit, succeed, deferredUnsafeDone, deferredInterruptWith, asUnit, deferredUnsafeMake, onInterrupt, suspend, interrupt, deferredAwait, catchAll, uninterruptible, whenEffect, deferredSucceed, zipRight } from './core.esm.js';
4
4
  import { forEachParUnboundedDiscard } from './fiberRuntime.esm.js';
5
- import { bounded as bounded$1, unbounded as unbounded$1, length, poll as poll$1, EmptyMutableQueue, offer as offer$1, offerAll as offerAll$1, pollUpTo, capacity as capacity$1 } from '../MutableQueue/dist/effect-MutableQueue.esm.js';
5
+ import { bounded as bounded$1, unbounded as unbounded$1, length, isEmpty as isEmpty$1, poll as poll$1, EmptyMutableQueue, offer as offer$1, offerAll as offerAll$1, pollUpTo, capacity as capacity$1 } from '../MutableQueue/dist/effect-MutableQueue.esm.js';
6
6
  import { make as make$1, get, set } from '../MutableRef/dist/effect-MutableRef.esm.js';
7
7
  import { none, some } from '../Option/dist/effect-Option.esm.js';
8
8
  import { pipeArguments } from '../Pipeable/dist/effect-Pipeable.esm.js';
@@ -162,7 +162,7 @@ class QueueImpl {
162
162
  // Not enough takers, offer to the queue
163
163
  const surplus = this.queue.offerAll(remaining);
164
164
  unsafeCompleteTakers(this.strategy, this.queue, this.takers);
165
- return isEmpty$1(surplus) ? succeed(true) : this.strategy.handleSurplus(surplus, this.queue, this.takers, this.shutdownFlag);
165
+ return isEmpty$2(surplus) ? succeed(true) : this.strategy.handleSurplus(surplus, this.queue, this.takers, this.shutdownFlag);
166
166
  });
167
167
  }
168
168
  take() {
@@ -353,6 +353,16 @@ class BackPressureStrategy {
353
353
  surplusSize() {
354
354
  return length(this.putters);
355
355
  }
356
+ onCompleteTakersWithEmptyQueue(takers) {
357
+ while (!isEmpty$1(this.putters) && !isEmpty$1(takers)) {
358
+ const taker = poll$1(takers, void 0);
359
+ const putter = poll$1(this.putters, void 0);
360
+ if (putter[2]) {
361
+ unsafeCompleteDeferred(putter[1], true);
362
+ }
363
+ unsafeCompleteDeferred(taker, putter[0]);
364
+ }
365
+ }
356
366
  shutdown() {
357
367
  return pipe(fiberId, flatMap(fiberId => pipe(sync(() => unsafePollAll(this.putters)), flatMap(putters => forEachParUnboundedDiscard(putters, ([_, deferred, isLastItem]) => isLastItem ? pipe(deferredInterruptWith(deferred, fiberId), asUnit) : unit, false)))));
358
368
  }
@@ -385,17 +395,12 @@ class BackPressureStrategy {
385
395
  }
386
396
  }
387
397
  unsafeOffer(iterable, deferred) {
388
- const iterator = iterable[Symbol.iterator]();
389
- let next = iterator.next();
390
- if (!next.done) {
391
- // eslint-disable-next-line no-constant-condition
392
- while (1) {
393
- const value = next.value;
394
- next = iterator.next();
395
- if (next.done) {
396
- pipe(this.putters, offer$1([value, deferred, true]));
397
- break;
398
- }
398
+ const stuff = Array.from(iterable);
399
+ for (let i = 0; i < stuff.length; i++) {
400
+ const value = stuff[i];
401
+ if (i === stuff.length - 1) {
402
+ pipe(this.putters, offer$1([value, deferred, true]));
403
+ } else {
399
404
  pipe(this.putters, offer$1([value, deferred, false]));
400
405
  }
401
406
  }
@@ -414,6 +419,7 @@ class DroppingStrategy {
414
419
  shutdown() {
415
420
  return unit;
416
421
  }
422
+ onCompleteTakersWithEmptyQueue() {}
417
423
  handleSurplus(_iterable, _queue, _takers, _isShutdown) {
418
424
  return succeed(false);
419
425
  }
@@ -431,6 +437,7 @@ class SlidingStrategy {
431
437
  shutdown() {
432
438
  return unit;
433
439
  }
440
+ onCompleteTakersWithEmptyQueue() {}
434
441
  handleSurplus(iterable, queue, takers, _isShutdown) {
435
442
  return sync(() => {
436
443
  this.unsafeOffer(queue, iterable);
@@ -500,6 +507,9 @@ const unsafeCompleteTakers = (strategy, queue, takers) => {
500
507
  keepPolling = false;
501
508
  }
502
509
  }
510
+ if (keepPolling && queue.length() === 0 && !isEmpty$1(takers)) {
511
+ strategy.onCompleteTakersWithEmptyQueue(takers);
512
+ }
503
513
  };
504
514
 
505
515
  export { BackingQueueFromMutableQueue, DequeueTypeId, EnqueueTypeId, QueueStrategyTypeId, awaitShutdown, backPressureStrategy, backingQueueFromMutableQueue, bounded, capacity, dequeueVariance, dropping, droppingStrategy, enqueueVariance, isDequeue, isEmpty, isEnqueue, isFull, isQueue, isShutdown, make, offer, offerAll, poll, shutdown, size, sliding, slidingStrategy, take, takeAll, takeBetween, takeN, takeUpTo, unbounded, unsafeCompleteTakers, unsafeOffer, unsafeRemove };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect",
3
- "version": "2.0.0-next.46",
3
+ "version": "2.0.0-next.47",
4
4
  "packageManager": "pnpm@8.7.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/src/Queue.ts CHANGED
@@ -216,6 +216,14 @@ export interface Strategy<A> extends Queue.StrategyVariance<A> {
216
216
  isShutdown: MutableRef.MutableRef<boolean>
217
217
  ): Effect.Effect<never, never, boolean>
218
218
 
219
+ /**
220
+ * It is called when the backing queue is empty but there are some
221
+ * takers that can be completed
222
+ */
223
+ onCompleteTakersWithEmptyQueue(
224
+ takers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>
225
+ ): void
226
+
219
227
  /**
220
228
  * Determines the behavior of the `Queue.Strategy` when the `Queue` has empty
221
229
  * slots following a `take` operation.
@@ -513,6 +513,17 @@ class BackPressureStrategy<A> implements Queue.Strategy<A> {
513
513
  return MutableQueue.length(this.putters)
514
514
  }
515
515
 
516
+ onCompleteTakersWithEmptyQueue(takers: MutableQueue.MutableQueue<Deferred.Deferred<never, A>>): void {
517
+ while (!MutableQueue.isEmpty(this.putters) && !MutableQueue.isEmpty(takers)) {
518
+ const taker = MutableQueue.poll(takers, void 0)!
519
+ const putter = MutableQueue.poll(this.putters, void 0)!
520
+ if (putter[2]) {
521
+ unsafeCompleteDeferred(putter[1], true)
522
+ }
523
+ unsafeCompleteDeferred(taker, putter[0])
524
+ }
525
+ }
526
+
516
527
  shutdown(): Effect.Effect<never, never, void> {
517
528
  return pipe(
518
529
  core.fiberId,
@@ -575,17 +586,12 @@ class BackPressureStrategy<A> implements Queue.Strategy<A> {
575
586
  }
576
587
 
577
588
  unsafeOffer(iterable: Iterable<A>, deferred: Deferred.Deferred<never, boolean>): void {
578
- const iterator = iterable[Symbol.iterator]()
579
- let next: IteratorResult<A> = iterator.next()
580
- if (!next.done) {
581
- // eslint-disable-next-line no-constant-condition
582
- while (1) {
583
- const value = next.value
584
- next = iterator.next()
585
- if (next.done) {
586
- pipe(this.putters, MutableQueue.offer([value, deferred, true as boolean] as const))
587
- break
588
- }
589
+ const stuff = Array.from(iterable)
590
+ for (let i = 0; i < stuff.length; i++) {
591
+ const value = stuff[i]
592
+ if (i === stuff.length - 1) {
593
+ pipe(this.putters, MutableQueue.offer([value, deferred, true as boolean] as const))
594
+ } else {
589
595
  pipe(this.putters, MutableQueue.offer([value, deferred, false as boolean] as const))
590
596
  }
591
597
  }
@@ -611,6 +617,9 @@ class DroppingStrategy<A> implements Queue.Strategy<A> {
611
617
  return core.unit
612
618
  }
613
619
 
620
+ onCompleteTakersWithEmptyQueue(): void {
621
+ }
622
+
614
623
  handleSurplus(
615
624
  _iterable: Iterable<A>,
616
625
  _queue: Queue.BackingQueue<A>,
@@ -640,6 +649,9 @@ class SlidingStrategy<A> implements Queue.Strategy<A> {
640
649
  return core.unit
641
650
  }
642
651
 
652
+ onCompleteTakersWithEmptyQueue(): void {
653
+ }
654
+
643
655
  handleSurplus(
644
656
  iterable: Iterable<A>,
645
657
  queue: Queue.BackingQueue<A>,
@@ -726,4 +738,7 @@ export const unsafeCompleteTakers = <A>(
726
738
  keepPolling = false
727
739
  }
728
740
  }
741
+ if (keepPolling && queue.length() === 0 && !MutableQueue.isEmpty(takers)) {
742
+ strategy.onCompleteTakersWithEmptyQueue(takers)
743
+ }
729
744
  }