@clayroach/effect 3.19.14-source-capture.6 → 3.19.14-source-capture.8
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/cjs/Utils.js +1 -1
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/internal/clock.js +1 -1
- package/dist/cjs/internal/clock.js.map +1 -1
- package/dist/esm/Utils.js +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/internal/clock.js +1 -1
- package/dist/esm/internal/clock.js.map +1 -1
- package/package.json +1 -1
- package/src/Arbitrary.ts +0 -1101
- package/src/Array.ts +0 -3589
- package/src/BigDecimal.ts +0 -1349
- package/src/BigInt.ts +0 -643
- package/src/Boolean.ts +0 -287
- package/src/Brand.ts +0 -360
- package/src/Cache.ts +0 -281
- package/src/Cause.ts +0 -1555
- package/src/Channel.ts +0 -2355
- package/src/ChildExecutorDecision.ts +0 -146
- package/src/Chunk.ts +0 -1495
- package/src/Clock.ts +0 -111
- package/src/Config.ts +0 -542
- package/src/ConfigError.ts +0 -270
- package/src/ConfigProvider.ts +0 -333
- package/src/ConfigProviderPathPatch.ts +0 -100
- package/src/Console.ts +0 -226
- package/src/Context.ts +0 -585
- package/src/Cron.ts +0 -706
- package/src/Data.ts +0 -596
- package/src/DateTime.ts +0 -1686
- package/src/DefaultServices.ts +0 -34
- package/src/Deferred.ts +0 -301
- package/src/Differ.ts +0 -450
- package/src/Duration.ts +0 -1000
- package/src/Effect.ts +0 -14839
- package/src/Effectable.ts +0 -107
- package/src/Either.ts +0 -1040
- package/src/Encoding.ts +0 -195
- package/src/Equal.ts +0 -98
- package/src/Equivalence.ts +0 -235
- package/src/ExecutionPlan.ts +0 -308
- package/src/ExecutionStrategy.ts +0 -119
- package/src/Exit.ts +0 -467
- package/src/FastCheck.ts +0 -9
- package/src/Fiber.ts +0 -744
- package/src/FiberHandle.ts +0 -540
- package/src/FiberId.ts +0 -195
- package/src/FiberMap.ts +0 -656
- package/src/FiberRef.ts +0 -431
- package/src/FiberRefs.ts +0 -204
- package/src/FiberRefsPatch.ts +0 -105
- package/src/FiberSet.ts +0 -491
- package/src/FiberStatus.ts +0 -108
- package/src/Function.ts +0 -1222
- package/src/GlobalValue.ts +0 -53
- package/src/Graph.ts +0 -3732
- package/src/GroupBy.ts +0 -103
- package/src/HKT.ts +0 -45
- package/src/Hash.ts +0 -195
- package/src/HashMap.ts +0 -519
- package/src/HashRing.ts +0 -317
- package/src/HashSet.ts +0 -2346
- package/src/Inspectable.ts +0 -287
- package/src/Iterable.ts +0 -1119
- package/src/JSONSchema.ts +0 -1044
- package/src/KeyedPool.ts +0 -167
- package/src/Layer.ts +0 -1251
- package/src/LayerMap.ts +0 -436
- package/src/List.ts +0 -977
- package/src/LogLevel.ts +0 -285
- package/src/LogSpan.ts +0 -25
- package/src/Logger.ts +0 -702
- package/src/Mailbox.ts +0 -268
- package/src/ManagedRuntime.ts +0 -180
- package/src/Match.ts +0 -1477
- package/src/MergeDecision.ts +0 -95
- package/src/MergeState.ts +0 -172
- package/src/MergeStrategy.ts +0 -107
- package/src/Metric.ts +0 -780
- package/src/MetricBoundaries.ts +0 -69
- package/src/MetricHook.ts +0 -151
- package/src/MetricKey.ts +0 -224
- package/src/MetricKeyType.ts +0 -262
- package/src/MetricLabel.ts +0 -47
- package/src/MetricPair.ts +0 -71
- package/src/MetricPolling.ts +0 -148
- package/src/MetricRegistry.ts +0 -48
- package/src/MetricState.ts +0 -257
- package/src/Micro.ts +0 -4405
- package/src/ModuleVersion.ts +0 -18
- package/src/MutableHashMap.ts +0 -411
- package/src/MutableHashSet.ts +0 -706
- package/src/MutableList.ts +0 -297
- package/src/MutableQueue.ts +0 -227
- package/src/MutableRef.ts +0 -202
- package/src/NonEmptyIterable.ts +0 -32
- package/src/Number.ts +0 -1071
- package/src/Option.ts +0 -2170
- package/src/Order.ts +0 -373
- package/src/Ordering.ts +0 -111
- package/src/ParseResult.ts +0 -2031
- package/src/PartitionedSemaphore.ts +0 -200
- package/src/Pipeable.ts +0 -566
- package/src/Pool.ts +0 -204
- package/src/Predicate.ts +0 -1405
- package/src/Pretty.ts +0 -205
- package/src/PrimaryKey.ts +0 -23
- package/src/PubSub.ts +0 -182
- package/src/Queue.ts +0 -644
- package/src/Random.ts +0 -204
- package/src/RateLimiter.ts +0 -138
- package/src/RcMap.ts +0 -141
- package/src/RcRef.ts +0 -122
- package/src/Readable.ts +0 -93
- package/src/Record.ts +0 -1274
- package/src/RedBlackTree.ts +0 -421
- package/src/Redacted.ts +0 -144
- package/src/Ref.ts +0 -180
- package/src/RegExp.ts +0 -38
- package/src/Reloadable.ts +0 -127
- package/src/Request.ts +0 -347
- package/src/RequestBlock.ts +0 -118
- package/src/RequestResolver.ts +0 -366
- package/src/Resource.ts +0 -119
- package/src/Runtime.ts +0 -383
- package/src/RuntimeFlags.ts +0 -368
- package/src/RuntimeFlagsPatch.ts +0 -183
- package/src/STM.ts +0 -2045
- package/src/Schedule.ts +0 -2219
- package/src/ScheduleDecision.ts +0 -62
- package/src/ScheduleInterval.ts +0 -151
- package/src/ScheduleIntervals.ts +0 -122
- package/src/Scheduler.ts +0 -353
- package/src/Schema.ts +0 -10914
- package/src/SchemaAST.ts +0 -3043
- package/src/Scope.ts +0 -204
- package/src/ScopedCache.ts +0 -151
- package/src/ScopedRef.ts +0 -117
- package/src/Secret.ts +0 -88
- package/src/SingleProducerAsyncInput.ts +0 -67
- package/src/Sink.ts +0 -1461
- package/src/SortedMap.ts +0 -287
- package/src/SortedSet.ts +0 -390
- package/src/Stream.ts +0 -6468
- package/src/StreamEmit.ts +0 -136
- package/src/StreamHaltStrategy.ts +0 -123
- package/src/Streamable.ts +0 -45
- package/src/String.ts +0 -778
- package/src/Struct.ts +0 -243
- package/src/Subscribable.ts +0 -100
- package/src/SubscriptionRef.ts +0 -298
- package/src/Supervisor.ts +0 -240
- package/src/Symbol.ts +0 -29
- package/src/SynchronizedRef.ts +0 -270
- package/src/TArray.ts +0 -495
- package/src/TDeferred.ts +0 -100
- package/src/TMap.ts +0 -515
- package/src/TPriorityQueue.ts +0 -223
- package/src/TPubSub.ts +0 -200
- package/src/TQueue.ts +0 -432
- package/src/TRandom.ts +0 -129
- package/src/TReentrantLock.ts +0 -224
- package/src/TRef.ts +0 -178
- package/src/TSemaphore.ts +0 -129
- package/src/TSet.ts +0 -365
- package/src/TSubscriptionRef.ts +0 -192
- package/src/Take.ts +0 -258
- package/src/TestAnnotation.ts +0 -158
- package/src/TestAnnotationMap.ts +0 -119
- package/src/TestAnnotations.ts +0 -117
- package/src/TestClock.ts +0 -556
- package/src/TestConfig.ts +0 -47
- package/src/TestContext.ts +0 -36
- package/src/TestLive.ts +0 -53
- package/src/TestServices.ts +0 -390
- package/src/TestSized.ts +0 -55
- package/src/Tracer.ts +0 -198
- package/src/Trie.ts +0 -840
- package/src/Tuple.ts +0 -305
- package/src/Types.ts +0 -353
- package/src/Unify.ts +0 -113
- package/src/UpstreamPullRequest.ts +0 -117
- package/src/UpstreamPullStrategy.ts +0 -121
- package/src/Utils.ts +0 -809
- package/src/index.ts +0 -1561
- package/src/internal/array.ts +0 -8
- package/src/internal/blockedRequests.ts +0 -520
- package/src/internal/cache.ts +0 -733
- package/src/internal/cause.ts +0 -1050
- package/src/internal/channel/channelExecutor.ts +0 -1200
- package/src/internal/channel/channelState.ts +0 -134
- package/src/internal/channel/childExecutorDecision.ts +0 -96
- package/src/internal/channel/continuation.ts +0 -200
- package/src/internal/channel/mergeDecision.ts +0 -113
- package/src/internal/channel/mergeState.ts +0 -120
- package/src/internal/channel/mergeStrategy.ts +0 -72
- package/src/internal/channel/singleProducerAsyncInput.ts +0 -259
- package/src/internal/channel/subexecutor.ts +0 -229
- package/src/internal/channel/upstreamPullRequest.ts +0 -84
- package/src/internal/channel/upstreamPullStrategy.ts +0 -87
- package/src/internal/channel.ts +0 -2603
- package/src/internal/clock.ts +0 -95
- package/src/internal/completedRequestMap.ts +0 -9
- package/src/internal/concurrency.ts +0 -54
- package/src/internal/config.ts +0 -716
- package/src/internal/configError.ts +0 -304
- package/src/internal/configProvider/pathPatch.ts +0 -97
- package/src/internal/configProvider.ts +0 -799
- package/src/internal/console.ts +0 -153
- package/src/internal/context.ts +0 -337
- package/src/internal/core-effect.ts +0 -2293
- package/src/internal/core-stream.ts +0 -998
- package/src/internal/core.ts +0 -3273
- package/src/internal/data.ts +0 -36
- package/src/internal/dataSource.ts +0 -327
- package/src/internal/dateTime.ts +0 -1277
- package/src/internal/defaultServices/console.ts +0 -100
- package/src/internal/defaultServices.ts +0 -163
- package/src/internal/deferred.ts +0 -46
- package/src/internal/differ/chunkPatch.ts +0 -211
- package/src/internal/differ/contextPatch.ts +0 -232
- package/src/internal/differ/hashMapPatch.ts +0 -220
- package/src/internal/differ/hashSetPatch.ts +0 -176
- package/src/internal/differ/orPatch.ts +0 -311
- package/src/internal/differ/readonlyArrayPatch.ts +0 -210
- package/src/internal/differ.ts +0 -200
- package/src/internal/doNotation.ts +0 -80
- package/src/internal/effect/circular.ts +0 -905
- package/src/internal/effectable.ts +0 -131
- package/src/internal/either.ts +0 -110
- package/src/internal/encoding/base64.ts +0 -286
- package/src/internal/encoding/base64Url.ts +0 -29
- package/src/internal/encoding/common.ts +0 -51
- package/src/internal/encoding/hex.ts +0 -315
- package/src/internal/errors.ts +0 -7
- package/src/internal/executionPlan.ts +0 -114
- package/src/internal/executionStrategy.ts +0 -74
- package/src/internal/fiber.ts +0 -388
- package/src/internal/fiberId.ts +0 -267
- package/src/internal/fiberMessage.ts +0 -82
- package/src/internal/fiberRefs/patch.ts +0 -144
- package/src/internal/fiberRefs.ts +0 -297
- package/src/internal/fiberRuntime.ts +0 -3915
- package/src/internal/fiberScope.ts +0 -71
- package/src/internal/fiberStatus.ts +0 -119
- package/src/internal/groupBy.ts +0 -530
- package/src/internal/hashMap/array.ts +0 -49
- package/src/internal/hashMap/bitwise.ts +0 -32
- package/src/internal/hashMap/config.ts +0 -14
- package/src/internal/hashMap/keySet.ts +0 -8
- package/src/internal/hashMap/node.ts +0 -391
- package/src/internal/hashMap.ts +0 -586
- package/src/internal/hashSet.ts +0 -323
- package/src/internal/keyedPool.ts +0 -244
- package/src/internal/layer/circular.ts +0 -228
- package/src/internal/layer.ts +0 -1487
- package/src/internal/logSpan.ts +0 -20
- package/src/internal/logger-circular.ts +0 -24
- package/src/internal/logger.ts +0 -485
- package/src/internal/mailbox.ts +0 -561
- package/src/internal/managedRuntime/circular.ts +0 -6
- package/src/internal/managedRuntime.ts +0 -134
- package/src/internal/matcher.ts +0 -652
- package/src/internal/metric/boundaries.ts +0 -75
- package/src/internal/metric/hook.ts +0 -483
- package/src/internal/metric/key.ts +0 -167
- package/src/internal/metric/keyType.ts +0 -238
- package/src/internal/metric/label.ts +0 -41
- package/src/internal/metric/pair.ts +0 -48
- package/src/internal/metric/polling.ts +0 -149
- package/src/internal/metric/registry.ts +0 -187
- package/src/internal/metric/state.ts +0 -290
- package/src/internal/metric.ts +0 -577
- package/src/internal/opCodes/cause.ts +0 -35
- package/src/internal/opCodes/channel.ts +0 -83
- package/src/internal/opCodes/channelChildExecutorDecision.ts +0 -17
- package/src/internal/opCodes/channelMergeDecision.ts +0 -11
- package/src/internal/opCodes/channelMergeState.ts +0 -17
- package/src/internal/opCodes/channelMergeStrategy.ts +0 -11
- package/src/internal/opCodes/channelState.ts +0 -23
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +0 -11
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +0 -11
- package/src/internal/opCodes/config.ts +0 -65
- package/src/internal/opCodes/configError.ts +0 -35
- package/src/internal/opCodes/continuation.ts +0 -11
- package/src/internal/opCodes/deferred.ts +0 -11
- package/src/internal/opCodes/effect.ts +0 -89
- package/src/internal/opCodes/layer.ts +0 -59
- package/src/internal/opCodes/streamHaltStrategy.ts +0 -23
- package/src/internal/option.ts +0 -80
- package/src/internal/pool.ts +0 -432
- package/src/internal/pubsub.ts +0 -1762
- package/src/internal/query.ts +0 -204
- package/src/internal/queue.ts +0 -766
- package/src/internal/random.ts +0 -161
- package/src/internal/rateLimiter.ts +0 -93
- package/src/internal/rcMap.ts +0 -285
- package/src/internal/rcRef.ts +0 -192
- package/src/internal/redBlackTree/iterator.ts +0 -200
- package/src/internal/redBlackTree/node.ts +0 -68
- package/src/internal/redBlackTree.ts +0 -1245
- package/src/internal/redacted.ts +0 -73
- package/src/internal/ref.ts +0 -171
- package/src/internal/reloadable.ts +0 -140
- package/src/internal/request.ts +0 -177
- package/src/internal/resource.ts +0 -76
- package/src/internal/ringBuffer.ts +0 -68
- package/src/internal/runtime.ts +0 -558
- package/src/internal/runtimeFlags.ts +0 -188
- package/src/internal/runtimeFlagsPatch.ts +0 -103
- package/src/internal/schedule/decision.ts +0 -47
- package/src/internal/schedule/interval.ts +0 -101
- package/src/internal/schedule/intervals.ts +0 -180
- package/src/internal/schedule.ts +0 -2199
- package/src/internal/schema/errors.ts +0 -191
- package/src/internal/schema/schemaId.ts +0 -106
- package/src/internal/schema/util.ts +0 -50
- package/src/internal/scopedCache.ts +0 -644
- package/src/internal/scopedRef.ts +0 -118
- package/src/internal/secret.ts +0 -89
- package/src/internal/singleShotGen.ts +0 -35
- package/src/internal/sink.ts +0 -2120
- package/src/internal/stack.ts +0 -10
- package/src/internal/stm/core.ts +0 -817
- package/src/internal/stm/entry.ts +0 -59
- package/src/internal/stm/journal.ts +0 -123
- package/src/internal/stm/opCodes/stm.ts +0 -71
- package/src/internal/stm/opCodes/stmState.ts +0 -17
- package/src/internal/stm/opCodes/strategy.ts +0 -17
- package/src/internal/stm/opCodes/tExit.ts +0 -29
- package/src/internal/stm/opCodes/tryCommit.ts +0 -11
- package/src/internal/stm/stm.ts +0 -1453
- package/src/internal/stm/stmState.ts +0 -136
- package/src/internal/stm/tArray.ts +0 -550
- package/src/internal/stm/tDeferred.ts +0 -81
- package/src/internal/stm/tExit.ts +0 -190
- package/src/internal/stm/tMap.ts +0 -824
- package/src/internal/stm/tPriorityQueue.ts +0 -267
- package/src/internal/stm/tPubSub.ts +0 -551
- package/src/internal/stm/tQueue.ts +0 -393
- package/src/internal/stm/tRandom.ts +0 -140
- package/src/internal/stm/tReentrantLock.ts +0 -352
- package/src/internal/stm/tRef.ts +0 -195
- package/src/internal/stm/tSemaphore.ts +0 -113
- package/src/internal/stm/tSet.ts +0 -259
- package/src/internal/stm/tSubscriptionRef.ts +0 -286
- package/src/internal/stm/tryCommit.ts +0 -34
- package/src/internal/stm/txnId.ts +0 -14
- package/src/internal/stm/versioned.ts +0 -4
- package/src/internal/stream/debounceState.ts +0 -57
- package/src/internal/stream/emit.ts +0 -123
- package/src/internal/stream/haltStrategy.ts +0 -94
- package/src/internal/stream/handoff.ts +0 -187
- package/src/internal/stream/handoffSignal.ts +0 -59
- package/src/internal/stream/pull.ts +0 -34
- package/src/internal/stream/sinkEndReason.ts +0 -30
- package/src/internal/stream/zipAllState.ts +0 -88
- package/src/internal/stream/zipChunksState.ts +0 -56
- package/src/internal/stream.ts +0 -8801
- package/src/internal/string-utils.ts +0 -107
- package/src/internal/subscriptionRef.ts +0 -138
- package/src/internal/supervisor/patch.ts +0 -190
- package/src/internal/supervisor.ts +0 -303
- package/src/internal/synchronizedRef.ts +0 -114
- package/src/internal/take.ts +0 -199
- package/src/internal/testing/sleep.ts +0 -27
- package/src/internal/testing/suspendedWarningData.ts +0 -85
- package/src/internal/testing/warningData.ts +0 -94
- package/src/internal/tracer.ts +0 -293
- package/src/internal/trie.ts +0 -722
- package/src/internal/version.ts +0 -7
package/src/internal/queue.ts
DELETED
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import * as Arr from "../Array.js"
|
|
2
|
-
import * as Chunk from "../Chunk.js"
|
|
3
|
-
import type * as Deferred from "../Deferred.js"
|
|
4
|
-
import type * as Effect from "../Effect.js"
|
|
5
|
-
import * as Effectable from "../Effectable.js"
|
|
6
|
-
import { dual, pipe } from "../Function.js"
|
|
7
|
-
import * as MutableQueue from "../MutableQueue.js"
|
|
8
|
-
import * as MutableRef from "../MutableRef.js"
|
|
9
|
-
import * as Option from "../Option.js"
|
|
10
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
11
|
-
import { hasProperty } from "../Predicate.js"
|
|
12
|
-
import type * as Queue from "../Queue.js"
|
|
13
|
-
import * as core from "./core.js"
|
|
14
|
-
import * as fiberRuntime from "./fiberRuntime.js"
|
|
15
|
-
|
|
16
|
-
/** @internal */
|
|
17
|
-
const EnqueueSymbolKey = "effect/QueueEnqueue"
|
|
18
|
-
|
|
19
|
-
/** @internal */
|
|
20
|
-
export const EnqueueTypeId: Queue.EnqueueTypeId = Symbol.for(EnqueueSymbolKey) as Queue.EnqueueTypeId
|
|
21
|
-
|
|
22
|
-
/** @internal */
|
|
23
|
-
const DequeueSymbolKey = "effect/QueueDequeue"
|
|
24
|
-
|
|
25
|
-
/** @internal */
|
|
26
|
-
export const DequeueTypeId: Queue.DequeueTypeId = Symbol.for(DequeueSymbolKey) as Queue.DequeueTypeId
|
|
27
|
-
|
|
28
|
-
/** @internal */
|
|
29
|
-
const QueueStrategySymbolKey = "effect/QueueStrategy"
|
|
30
|
-
|
|
31
|
-
/** @internal */
|
|
32
|
-
export const QueueStrategyTypeId: Queue.QueueStrategyTypeId = Symbol.for(
|
|
33
|
-
QueueStrategySymbolKey
|
|
34
|
-
) as Queue.QueueStrategyTypeId
|
|
35
|
-
|
|
36
|
-
/** @internal */
|
|
37
|
-
const BackingQueueSymbolKey = "effect/BackingQueue"
|
|
38
|
-
|
|
39
|
-
/** @internal */
|
|
40
|
-
export const BackingQueueTypeId: Queue.BackingQueueTypeId = Symbol.for(
|
|
41
|
-
BackingQueueSymbolKey
|
|
42
|
-
) as Queue.BackingQueueTypeId
|
|
43
|
-
|
|
44
|
-
const queueStrategyVariance = {
|
|
45
|
-
/* c8 ignore next */
|
|
46
|
-
_A: (_: any) => _
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const backingQueueVariance = {
|
|
50
|
-
/* c8 ignore next */
|
|
51
|
-
_A: (_: any) => _
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** @internal */
|
|
55
|
-
export const enqueueVariance = {
|
|
56
|
-
/* c8 ignore next */
|
|
57
|
-
_In: (_: unknown) => _
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** @internal */
|
|
61
|
-
export const dequeueVariance = {
|
|
62
|
-
/* c8 ignore next */
|
|
63
|
-
_Out: (_: never) => _
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** @internal */
|
|
67
|
-
class QueueImpl<in out A> extends Effectable.Class<A> implements Queue.Queue<A> {
|
|
68
|
-
readonly [EnqueueTypeId] = enqueueVariance
|
|
69
|
-
readonly [DequeueTypeId] = dequeueVariance
|
|
70
|
-
|
|
71
|
-
constructor(
|
|
72
|
-
/** @internal */
|
|
73
|
-
readonly queue: Queue.BackingQueue<A>,
|
|
74
|
-
/** @internal */
|
|
75
|
-
readonly takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
|
76
|
-
/** @internal */
|
|
77
|
-
readonly shutdownHook: Deferred.Deferred<void>,
|
|
78
|
-
/** @internal */
|
|
79
|
-
readonly shutdownFlag: MutableRef.MutableRef<boolean>,
|
|
80
|
-
/** @internal */
|
|
81
|
-
readonly strategy: Queue.Strategy<A>
|
|
82
|
-
) {
|
|
83
|
-
super()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
pipe() {
|
|
87
|
-
return pipeArguments(this, arguments)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
commit() {
|
|
91
|
-
return this.take
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
capacity(): number {
|
|
95
|
-
return this.queue.capacity()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get size(): Effect.Effect<number> {
|
|
99
|
-
return core.suspend(() => core.catchAll(this.unsafeSize(), () => core.interrupt))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
unsafeSize() {
|
|
103
|
-
if (MutableRef.get(this.shutdownFlag)) {
|
|
104
|
-
return Option.none<number>()
|
|
105
|
-
}
|
|
106
|
-
return Option.some(
|
|
107
|
-
this.queue.length() -
|
|
108
|
-
MutableQueue.length(this.takers) +
|
|
109
|
-
this.strategy.surplusSize()
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get isEmpty(): Effect.Effect<boolean> {
|
|
114
|
-
return core.map(this.size, (size) => size <= 0)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get isFull(): Effect.Effect<boolean> {
|
|
118
|
-
return core.map(this.size, (size) => size >= this.capacity())
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
get shutdown(): Effect.Effect<void> {
|
|
122
|
-
return core.uninterruptible(
|
|
123
|
-
core.withFiberRuntime((state) => {
|
|
124
|
-
pipe(this.shutdownFlag, MutableRef.set(true))
|
|
125
|
-
return pipe(
|
|
126
|
-
fiberRuntime.forEachConcurrentDiscard(
|
|
127
|
-
unsafePollAll(this.takers),
|
|
128
|
-
(d) => core.deferredInterruptWith(d, state.id()),
|
|
129
|
-
false,
|
|
130
|
-
false
|
|
131
|
-
),
|
|
132
|
-
core.zipRight(this.strategy.shutdown),
|
|
133
|
-
core.whenEffect(core.deferredSucceed(this.shutdownHook, void 0)),
|
|
134
|
-
core.asVoid
|
|
135
|
-
)
|
|
136
|
-
})
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get isShutdown(): Effect.Effect<boolean> {
|
|
141
|
-
return core.sync(() => MutableRef.get(this.shutdownFlag))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
get awaitShutdown(): Effect.Effect<void> {
|
|
145
|
-
return core.deferredAwait(this.shutdownHook)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
isActive() {
|
|
149
|
-
return !MutableRef.get(this.shutdownFlag)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
unsafeOffer(value: A): boolean {
|
|
153
|
-
if (MutableRef.get(this.shutdownFlag)) {
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
let noRemaining: boolean
|
|
157
|
-
if (this.queue.length() === 0) {
|
|
158
|
-
const taker = pipe(
|
|
159
|
-
this.takers,
|
|
160
|
-
MutableQueue.poll(MutableQueue.EmptyMutableQueue)
|
|
161
|
-
)
|
|
162
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
163
|
-
unsafeCompleteDeferred(taker, value)
|
|
164
|
-
noRemaining = true
|
|
165
|
-
} else {
|
|
166
|
-
noRemaining = false
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
noRemaining = false
|
|
170
|
-
}
|
|
171
|
-
if (noRemaining) {
|
|
172
|
-
return true
|
|
173
|
-
}
|
|
174
|
-
// Not enough takers, offer to the queue
|
|
175
|
-
const succeeded = this.queue.offer(value)
|
|
176
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers)
|
|
177
|
-
return succeeded
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
offer(value: A): Effect.Effect<boolean> {
|
|
181
|
-
return core.suspend(() => {
|
|
182
|
-
if (MutableRef.get(this.shutdownFlag)) {
|
|
183
|
-
return core.interrupt
|
|
184
|
-
}
|
|
185
|
-
let noRemaining: boolean
|
|
186
|
-
if (this.queue.length() === 0) {
|
|
187
|
-
const taker = pipe(
|
|
188
|
-
this.takers,
|
|
189
|
-
MutableQueue.poll(MutableQueue.EmptyMutableQueue)
|
|
190
|
-
)
|
|
191
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
192
|
-
unsafeCompleteDeferred(taker, value)
|
|
193
|
-
noRemaining = true
|
|
194
|
-
} else {
|
|
195
|
-
noRemaining = false
|
|
196
|
-
}
|
|
197
|
-
} else {
|
|
198
|
-
noRemaining = false
|
|
199
|
-
}
|
|
200
|
-
if (noRemaining) {
|
|
201
|
-
return core.succeed(true)
|
|
202
|
-
}
|
|
203
|
-
// Not enough takers, offer to the queue
|
|
204
|
-
const succeeded = this.queue.offer(value)
|
|
205
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers)
|
|
206
|
-
return succeeded
|
|
207
|
-
? core.succeed(true)
|
|
208
|
-
: this.strategy.handleSurplus([value], this.queue, this.takers, this.shutdownFlag)
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
offerAll(iterable: Iterable<A>): Effect.Effect<boolean> {
|
|
213
|
-
return core.suspend(() => {
|
|
214
|
-
if (MutableRef.get(this.shutdownFlag)) {
|
|
215
|
-
return core.interrupt
|
|
216
|
-
}
|
|
217
|
-
const values = Arr.fromIterable(iterable)
|
|
218
|
-
const pTakers = this.queue.length() === 0
|
|
219
|
-
? Arr.fromIterable(unsafePollN(this.takers, values.length))
|
|
220
|
-
: Arr.empty
|
|
221
|
-
const [forTakers, remaining] = pipe(values, Arr.splitAt(pTakers.length))
|
|
222
|
-
for (let i = 0; i < pTakers.length; i++) {
|
|
223
|
-
const taker = (pTakers as any)[i]
|
|
224
|
-
const item = forTakers[i]
|
|
225
|
-
unsafeCompleteDeferred(taker, item)
|
|
226
|
-
}
|
|
227
|
-
if (remaining.length === 0) {
|
|
228
|
-
return core.succeed(true)
|
|
229
|
-
}
|
|
230
|
-
// Not enough takers, offer to the queue
|
|
231
|
-
const surplus = this.queue.offerAll(remaining)
|
|
232
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers)
|
|
233
|
-
return Chunk.isEmpty(surplus)
|
|
234
|
-
? core.succeed(true)
|
|
235
|
-
: this.strategy.handleSurplus(surplus, this.queue, this.takers, this.shutdownFlag)
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
get take(): Effect.Effect<A> {
|
|
240
|
-
return core.withFiberRuntime((state) => {
|
|
241
|
-
if (MutableRef.get(this.shutdownFlag)) {
|
|
242
|
-
return core.interrupt
|
|
243
|
-
}
|
|
244
|
-
const item = this.queue.poll(MutableQueue.EmptyMutableQueue)
|
|
245
|
-
if (item !== MutableQueue.EmptyMutableQueue) {
|
|
246
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers)
|
|
247
|
-
return core.succeed(item)
|
|
248
|
-
} else {
|
|
249
|
-
// Add the deferred to takers, then:
|
|
250
|
-
// - Try to take again in case a value was added since
|
|
251
|
-
// - Wait for the deferred to be completed
|
|
252
|
-
// - Clean up resources in case of interruption
|
|
253
|
-
const deferred = core.deferredUnsafeMake<A>(state.id())
|
|
254
|
-
return pipe(
|
|
255
|
-
core.suspend(() => {
|
|
256
|
-
pipe(this.takers, MutableQueue.offer(deferred))
|
|
257
|
-
unsafeCompleteTakers(this.strategy, this.queue, this.takers)
|
|
258
|
-
return MutableRef.get(this.shutdownFlag) ?
|
|
259
|
-
core.interrupt :
|
|
260
|
-
core.deferredAwait(deferred)
|
|
261
|
-
}),
|
|
262
|
-
core.onInterrupt(() => {
|
|
263
|
-
return core.sync(() => unsafeRemove(this.takers, deferred))
|
|
264
|
-
})
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
get takeAll(): Effect.Effect<Chunk.Chunk<A>> {
|
|
271
|
-
return core.suspend(() => {
|
|
272
|
-
return MutableRef.get(this.shutdownFlag)
|
|
273
|
-
? core.interrupt
|
|
274
|
-
: core.sync(() => {
|
|
275
|
-
const values = this.queue.pollUpTo(Number.POSITIVE_INFINITY)
|
|
276
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers)
|
|
277
|
-
return Chunk.fromIterable(values)
|
|
278
|
-
})
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
takeUpTo(max: number): Effect.Effect<Chunk.Chunk<A>> {
|
|
283
|
-
return core.suspend(() =>
|
|
284
|
-
MutableRef.get(this.shutdownFlag)
|
|
285
|
-
? core.interrupt
|
|
286
|
-
: core.sync(() => {
|
|
287
|
-
const values = this.queue.pollUpTo(max)
|
|
288
|
-
this.strategy.unsafeOnQueueEmptySpace(this.queue, this.takers)
|
|
289
|
-
return Chunk.fromIterable(values)
|
|
290
|
-
})
|
|
291
|
-
)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
takeBetween(min: number, max: number): Effect.Effect<Chunk.Chunk<A>> {
|
|
295
|
-
return core.suspend(() =>
|
|
296
|
-
takeRemainderLoop(
|
|
297
|
-
this,
|
|
298
|
-
min,
|
|
299
|
-
max,
|
|
300
|
-
Chunk.empty()
|
|
301
|
-
)
|
|
302
|
-
)
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/** @internal */
|
|
307
|
-
const takeRemainderLoop = <A>(
|
|
308
|
-
self: Queue.Dequeue<A>,
|
|
309
|
-
min: number,
|
|
310
|
-
max: number,
|
|
311
|
-
acc: Chunk.Chunk<A>
|
|
312
|
-
): Effect.Effect<Chunk.Chunk<A>> => {
|
|
313
|
-
if (max < min) {
|
|
314
|
-
return core.succeed(acc)
|
|
315
|
-
}
|
|
316
|
-
return pipe(
|
|
317
|
-
takeUpTo(self, max),
|
|
318
|
-
core.flatMap((bs) => {
|
|
319
|
-
const remaining = min - bs.length
|
|
320
|
-
if (remaining === 1) {
|
|
321
|
-
return pipe(
|
|
322
|
-
take(self),
|
|
323
|
-
core.map((b) => pipe(acc, Chunk.appendAll(bs), Chunk.append(b)))
|
|
324
|
-
)
|
|
325
|
-
}
|
|
326
|
-
if (remaining > 1) {
|
|
327
|
-
return pipe(
|
|
328
|
-
take(self),
|
|
329
|
-
core.flatMap((b) =>
|
|
330
|
-
takeRemainderLoop(
|
|
331
|
-
self,
|
|
332
|
-
remaining - 1,
|
|
333
|
-
max - bs.length - 1,
|
|
334
|
-
pipe(acc, Chunk.appendAll(bs), Chunk.append(b))
|
|
335
|
-
)
|
|
336
|
-
)
|
|
337
|
-
)
|
|
338
|
-
}
|
|
339
|
-
return core.succeed(pipe(acc, Chunk.appendAll(bs)))
|
|
340
|
-
})
|
|
341
|
-
)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** @internal */
|
|
345
|
-
export const isQueue = (u: unknown): u is Queue.Queue<unknown> => isEnqueue(u) && isDequeue(u)
|
|
346
|
-
|
|
347
|
-
/** @internal */
|
|
348
|
-
export const isEnqueue = (u: unknown): u is Queue.Enqueue<unknown> => hasProperty(u, EnqueueTypeId)
|
|
349
|
-
|
|
350
|
-
/** @internal */
|
|
351
|
-
export const isDequeue = (u: unknown): u is Queue.Dequeue<unknown> => hasProperty(u, DequeueTypeId)
|
|
352
|
-
|
|
353
|
-
/** @internal */
|
|
354
|
-
export const bounded = <A>(requestedCapacity: number): Effect.Effect<Queue.Queue<A>> =>
|
|
355
|
-
pipe(
|
|
356
|
-
core.sync(() => MutableQueue.bounded<A>(requestedCapacity)),
|
|
357
|
-
core.flatMap((queue) => make(backingQueueFromMutableQueue(queue), backPressureStrategy()))
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
/** @internal */
|
|
361
|
-
export const dropping = <A>(requestedCapacity: number): Effect.Effect<Queue.Queue<A>> =>
|
|
362
|
-
pipe(
|
|
363
|
-
core.sync(() => MutableQueue.bounded<A>(requestedCapacity)),
|
|
364
|
-
core.flatMap((queue) => make(backingQueueFromMutableQueue(queue), droppingStrategy()))
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
/** @internal */
|
|
368
|
-
export const sliding = <A>(requestedCapacity: number): Effect.Effect<Queue.Queue<A>> =>
|
|
369
|
-
pipe(
|
|
370
|
-
core.sync(() => MutableQueue.bounded<A>(requestedCapacity)),
|
|
371
|
-
core.flatMap((queue) => make(backingQueueFromMutableQueue(queue), slidingStrategy()))
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
/** @internal */
|
|
375
|
-
export const unbounded = <A>(): Effect.Effect<Queue.Queue<A>> =>
|
|
376
|
-
pipe(
|
|
377
|
-
core.sync(() => MutableQueue.unbounded<A>()),
|
|
378
|
-
core.flatMap((queue) => make(backingQueueFromMutableQueue(queue), droppingStrategy()))
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
/** @internal */
|
|
382
|
-
const unsafeMake = <A>(
|
|
383
|
-
queue: Queue.BackingQueue<A>,
|
|
384
|
-
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
|
385
|
-
shutdownHook: Deferred.Deferred<void>,
|
|
386
|
-
shutdownFlag: MutableRef.MutableRef<boolean>,
|
|
387
|
-
strategy: Queue.Strategy<A>
|
|
388
|
-
): Queue.Queue<A> => {
|
|
389
|
-
return new QueueImpl(queue, takers, shutdownHook, shutdownFlag, strategy)
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/** @internal */
|
|
393
|
-
export const make = <A>(
|
|
394
|
-
queue: Queue.BackingQueue<A>,
|
|
395
|
-
strategy: Queue.Strategy<A>
|
|
396
|
-
): Effect.Effect<Queue.Queue<A>> =>
|
|
397
|
-
pipe(
|
|
398
|
-
core.deferredMake<void>(),
|
|
399
|
-
core.map((deferred) =>
|
|
400
|
-
unsafeMake(
|
|
401
|
-
queue,
|
|
402
|
-
MutableQueue.unbounded(),
|
|
403
|
-
deferred,
|
|
404
|
-
MutableRef.make(false),
|
|
405
|
-
strategy
|
|
406
|
-
)
|
|
407
|
-
)
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
/** @internal */
|
|
411
|
-
export class BackingQueueFromMutableQueue<in out A> implements Queue.BackingQueue<A> {
|
|
412
|
-
readonly [BackingQueueTypeId] = backingQueueVariance
|
|
413
|
-
constructor(readonly mutable: MutableQueue.MutableQueue<A>) {}
|
|
414
|
-
poll<Def>(def: Def): A | Def {
|
|
415
|
-
return MutableQueue.poll(this.mutable, def)
|
|
416
|
-
}
|
|
417
|
-
pollUpTo(limit: number): Chunk.Chunk<A> {
|
|
418
|
-
return MutableQueue.pollUpTo(this.mutable, limit)
|
|
419
|
-
}
|
|
420
|
-
offerAll(elements: Iterable<A>): Chunk.Chunk<A> {
|
|
421
|
-
return MutableQueue.offerAll(this.mutable, elements)
|
|
422
|
-
}
|
|
423
|
-
offer(element: A): boolean {
|
|
424
|
-
return MutableQueue.offer(this.mutable, element)
|
|
425
|
-
}
|
|
426
|
-
capacity(): number {
|
|
427
|
-
return MutableQueue.capacity(this.mutable)
|
|
428
|
-
}
|
|
429
|
-
length(): number {
|
|
430
|
-
return MutableQueue.length(this.mutable)
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
/** @internal */
|
|
435
|
-
export const backingQueueFromMutableQueue = <A>(mutable: MutableQueue.MutableQueue<A>): Queue.BackingQueue<A> =>
|
|
436
|
-
new BackingQueueFromMutableQueue(mutable)
|
|
437
|
-
|
|
438
|
-
/** @internal */
|
|
439
|
-
export const capacity = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): number => self.capacity()
|
|
440
|
-
|
|
441
|
-
/** @internal */
|
|
442
|
-
export const size = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<number> => self.size
|
|
443
|
-
|
|
444
|
-
/** @internal */
|
|
445
|
-
export const isFull = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<boolean> => self.isFull
|
|
446
|
-
|
|
447
|
-
/** @internal */
|
|
448
|
-
export const isEmpty = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<boolean> => self.isEmpty
|
|
449
|
-
|
|
450
|
-
/** @internal */
|
|
451
|
-
export const isShutdown = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<boolean> => self.isShutdown
|
|
452
|
-
|
|
453
|
-
/** @internal */
|
|
454
|
-
export const awaitShutdown = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<void> => self.awaitShutdown
|
|
455
|
-
|
|
456
|
-
/** @internal */
|
|
457
|
-
export const shutdown = <A>(self: Queue.Dequeue<A> | Queue.Enqueue<A>): Effect.Effect<void> => self.shutdown
|
|
458
|
-
|
|
459
|
-
/** @internal */
|
|
460
|
-
export const offer = dual<
|
|
461
|
-
<A>(value: A) => (self: Queue.Enqueue<A>) => Effect.Effect<boolean>,
|
|
462
|
-
<A>(self: Queue.Enqueue<A>, value: A) => Effect.Effect<boolean>
|
|
463
|
-
>(2, (self, value) => self.offer(value))
|
|
464
|
-
|
|
465
|
-
/** @internal */
|
|
466
|
-
export const unsafeOffer = dual<
|
|
467
|
-
<A>(value: A) => (self: Queue.Enqueue<A>) => boolean,
|
|
468
|
-
<A>(self: Queue.Enqueue<A>, value: A) => boolean
|
|
469
|
-
>(2, (self, value) => self.unsafeOffer(value))
|
|
470
|
-
|
|
471
|
-
/** @internal */
|
|
472
|
-
export const offerAll = dual<
|
|
473
|
-
<A>(
|
|
474
|
-
iterable: Iterable<A>
|
|
475
|
-
) => (self: Queue.Enqueue<A>) => Effect.Effect<boolean>,
|
|
476
|
-
<A>(
|
|
477
|
-
self: Queue.Enqueue<A>,
|
|
478
|
-
iterable: Iterable<A>
|
|
479
|
-
) => Effect.Effect<boolean>
|
|
480
|
-
>(2, (self, iterable) => self.offerAll(iterable))
|
|
481
|
-
|
|
482
|
-
/** @internal */
|
|
483
|
-
export const poll = <A>(self: Queue.Dequeue<A>): Effect.Effect<Option.Option<A>> =>
|
|
484
|
-
core.map(self.takeUpTo(1), Chunk.head)
|
|
485
|
-
|
|
486
|
-
/** @internal */
|
|
487
|
-
export const take = <A>(self: Queue.Dequeue<A>): Effect.Effect<A> => self.take
|
|
488
|
-
|
|
489
|
-
/** @internal */
|
|
490
|
-
export const takeAll = <A>(self: Queue.Dequeue<A>): Effect.Effect<Chunk.Chunk<A>> => self.takeAll
|
|
491
|
-
|
|
492
|
-
/** @internal */
|
|
493
|
-
export const takeUpTo = dual<
|
|
494
|
-
(max: number) => <A>(self: Queue.Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>,
|
|
495
|
-
<A>(self: Queue.Dequeue<A>, max: number) => Effect.Effect<Chunk.Chunk<A>>
|
|
496
|
-
>(2, (self, max) => self.takeUpTo(max))
|
|
497
|
-
|
|
498
|
-
/** @internal */
|
|
499
|
-
export const takeBetween = dual<
|
|
500
|
-
(min: number, max: number) => <A>(self: Queue.Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>,
|
|
501
|
-
<A>(self: Queue.Dequeue<A>, min: number, max: number) => Effect.Effect<Chunk.Chunk<A>>
|
|
502
|
-
>(3, (self, min, max) => self.takeBetween(min, max))
|
|
503
|
-
|
|
504
|
-
/** @internal */
|
|
505
|
-
export const takeN = dual<
|
|
506
|
-
(n: number) => <A>(self: Queue.Dequeue<A>) => Effect.Effect<Chunk.Chunk<A>>,
|
|
507
|
-
<A>(self: Queue.Dequeue<A>, n: number) => Effect.Effect<Chunk.Chunk<A>>
|
|
508
|
-
>(2, (self, n) => self.takeBetween(n, n))
|
|
509
|
-
|
|
510
|
-
// -----------------------------------------------------------------------------
|
|
511
|
-
// Strategy
|
|
512
|
-
// -----------------------------------------------------------------------------
|
|
513
|
-
|
|
514
|
-
/** @internal */
|
|
515
|
-
export const backPressureStrategy = <A>(): Queue.Strategy<A> => new BackPressureStrategy()
|
|
516
|
-
|
|
517
|
-
/** @internal */
|
|
518
|
-
export const droppingStrategy = <A>(): Queue.Strategy<A> => new DroppingStrategy()
|
|
519
|
-
|
|
520
|
-
/** @internal */
|
|
521
|
-
export const slidingStrategy = <A>(): Queue.Strategy<A> => new SlidingStrategy()
|
|
522
|
-
|
|
523
|
-
/** @internal */
|
|
524
|
-
class BackPressureStrategy<in out A> implements Queue.Strategy<A> {
|
|
525
|
-
readonly [QueueStrategyTypeId] = queueStrategyVariance
|
|
526
|
-
|
|
527
|
-
readonly putters = MutableQueue.unbounded<readonly [A, Deferred.Deferred<boolean>, boolean]>()
|
|
528
|
-
|
|
529
|
-
surplusSize(): number {
|
|
530
|
-
return MutableQueue.length(this.putters)
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
onCompleteTakersWithEmptyQueue(takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>): void {
|
|
534
|
-
while (!MutableQueue.isEmpty(this.putters) && !MutableQueue.isEmpty(takers)) {
|
|
535
|
-
const taker = MutableQueue.poll(takers, void 0)!
|
|
536
|
-
const putter = MutableQueue.poll(this.putters, void 0)!
|
|
537
|
-
if (putter[2]) {
|
|
538
|
-
unsafeCompleteDeferred(putter[1], true)
|
|
539
|
-
}
|
|
540
|
-
unsafeCompleteDeferred(taker, putter[0])
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
get shutdown(): Effect.Effect<void> {
|
|
545
|
-
return pipe(
|
|
546
|
-
core.fiberId,
|
|
547
|
-
core.flatMap((fiberId) =>
|
|
548
|
-
pipe(
|
|
549
|
-
core.sync(() => unsafePollAll(this.putters)),
|
|
550
|
-
core.flatMap((putters) =>
|
|
551
|
-
fiberRuntime.forEachConcurrentDiscard(
|
|
552
|
-
putters,
|
|
553
|
-
([_, deferred, isLastItem]) =>
|
|
554
|
-
isLastItem ?
|
|
555
|
-
pipe(
|
|
556
|
-
core.deferredInterruptWith(deferred, fiberId),
|
|
557
|
-
core.asVoid
|
|
558
|
-
) :
|
|
559
|
-
core.void,
|
|
560
|
-
false,
|
|
561
|
-
false
|
|
562
|
-
)
|
|
563
|
-
)
|
|
564
|
-
)
|
|
565
|
-
)
|
|
566
|
-
)
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
handleSurplus(
|
|
570
|
-
iterable: Iterable<A>,
|
|
571
|
-
queue: Queue.BackingQueue<A>,
|
|
572
|
-
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
|
573
|
-
isShutdown: MutableRef.MutableRef<boolean>
|
|
574
|
-
): Effect.Effect<boolean> {
|
|
575
|
-
return core.withFiberRuntime((state) => {
|
|
576
|
-
const deferred = core.deferredUnsafeMake<boolean>(state.id())
|
|
577
|
-
return pipe(
|
|
578
|
-
core.suspend(() => {
|
|
579
|
-
this.unsafeOffer(iterable, deferred)
|
|
580
|
-
this.unsafeOnQueueEmptySpace(queue, takers)
|
|
581
|
-
unsafeCompleteTakers(this, queue, takers)
|
|
582
|
-
return MutableRef.get(isShutdown) ? core.interrupt : core.deferredAwait(deferred)
|
|
583
|
-
}),
|
|
584
|
-
core.onInterrupt(() => core.sync(() => this.unsafeRemove(deferred)))
|
|
585
|
-
)
|
|
586
|
-
})
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
unsafeOnQueueEmptySpace(
|
|
590
|
-
queue: Queue.BackingQueue<A>,
|
|
591
|
-
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
|
592
|
-
): void {
|
|
593
|
-
let keepPolling = true
|
|
594
|
-
while (keepPolling && (queue.capacity() === Number.POSITIVE_INFINITY || queue.length() < queue.capacity())) {
|
|
595
|
-
const putter = pipe(this.putters, MutableQueue.poll(MutableQueue.EmptyMutableQueue))
|
|
596
|
-
if (putter === MutableQueue.EmptyMutableQueue) {
|
|
597
|
-
keepPolling = false
|
|
598
|
-
} else {
|
|
599
|
-
const offered = queue.offer(putter[0])
|
|
600
|
-
if (offered && putter[2]) {
|
|
601
|
-
unsafeCompleteDeferred(putter[1], true)
|
|
602
|
-
} else if (!offered) {
|
|
603
|
-
unsafeOfferAll(this.putters, pipe(unsafePollAll(this.putters), Chunk.prepend(putter)))
|
|
604
|
-
}
|
|
605
|
-
unsafeCompleteTakers(this, queue, takers)
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
unsafeOffer(iterable: Iterable<A>, deferred: Deferred.Deferred<boolean>): void {
|
|
611
|
-
const stuff = Arr.fromIterable(iterable)
|
|
612
|
-
for (let i = 0; i < stuff.length; i++) {
|
|
613
|
-
const value = stuff[i]
|
|
614
|
-
if (i === stuff.length - 1) {
|
|
615
|
-
pipe(this.putters, MutableQueue.offer([value, deferred, true as boolean] as const))
|
|
616
|
-
} else {
|
|
617
|
-
pipe(this.putters, MutableQueue.offer([value, deferred, false as boolean] as const))
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
unsafeRemove(deferred: Deferred.Deferred<boolean>): void {
|
|
623
|
-
unsafeOfferAll(
|
|
624
|
-
this.putters,
|
|
625
|
-
pipe(unsafePollAll(this.putters), Chunk.filter(([, _]) => _ !== deferred))
|
|
626
|
-
)
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
/** @internal */
|
|
631
|
-
class DroppingStrategy<in out A> implements Queue.Strategy<A> {
|
|
632
|
-
readonly [QueueStrategyTypeId] = queueStrategyVariance
|
|
633
|
-
|
|
634
|
-
surplusSize(): number {
|
|
635
|
-
return 0
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
get shutdown(): Effect.Effect<void> {
|
|
639
|
-
return core.void
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
onCompleteTakersWithEmptyQueue(): void {
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
handleSurplus(
|
|
646
|
-
_iterable: Iterable<A>,
|
|
647
|
-
_queue: Queue.BackingQueue<A>,
|
|
648
|
-
_takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
|
649
|
-
_isShutdown: MutableRef.MutableRef<boolean>
|
|
650
|
-
): Effect.Effect<boolean> {
|
|
651
|
-
return core.succeed(false)
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
unsafeOnQueueEmptySpace(
|
|
655
|
-
_queue: Queue.BackingQueue<A>,
|
|
656
|
-
_takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
|
657
|
-
): void {
|
|
658
|
-
//
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/** @internal */
|
|
663
|
-
class SlidingStrategy<in out A> implements Queue.Strategy<A> {
|
|
664
|
-
readonly [QueueStrategyTypeId] = queueStrategyVariance
|
|
665
|
-
|
|
666
|
-
surplusSize(): number {
|
|
667
|
-
return 0
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
get shutdown(): Effect.Effect<void> {
|
|
671
|
-
return core.void
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
onCompleteTakersWithEmptyQueue(): void {
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
handleSurplus(
|
|
678
|
-
iterable: Iterable<A>,
|
|
679
|
-
queue: Queue.BackingQueue<A>,
|
|
680
|
-
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>,
|
|
681
|
-
_isShutdown: MutableRef.MutableRef<boolean>
|
|
682
|
-
): Effect.Effect<boolean> {
|
|
683
|
-
return core.sync(() => {
|
|
684
|
-
this.unsafeOffer(queue, iterable)
|
|
685
|
-
unsafeCompleteTakers(this, queue, takers)
|
|
686
|
-
return true
|
|
687
|
-
})
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
unsafeOnQueueEmptySpace(
|
|
691
|
-
_queue: Queue.BackingQueue<A>,
|
|
692
|
-
_takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
|
693
|
-
): void {
|
|
694
|
-
//
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
unsafeOffer(queue: Queue.BackingQueue<A>, iterable: Iterable<A>): void {
|
|
698
|
-
const iterator = iterable[Symbol.iterator]()
|
|
699
|
-
let next: IteratorResult<A>
|
|
700
|
-
let offering = true
|
|
701
|
-
while (!(next = iterator.next()).done && offering) {
|
|
702
|
-
if (queue.capacity() === 0) {
|
|
703
|
-
return
|
|
704
|
-
}
|
|
705
|
-
// Poll 1 and retry
|
|
706
|
-
queue.poll(MutableQueue.EmptyMutableQueue)
|
|
707
|
-
offering = queue.offer(next.value)
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
/** @internal */
|
|
713
|
-
const unsafeCompleteDeferred = <A>(deferred: Deferred.Deferred<A>, a: A): void => {
|
|
714
|
-
return core.deferredUnsafeDone(deferred, core.succeed(a))
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/** @internal */
|
|
718
|
-
const unsafeOfferAll = <A>(queue: MutableQueue.MutableQueue<A>, as: Iterable<A>): Chunk.Chunk<A> => {
|
|
719
|
-
return pipe(queue, MutableQueue.offerAll(as))
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
/** @internal */
|
|
723
|
-
const unsafePollAll = <A>(queue: MutableQueue.MutableQueue<A>): Chunk.Chunk<A> => {
|
|
724
|
-
return pipe(queue, MutableQueue.pollUpTo(Number.POSITIVE_INFINITY))
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
/** @internal */
|
|
728
|
-
const unsafePollN = <A>(queue: MutableQueue.MutableQueue<A>, max: number): Chunk.Chunk<A> => {
|
|
729
|
-
return pipe(queue, MutableQueue.pollUpTo(max))
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/** @internal */
|
|
733
|
-
export const unsafeRemove = <A>(queue: MutableQueue.MutableQueue<A>, a: A): void => {
|
|
734
|
-
unsafeOfferAll(
|
|
735
|
-
queue,
|
|
736
|
-
pipe(unsafePollAll(queue), Chunk.filter((b) => a !== b))
|
|
737
|
-
)
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
/** @internal */
|
|
741
|
-
export const unsafeCompleteTakers = <A>(
|
|
742
|
-
strategy: Queue.Strategy<A>,
|
|
743
|
-
queue: Queue.BackingQueue<A>,
|
|
744
|
-
takers: MutableQueue.MutableQueue<Deferred.Deferred<A>>
|
|
745
|
-
): void => {
|
|
746
|
-
// Check both a taker and an item are in the queue, starting with the taker
|
|
747
|
-
let keepPolling = true
|
|
748
|
-
while (keepPolling && queue.length() !== 0) {
|
|
749
|
-
const taker = pipe(takers, MutableQueue.poll(MutableQueue.EmptyMutableQueue))
|
|
750
|
-
if (taker !== MutableQueue.EmptyMutableQueue) {
|
|
751
|
-
const element = queue.poll(MutableQueue.EmptyMutableQueue)
|
|
752
|
-
if (element !== MutableQueue.EmptyMutableQueue) {
|
|
753
|
-
unsafeCompleteDeferred(taker, element)
|
|
754
|
-
strategy.unsafeOnQueueEmptySpace(queue, takers)
|
|
755
|
-
} else {
|
|
756
|
-
unsafeOfferAll(takers, pipe(unsafePollAll(takers), Chunk.prepend(taker)))
|
|
757
|
-
}
|
|
758
|
-
keepPolling = true
|
|
759
|
-
} else {
|
|
760
|
-
keepPolling = false
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
if (keepPolling && queue.length() === 0 && !MutableQueue.isEmpty(takers)) {
|
|
764
|
-
strategy.onCompleteTakersWithEmptyQueue(takers)
|
|
765
|
-
}
|
|
766
|
-
}
|