@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/pool.ts
DELETED
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import type { Cause } from "../Cause.js"
|
|
2
|
-
import * as Context from "../Context.js"
|
|
3
|
-
import * as Duration from "../Duration.js"
|
|
4
|
-
import type { Effect, Semaphore } from "../Effect.js"
|
|
5
|
-
import * as Effectable from "../Effectable.js"
|
|
6
|
-
import type { Exit } from "../Exit.js"
|
|
7
|
-
import { dual, identity } from "../Function.js"
|
|
8
|
-
import * as Iterable from "../Iterable.js"
|
|
9
|
-
import * as Option from "../Option.js"
|
|
10
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
11
|
-
import type { Pool, PoolTypeId as PoolTypeId_ } from "../Pool.js"
|
|
12
|
-
import { hasProperty } from "../Predicate.js"
|
|
13
|
-
import type { Scope } from "../Scope.js"
|
|
14
|
-
import * as coreEffect from "./core-effect.js"
|
|
15
|
-
import * as core from "./core.js"
|
|
16
|
-
import * as defaultServices from "./defaultServices.js"
|
|
17
|
-
import * as circular from "./effect/circular.js"
|
|
18
|
-
import * as fiberRuntime from "./fiberRuntime.js"
|
|
19
|
-
import * as internalQueue from "./queue.js"
|
|
20
|
-
|
|
21
|
-
/** @internal */
|
|
22
|
-
export const PoolTypeId: PoolTypeId_ = Symbol.for("effect/Pool") as PoolTypeId_
|
|
23
|
-
|
|
24
|
-
const poolVariance = {
|
|
25
|
-
/* c8 ignore next */
|
|
26
|
-
_E: (_: never) => _,
|
|
27
|
-
/* c8 ignore next */
|
|
28
|
-
_A: (_: any) => _
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @internal */
|
|
32
|
-
export const isPool = (u: unknown): u is Pool<unknown, unknown> => hasProperty(u, PoolTypeId)
|
|
33
|
-
|
|
34
|
-
/** @internal */
|
|
35
|
-
export const makeWith = <A, E, R>(options: {
|
|
36
|
-
readonly acquire: Effect<A, E, R>
|
|
37
|
-
readonly min: number
|
|
38
|
-
readonly max: number
|
|
39
|
-
readonly concurrency?: number | undefined
|
|
40
|
-
readonly targetUtilization?: number | undefined
|
|
41
|
-
readonly strategy: Strategy<A, E>
|
|
42
|
-
}): Effect<Pool<A, E>, never, Scope | R> =>
|
|
43
|
-
core.uninterruptibleMask((restore) =>
|
|
44
|
-
core.flatMap(core.context<R | Scope>(), (context) => {
|
|
45
|
-
const scope = Context.get(context, fiberRuntime.scopeTag)
|
|
46
|
-
const acquire = core.mapInputContext(
|
|
47
|
-
options.acquire,
|
|
48
|
-
(input) => Context.merge(context, input)
|
|
49
|
-
) as Effect<
|
|
50
|
-
A,
|
|
51
|
-
E,
|
|
52
|
-
Scope
|
|
53
|
-
>
|
|
54
|
-
const pool = new PoolImpl<A, E>(
|
|
55
|
-
scope,
|
|
56
|
-
acquire,
|
|
57
|
-
options.concurrency ?? 1,
|
|
58
|
-
options.min,
|
|
59
|
-
options.max,
|
|
60
|
-
options.strategy,
|
|
61
|
-
Math.min(Math.max(options.targetUtilization ?? 1, 0.1), 1)
|
|
62
|
-
)
|
|
63
|
-
const initialize = core.tap(fiberRuntime.forkDaemon(restore(pool.resize)), (fiber) =>
|
|
64
|
-
scope.addFinalizer(() => core.interruptFiber(fiber)))
|
|
65
|
-
const runStrategy = core.tap(fiberRuntime.forkDaemon(restore(options.strategy.run(pool))), (fiber) =>
|
|
66
|
-
scope.addFinalizer(() =>
|
|
67
|
-
core.interruptFiber(fiber)
|
|
68
|
-
))
|
|
69
|
-
return core.succeed(pool).pipe(
|
|
70
|
-
core.zipLeft(scope.addFinalizer(() =>
|
|
71
|
-
pool.shutdown
|
|
72
|
-
)),
|
|
73
|
-
core.zipLeft(initialize),
|
|
74
|
-
core.zipLeft(runStrategy)
|
|
75
|
-
)
|
|
76
|
-
})
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
/** @internal */
|
|
80
|
-
export const make = <A, E, R>(options: {
|
|
81
|
-
readonly acquire: Effect<A, E, R>
|
|
82
|
-
readonly size: number
|
|
83
|
-
readonly concurrency?: number | undefined
|
|
84
|
-
readonly targetUtilization?: number | undefined
|
|
85
|
-
}): Effect<Pool<A, E>, never, R | Scope> =>
|
|
86
|
-
makeWith({ ...options, min: options.size, max: options.size, strategy: strategyNoop() })
|
|
87
|
-
|
|
88
|
-
/** @internal */
|
|
89
|
-
export const makeWithTTL = <A, E, R>(options: {
|
|
90
|
-
readonly acquire: Effect<A, E, R>
|
|
91
|
-
readonly min: number
|
|
92
|
-
readonly max: number
|
|
93
|
-
readonly concurrency?: number | undefined
|
|
94
|
-
readonly targetUtilization?: number | undefined
|
|
95
|
-
readonly timeToLive: Duration.DurationInput
|
|
96
|
-
readonly timeToLiveStrategy?: "creation" | "usage" | undefined
|
|
97
|
-
}): Effect<Pool<A, E>, never, R | Scope> =>
|
|
98
|
-
core.flatMap(
|
|
99
|
-
options.timeToLiveStrategy === "creation" ?
|
|
100
|
-
strategyCreationTTL<A, E>(options.timeToLive) :
|
|
101
|
-
strategyUsageTTL<A, E>(options.timeToLive),
|
|
102
|
-
(strategy) => makeWith({ ...options, strategy })
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
/** @internal */
|
|
106
|
-
export const get = <A, E>(self: Pool<A, E>): Effect<A, E, Scope> => self.get
|
|
107
|
-
|
|
108
|
-
/** @internal */
|
|
109
|
-
export const invalidate: {
|
|
110
|
-
<A>(item: A): <E>(self: Pool<A, E>) => Effect<void>
|
|
111
|
-
<A, E>(self: Pool<A, E>, item: A): Effect<void>
|
|
112
|
-
} = dual(2, <A, E>(self: Pool<A, E>, item: A): Effect<void> => self.invalidate(item))
|
|
113
|
-
|
|
114
|
-
interface PoolItem<A, E> {
|
|
115
|
-
readonly exit: Exit<A, E>
|
|
116
|
-
finalizer: Effect<void>
|
|
117
|
-
refCount: number
|
|
118
|
-
disableReclaim: boolean
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
interface Strategy<A, E> {
|
|
122
|
-
readonly run: (pool: PoolImpl<A, E>) => Effect<void>
|
|
123
|
-
readonly onAcquire: (item: PoolItem<A, E>) => Effect<void>
|
|
124
|
-
readonly reclaim: (pool: PoolImpl<A, E>) => Effect<Option.Option<PoolItem<A, E>>>
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class PoolImpl<A, E> extends Effectable.Class<A, E, Scope> implements Pool<A, E> {
|
|
128
|
-
readonly [PoolTypeId]: Pool.Variance<A, E>[PoolTypeId_]
|
|
129
|
-
|
|
130
|
-
isShuttingDown = false
|
|
131
|
-
readonly semaphore: Semaphore
|
|
132
|
-
readonly items = new Set<PoolItem<A, E>>()
|
|
133
|
-
readonly available = new Set<PoolItem<A, E>>()
|
|
134
|
-
readonly availableLatch = circular.unsafeMakeLatch(false)
|
|
135
|
-
readonly invalidated = new Set<PoolItem<A, E>>()
|
|
136
|
-
waiters = 0
|
|
137
|
-
|
|
138
|
-
constructor(
|
|
139
|
-
readonly scope: Scope,
|
|
140
|
-
readonly acquire: Effect<A, E, Scope>,
|
|
141
|
-
readonly concurrency: number,
|
|
142
|
-
readonly minSize: number,
|
|
143
|
-
readonly maxSize: number,
|
|
144
|
-
readonly strategy: Strategy<A, E>,
|
|
145
|
-
readonly targetUtilization: number
|
|
146
|
-
) {
|
|
147
|
-
super()
|
|
148
|
-
this[PoolTypeId] = poolVariance
|
|
149
|
-
this.semaphore = circular.unsafeMakeSemaphore(concurrency * maxSize)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
readonly allocate: Effect<PoolItem<A, E>> = core.acquireUseRelease(
|
|
153
|
-
fiberRuntime.scopeMake(),
|
|
154
|
-
(scope) =>
|
|
155
|
-
this.acquire.pipe(
|
|
156
|
-
fiberRuntime.scopeExtend(scope),
|
|
157
|
-
core.exit,
|
|
158
|
-
core.flatMap((exit) => {
|
|
159
|
-
const item: PoolItem<A, E> = {
|
|
160
|
-
exit,
|
|
161
|
-
finalizer: core.catchAllCause(scope.close(exit), reportUnhandledError),
|
|
162
|
-
refCount: 0,
|
|
163
|
-
disableReclaim: false
|
|
164
|
-
}
|
|
165
|
-
this.items.add(item)
|
|
166
|
-
this.available.add(item)
|
|
167
|
-
return core.as(
|
|
168
|
-
exit._tag === "Success"
|
|
169
|
-
? this.strategy.onAcquire(item)
|
|
170
|
-
: core.zipRight(item.finalizer, this.strategy.onAcquire(item)),
|
|
171
|
-
item
|
|
172
|
-
)
|
|
173
|
-
})
|
|
174
|
-
),
|
|
175
|
-
(scope, exit) => exit._tag === "Failure" ? scope.close(exit) : core.void
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
get currentUsage() {
|
|
179
|
-
let count = this.waiters
|
|
180
|
-
for (const item of this.items) {
|
|
181
|
-
count += item.refCount
|
|
182
|
-
}
|
|
183
|
-
return count
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
get targetSize() {
|
|
187
|
-
if (this.isShuttingDown) return 0
|
|
188
|
-
const utilization = this.currentUsage / this.targetUtilization
|
|
189
|
-
const target = Math.ceil(utilization / this.concurrency)
|
|
190
|
-
return Math.min(Math.max(this.minSize, target), this.maxSize)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
get activeSize() {
|
|
194
|
-
return this.items.size - this.invalidated.size
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
readonly resizeLoop: Effect<void> = core.suspend(() => {
|
|
198
|
-
if (this.activeSize >= this.targetSize) {
|
|
199
|
-
return core.void
|
|
200
|
-
}
|
|
201
|
-
const toAcquire = this.targetSize - this.activeSize
|
|
202
|
-
return this.strategy.reclaim(this).pipe(
|
|
203
|
-
core.flatMap(Option.match({
|
|
204
|
-
onNone: () => this.allocate,
|
|
205
|
-
onSome: core.succeed
|
|
206
|
-
})),
|
|
207
|
-
fiberRuntime.replicateEffect(toAcquire, { concurrency: toAcquire }),
|
|
208
|
-
core.zipLeft(this.availableLatch.open),
|
|
209
|
-
core.flatMap((items) => items.some((_) => _.exit._tag === "Failure") ? core.void : this.resizeLoop)
|
|
210
|
-
)
|
|
211
|
-
})
|
|
212
|
-
readonly resizeSemaphore = circular.unsafeMakeSemaphore(1)
|
|
213
|
-
readonly resize = this.resizeSemaphore.withPermits(1)(this.resizeLoop)
|
|
214
|
-
|
|
215
|
-
readonly getPoolItem: Effect<PoolItem<A, E>, never, Scope> = core.uninterruptibleMask((restore) =>
|
|
216
|
-
restore(this.semaphore.take(1)).pipe(
|
|
217
|
-
core.zipRight(fiberRuntime.scopeTag),
|
|
218
|
-
core.flatMap((scope) =>
|
|
219
|
-
core.suspend(() => {
|
|
220
|
-
this.waiters++
|
|
221
|
-
if (this.isShuttingDown) {
|
|
222
|
-
return core.interrupt
|
|
223
|
-
} else if (this.targetSize > this.activeSize) {
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
225
|
-
const self = this
|
|
226
|
-
return core.flatMap(
|
|
227
|
-
this.resizeSemaphore.withPermitsIfAvailable(1)(
|
|
228
|
-
circular.forkIn(core.interruptible(this.resize), this.scope)
|
|
229
|
-
),
|
|
230
|
-
function loop(): Effect<PoolItem<A, E>> {
|
|
231
|
-
if (self.isShuttingDown) {
|
|
232
|
-
return core.interrupt
|
|
233
|
-
} else if (self.available.size > 0) {
|
|
234
|
-
return core.succeed(Iterable.unsafeHead(self.available))
|
|
235
|
-
}
|
|
236
|
-
self.availableLatch.unsafeClose()
|
|
237
|
-
return core.flatMap(self.availableLatch.await, loop)
|
|
238
|
-
}
|
|
239
|
-
)
|
|
240
|
-
}
|
|
241
|
-
return core.succeed(Iterable.unsafeHead(this.available))
|
|
242
|
-
}).pipe(
|
|
243
|
-
fiberRuntime.ensuring(core.sync(() => this.waiters--)),
|
|
244
|
-
core.tap((item) => {
|
|
245
|
-
if (item.exit._tag === "Failure") {
|
|
246
|
-
this.items.delete(item)
|
|
247
|
-
this.invalidated.delete(item)
|
|
248
|
-
this.available.delete(item)
|
|
249
|
-
return this.semaphore.release(1)
|
|
250
|
-
}
|
|
251
|
-
item.refCount++
|
|
252
|
-
this.available.delete(item)
|
|
253
|
-
if (item.refCount < this.concurrency) {
|
|
254
|
-
this.available.add(item)
|
|
255
|
-
}
|
|
256
|
-
return scope.addFinalizer(() =>
|
|
257
|
-
core.zipRight(
|
|
258
|
-
core.suspend(() => {
|
|
259
|
-
item.refCount--
|
|
260
|
-
if (this.invalidated.has(item)) {
|
|
261
|
-
return this.invalidatePoolItem(item)
|
|
262
|
-
}
|
|
263
|
-
this.available.add(item)
|
|
264
|
-
return core.exitVoid
|
|
265
|
-
}),
|
|
266
|
-
this.semaphore.release(1)
|
|
267
|
-
)
|
|
268
|
-
)
|
|
269
|
-
}),
|
|
270
|
-
core.onInterrupt(() => this.semaphore.release(1))
|
|
271
|
-
)
|
|
272
|
-
)
|
|
273
|
-
)
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
commit() {
|
|
277
|
-
return this.get
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
readonly get: Effect<A, E, Scope> = core.flatMap(
|
|
281
|
-
core.suspend(() => this.isShuttingDown ? core.interrupt : this.getPoolItem),
|
|
282
|
-
(_) => _.exit
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
invalidate(item: A): Effect<void> {
|
|
286
|
-
return core.suspend(() => {
|
|
287
|
-
if (this.isShuttingDown) return core.void
|
|
288
|
-
for (const poolItem of this.items) {
|
|
289
|
-
if (poolItem.exit._tag === "Success" && poolItem.exit.value === item) {
|
|
290
|
-
poolItem.disableReclaim = true
|
|
291
|
-
return core.uninterruptible(this.invalidatePoolItem(poolItem))
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return core.void
|
|
295
|
-
})
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
invalidatePoolItem(poolItem: PoolItem<A, E>): Effect<void> {
|
|
299
|
-
return core.suspend(() => {
|
|
300
|
-
if (!this.items.has(poolItem)) {
|
|
301
|
-
return core.void
|
|
302
|
-
} else if (poolItem.refCount === 0) {
|
|
303
|
-
this.items.delete(poolItem)
|
|
304
|
-
this.available.delete(poolItem)
|
|
305
|
-
this.invalidated.delete(poolItem)
|
|
306
|
-
return core.zipRight(
|
|
307
|
-
poolItem.finalizer,
|
|
308
|
-
circular.forkIn(core.interruptible(this.resize), this.scope)
|
|
309
|
-
)
|
|
310
|
-
}
|
|
311
|
-
this.invalidated.add(poolItem)
|
|
312
|
-
this.available.delete(poolItem)
|
|
313
|
-
return core.void
|
|
314
|
-
})
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
get shutdown(): Effect<void> {
|
|
318
|
-
return core.suspend(() => {
|
|
319
|
-
if (this.isShuttingDown) return core.void
|
|
320
|
-
this.isShuttingDown = true
|
|
321
|
-
const size = this.items.size
|
|
322
|
-
const semaphore = circular.unsafeMakeSemaphore(size)
|
|
323
|
-
return core.forEachSequentialDiscard(this.items, (item) => {
|
|
324
|
-
if (item.refCount > 0) {
|
|
325
|
-
item.finalizer = core.zipLeft(item.finalizer, semaphore.release(1))
|
|
326
|
-
this.invalidated.add(item)
|
|
327
|
-
return semaphore.take(1)
|
|
328
|
-
}
|
|
329
|
-
this.items.delete(item)
|
|
330
|
-
this.available.delete(item)
|
|
331
|
-
this.invalidated.delete(item)
|
|
332
|
-
return item.finalizer
|
|
333
|
-
}).pipe(
|
|
334
|
-
core.zipRight(this.semaphore.releaseAll),
|
|
335
|
-
core.zipRight(this.availableLatch.open),
|
|
336
|
-
core.zipRight(semaphore.take(size))
|
|
337
|
-
)
|
|
338
|
-
})
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
pipe() {
|
|
342
|
-
return pipeArguments(this, arguments)
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const strategyNoop = <A, E>(): Strategy<A, E> => ({
|
|
347
|
-
run: (_) => core.void,
|
|
348
|
-
onAcquire: (_) => core.void,
|
|
349
|
-
reclaim: (_) => coreEffect.succeedNone
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
const strategyCreationTTL = <A, E>(ttl: Duration.DurationInput) =>
|
|
353
|
-
defaultServices.clockWith((clock) =>
|
|
354
|
-
core.map(internalQueue.unbounded<PoolItem<A, E>>(), (queue) => {
|
|
355
|
-
const ttlMillis = Duration.toMillis(ttl)
|
|
356
|
-
const creationTimes = new WeakMap<PoolItem<A, E>, number>()
|
|
357
|
-
return identity<Strategy<A, E>>({
|
|
358
|
-
run: (pool) => {
|
|
359
|
-
const process = (item: PoolItem<A, E>): Effect<void> =>
|
|
360
|
-
core.suspend(() => {
|
|
361
|
-
if (!pool.items.has(item) || pool.invalidated.has(item)) {
|
|
362
|
-
return core.void
|
|
363
|
-
}
|
|
364
|
-
const now = clock.unsafeCurrentTimeMillis()
|
|
365
|
-
const created = creationTimes.get(item)!
|
|
366
|
-
const remaining = ttlMillis - (now - created)
|
|
367
|
-
return remaining > 0
|
|
368
|
-
? coreEffect.delay(process(item), remaining)
|
|
369
|
-
: pool.invalidatePoolItem(item)
|
|
370
|
-
})
|
|
371
|
-
return queue.take.pipe(
|
|
372
|
-
core.tap(process),
|
|
373
|
-
coreEffect.forever
|
|
374
|
-
)
|
|
375
|
-
},
|
|
376
|
-
onAcquire: (item) =>
|
|
377
|
-
core.suspend(() => {
|
|
378
|
-
creationTimes.set(item, clock.unsafeCurrentTimeMillis())
|
|
379
|
-
return queue.offer(item)
|
|
380
|
-
}),
|
|
381
|
-
reclaim: (_) => coreEffect.succeedNone
|
|
382
|
-
})
|
|
383
|
-
})
|
|
384
|
-
)
|
|
385
|
-
|
|
386
|
-
const strategyUsageTTL = <A, E>(ttl: Duration.DurationInput) =>
|
|
387
|
-
core.map(internalQueue.unbounded<PoolItem<A, E>>(), (queue) => {
|
|
388
|
-
return identity<Strategy<A, E>>({
|
|
389
|
-
run: (pool) => {
|
|
390
|
-
const process: Effect<void> = core.suspend(() => {
|
|
391
|
-
const excess = pool.activeSize - pool.targetSize
|
|
392
|
-
if (excess <= 0) return core.void
|
|
393
|
-
return queue.take.pipe(
|
|
394
|
-
core.tap((item) => pool.invalidatePoolItem(item)),
|
|
395
|
-
core.zipRight(process)
|
|
396
|
-
)
|
|
397
|
-
})
|
|
398
|
-
return process.pipe(
|
|
399
|
-
coreEffect.delay(ttl),
|
|
400
|
-
coreEffect.forever
|
|
401
|
-
)
|
|
402
|
-
},
|
|
403
|
-
onAcquire: (item) => queue.offer(item),
|
|
404
|
-
reclaim(pool) {
|
|
405
|
-
return core.suspend((): Effect<Option.Option<PoolItem<A, E>>> => {
|
|
406
|
-
if (pool.invalidated.size === 0) {
|
|
407
|
-
return coreEffect.succeedNone
|
|
408
|
-
}
|
|
409
|
-
const item = Iterable.head(
|
|
410
|
-
Iterable.filter(pool.invalidated, (item) => !item.disableReclaim)
|
|
411
|
-
)
|
|
412
|
-
if (item._tag === "None") {
|
|
413
|
-
return coreEffect.succeedNone
|
|
414
|
-
}
|
|
415
|
-
pool.invalidated.delete(item.value)
|
|
416
|
-
if (item.value.refCount < pool.concurrency) {
|
|
417
|
-
pool.available.add(item.value)
|
|
418
|
-
}
|
|
419
|
-
return core.as(queue.offer(item.value), item)
|
|
420
|
-
})
|
|
421
|
-
}
|
|
422
|
-
})
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
const reportUnhandledError = <E>(cause: Cause<E>) =>
|
|
426
|
-
core.withFiberRuntime<void>((fiber) => {
|
|
427
|
-
const unhandledLogLevel = fiber.getFiberRef(core.currentUnhandledErrorLogLevel)
|
|
428
|
-
if (unhandledLogLevel._tag === "Some") {
|
|
429
|
-
fiber.log("Unhandled error in pool finalizer", cause, unhandledLogLevel)
|
|
430
|
-
}
|
|
431
|
-
return core.void
|
|
432
|
-
})
|