@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/mailbox.ts
DELETED
|
@@ -1,561 +0,0 @@
|
|
|
1
|
-
import * as Arr from "../Array.js"
|
|
2
|
-
import type { Cause } from "../Cause.js"
|
|
3
|
-
import { NoSuchElementException } from "../Cause.js"
|
|
4
|
-
import type { Channel } from "../Channel.js"
|
|
5
|
-
import * as Chunk from "../Chunk.js"
|
|
6
|
-
import type { Effect } from "../Effect.js"
|
|
7
|
-
import * as Effectable from "../Effectable.js"
|
|
8
|
-
import type { Exit } from "../Exit.js"
|
|
9
|
-
import { dual } from "../Function.js"
|
|
10
|
-
import * as Inspectable from "../Inspectable.js"
|
|
11
|
-
import type * as Api from "../Mailbox.js"
|
|
12
|
-
import * as Option from "../Option.js"
|
|
13
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
14
|
-
import { hasProperty } from "../Predicate.js"
|
|
15
|
-
import type { Scheduler } from "../Scheduler.js"
|
|
16
|
-
import type { Scope } from "../Scope.js"
|
|
17
|
-
import type { Stream } from "../Stream.js"
|
|
18
|
-
import * as channel from "./channel.js"
|
|
19
|
-
import * as channelExecutor from "./channel/channelExecutor.js"
|
|
20
|
-
import * as coreChannel from "./core-stream.js"
|
|
21
|
-
import * as core from "./core.js"
|
|
22
|
-
import * as circular from "./effect/circular.js"
|
|
23
|
-
import * as fiberRuntime from "./fiberRuntime.js"
|
|
24
|
-
import * as stream from "./stream.js"
|
|
25
|
-
|
|
26
|
-
/** @internal */
|
|
27
|
-
export const TypeId: Api.TypeId = Symbol.for("effect/Mailbox") as Api.TypeId
|
|
28
|
-
|
|
29
|
-
/** @internal */
|
|
30
|
-
export const ReadonlyTypeId: Api.ReadonlyTypeId = Symbol.for("effect/Mailbox/ReadonlyMailbox") as Api.ReadonlyTypeId
|
|
31
|
-
|
|
32
|
-
/** @internal */
|
|
33
|
-
export const isMailbox = (u: unknown): u is Api.Mailbox<unknown, unknown> => hasProperty(u, TypeId)
|
|
34
|
-
|
|
35
|
-
/** @internal */
|
|
36
|
-
export const isReadonlyMailbox = (u: unknown): u is Api.ReadonlyMailbox<unknown, unknown> =>
|
|
37
|
-
hasProperty(u, ReadonlyTypeId)
|
|
38
|
-
|
|
39
|
-
type MailboxState<A, E> = {
|
|
40
|
-
readonly _tag: "Open"
|
|
41
|
-
readonly takers: Set<(_: Effect<void, E>) => void>
|
|
42
|
-
readonly offers: Set<OfferEntry<A>>
|
|
43
|
-
readonly awaiters: Set<(_: Effect<void, E>) => void>
|
|
44
|
-
} | {
|
|
45
|
-
readonly _tag: "Closing"
|
|
46
|
-
readonly takers: Set<(_: Effect<void, E>) => void>
|
|
47
|
-
readonly offers: Set<OfferEntry<A>>
|
|
48
|
-
readonly awaiters: Set<(_: Effect<void, E>) => void>
|
|
49
|
-
readonly exit: Exit<void, E>
|
|
50
|
-
} | {
|
|
51
|
-
readonly _tag: "Done"
|
|
52
|
-
readonly exit: Exit<void, E>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type OfferEntry<A> = {
|
|
56
|
-
readonly _tag: "Array"
|
|
57
|
-
readonly remaining: Array<A>
|
|
58
|
-
offset: number
|
|
59
|
-
readonly resume: (_: Effect<Chunk.Chunk<A>>) => void
|
|
60
|
-
} | {
|
|
61
|
-
readonly _tag: "Single"
|
|
62
|
-
readonly message: A
|
|
63
|
-
readonly resume: (_: Effect<boolean>) => void
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const empty = Chunk.empty()
|
|
67
|
-
const exitEmpty = core.exitSucceed(empty)
|
|
68
|
-
const exitFalse = core.exitSucceed(false)
|
|
69
|
-
const exitTrue = core.exitSucceed(true)
|
|
70
|
-
const constDone = [empty, true] as const
|
|
71
|
-
|
|
72
|
-
class MailboxImpl<A, E> extends Effectable.Class<readonly [messages: Chunk.Chunk<A>, done: boolean], E>
|
|
73
|
-
implements Api.Mailbox<A, E>
|
|
74
|
-
{
|
|
75
|
-
readonly [TypeId]: Api.TypeId = TypeId
|
|
76
|
-
readonly [ReadonlyTypeId]: Api.ReadonlyTypeId = ReadonlyTypeId
|
|
77
|
-
private state: MailboxState<A, E> = {
|
|
78
|
-
_tag: "Open",
|
|
79
|
-
takers: new Set(),
|
|
80
|
-
offers: new Set(),
|
|
81
|
-
awaiters: new Set()
|
|
82
|
-
}
|
|
83
|
-
private messages: Array<A> = []
|
|
84
|
-
private messagesChunk = Chunk.empty<A>()
|
|
85
|
-
constructor(
|
|
86
|
-
readonly scheduler: Scheduler,
|
|
87
|
-
private capacity: number,
|
|
88
|
-
readonly strategy: "suspend" | "dropping" | "sliding"
|
|
89
|
-
) {
|
|
90
|
-
super()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
offer(message: A): Effect<boolean> {
|
|
94
|
-
return core.suspend(() => {
|
|
95
|
-
if (this.state._tag !== "Open") {
|
|
96
|
-
return exitFalse
|
|
97
|
-
} else if (this.messages.length + this.messagesChunk.length >= this.capacity) {
|
|
98
|
-
switch (this.strategy) {
|
|
99
|
-
case "dropping":
|
|
100
|
-
return exitFalse
|
|
101
|
-
case "suspend":
|
|
102
|
-
if (this.capacity <= 0 && this.state.takers.size > 0) {
|
|
103
|
-
this.messages.push(message)
|
|
104
|
-
this.releaseTaker()
|
|
105
|
-
return exitTrue
|
|
106
|
-
}
|
|
107
|
-
return this.offerRemainingSingle(message)
|
|
108
|
-
case "sliding":
|
|
109
|
-
this.unsafeTake()
|
|
110
|
-
this.messages.push(message)
|
|
111
|
-
return exitTrue
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
this.messages.push(message)
|
|
115
|
-
this.scheduleReleaseTaker()
|
|
116
|
-
return exitTrue
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
unsafeOffer(message: A): boolean {
|
|
120
|
-
if (this.state._tag !== "Open") {
|
|
121
|
-
return false
|
|
122
|
-
} else if (this.messages.length + this.messagesChunk.length >= this.capacity) {
|
|
123
|
-
if (this.strategy === "sliding") {
|
|
124
|
-
this.unsafeTake()
|
|
125
|
-
this.messages.push(message)
|
|
126
|
-
return true
|
|
127
|
-
} else if (this.capacity <= 0 && this.state.takers.size > 0) {
|
|
128
|
-
this.messages.push(message)
|
|
129
|
-
this.releaseTaker()
|
|
130
|
-
return true
|
|
131
|
-
}
|
|
132
|
-
return false
|
|
133
|
-
}
|
|
134
|
-
this.messages.push(message)
|
|
135
|
-
this.scheduleReleaseTaker()
|
|
136
|
-
return true
|
|
137
|
-
}
|
|
138
|
-
offerAll(messages: Iterable<A>): Effect<Chunk.Chunk<A>> {
|
|
139
|
-
return core.suspend(() => {
|
|
140
|
-
if (this.state._tag !== "Open") {
|
|
141
|
-
return core.succeed(Chunk.fromIterable(messages))
|
|
142
|
-
}
|
|
143
|
-
const remaining = this.unsafeOfferAllArray(messages)
|
|
144
|
-
if (remaining.length === 0) {
|
|
145
|
-
return exitEmpty
|
|
146
|
-
} else if (this.strategy === "dropping") {
|
|
147
|
-
return core.succeed(Chunk.unsafeFromArray(remaining))
|
|
148
|
-
}
|
|
149
|
-
return this.offerRemainingArray(remaining)
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
unsafeOfferAll(messages: Iterable<A>): Chunk.Chunk<A> {
|
|
153
|
-
return Chunk.unsafeFromArray(this.unsafeOfferAllArray(messages))
|
|
154
|
-
}
|
|
155
|
-
unsafeOfferAllArray(messages: Iterable<A>): Array<A> {
|
|
156
|
-
if (this.state._tag !== "Open") {
|
|
157
|
-
return Arr.fromIterable(messages)
|
|
158
|
-
} else if (this.capacity === Number.POSITIVE_INFINITY || this.strategy === "sliding") {
|
|
159
|
-
if (this.messages.length > 0) {
|
|
160
|
-
this.messagesChunk = Chunk.appendAll(this.messagesChunk, Chunk.unsafeFromArray(this.messages))
|
|
161
|
-
}
|
|
162
|
-
if (this.strategy === "sliding") {
|
|
163
|
-
this.messagesChunk = this.messagesChunk.pipe(
|
|
164
|
-
Chunk.appendAll(Chunk.fromIterable(messages)),
|
|
165
|
-
Chunk.takeRight(this.capacity)
|
|
166
|
-
)
|
|
167
|
-
} else if (Chunk.isChunk(messages)) {
|
|
168
|
-
this.messagesChunk = Chunk.appendAll(this.messagesChunk, messages)
|
|
169
|
-
} else {
|
|
170
|
-
this.messages = Arr.fromIterable(messages)
|
|
171
|
-
}
|
|
172
|
-
this.scheduleReleaseTaker()
|
|
173
|
-
return []
|
|
174
|
-
}
|
|
175
|
-
const free = this.capacity <= 0
|
|
176
|
-
? this.state.takers.size
|
|
177
|
-
: this.capacity - this.messages.length - this.messagesChunk.length
|
|
178
|
-
if (free === 0) {
|
|
179
|
-
return Arr.fromIterable(messages)
|
|
180
|
-
}
|
|
181
|
-
const remaining: Array<A> = []
|
|
182
|
-
let i = 0
|
|
183
|
-
for (const message of messages) {
|
|
184
|
-
if (i < free) {
|
|
185
|
-
this.messages.push(message)
|
|
186
|
-
} else {
|
|
187
|
-
remaining.push(message)
|
|
188
|
-
}
|
|
189
|
-
i++
|
|
190
|
-
}
|
|
191
|
-
this.scheduleReleaseTaker()
|
|
192
|
-
return remaining
|
|
193
|
-
}
|
|
194
|
-
fail(error: E) {
|
|
195
|
-
return this.done(core.exitFail(error))
|
|
196
|
-
}
|
|
197
|
-
failCause(cause: Cause<E>) {
|
|
198
|
-
return this.done(core.exitFailCause(cause))
|
|
199
|
-
}
|
|
200
|
-
unsafeDone(exit: Exit<void, E>): boolean {
|
|
201
|
-
if (this.state._tag !== "Open") {
|
|
202
|
-
return false
|
|
203
|
-
} else if (this.state.offers.size === 0 && this.messages.length === 0 && this.messagesChunk.length === 0) {
|
|
204
|
-
this.finalize(exit)
|
|
205
|
-
return true
|
|
206
|
-
}
|
|
207
|
-
this.state = { ...this.state, _tag: "Closing", exit }
|
|
208
|
-
return true
|
|
209
|
-
}
|
|
210
|
-
shutdown: Effect<boolean> = core.sync(() => {
|
|
211
|
-
if (this.state._tag === "Done") {
|
|
212
|
-
return true
|
|
213
|
-
}
|
|
214
|
-
this.messages = []
|
|
215
|
-
this.messagesChunk = empty
|
|
216
|
-
const offers = this.state.offers
|
|
217
|
-
this.finalize(this.state._tag === "Open" ? core.exitVoid : this.state.exit)
|
|
218
|
-
if (offers.size > 0) {
|
|
219
|
-
for (const entry of offers) {
|
|
220
|
-
if (entry._tag === "Single") {
|
|
221
|
-
entry.resume(exitFalse)
|
|
222
|
-
} else {
|
|
223
|
-
entry.resume(core.exitSucceed(Chunk.unsafeFromArray(entry.remaining.slice(entry.offset))))
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
offers.clear()
|
|
227
|
-
}
|
|
228
|
-
return true
|
|
229
|
-
})
|
|
230
|
-
done(exit: Exit<void, E>) {
|
|
231
|
-
return core.sync(() => this.unsafeDone(exit))
|
|
232
|
-
}
|
|
233
|
-
end = this.done(core.exitVoid)
|
|
234
|
-
clear: Effect<Chunk.Chunk<A>, E> = core.suspend(() => {
|
|
235
|
-
if (this.state._tag === "Done") {
|
|
236
|
-
return core.exitAs(this.state.exit, empty)
|
|
237
|
-
}
|
|
238
|
-
const messages = this.unsafeTakeAll()
|
|
239
|
-
this.releaseCapacity()
|
|
240
|
-
return core.succeed(messages)
|
|
241
|
-
})
|
|
242
|
-
takeAll: Effect<readonly [messages: Chunk.Chunk<A>, done: boolean], E> = core.suspend(() => {
|
|
243
|
-
if (this.state._tag === "Done") {
|
|
244
|
-
return core.exitAs(this.state.exit, constDone)
|
|
245
|
-
}
|
|
246
|
-
const messages = this.unsafeTakeAll()
|
|
247
|
-
if (messages.length === 0) {
|
|
248
|
-
return core.zipRight(this.awaitTake, this.takeAll)
|
|
249
|
-
}
|
|
250
|
-
return core.succeed([messages, this.releaseCapacity()])
|
|
251
|
-
})
|
|
252
|
-
takeN(n: number): Effect<readonly [messages: Chunk.Chunk<A>, done: boolean], E> {
|
|
253
|
-
return core.suspend(() => {
|
|
254
|
-
if (this.state._tag === "Done") {
|
|
255
|
-
return core.exitAs(this.state.exit, constDone)
|
|
256
|
-
} else if (n <= 0) {
|
|
257
|
-
return core.succeed([empty, false])
|
|
258
|
-
}
|
|
259
|
-
n = Math.min(n, this.capacity)
|
|
260
|
-
let messages: Chunk.Chunk<A>
|
|
261
|
-
if (n <= this.messagesChunk.length) {
|
|
262
|
-
messages = Chunk.take(this.messagesChunk, n)
|
|
263
|
-
this.messagesChunk = Chunk.drop(this.messagesChunk, n)
|
|
264
|
-
} else if (n <= this.messages.length + this.messagesChunk.length) {
|
|
265
|
-
this.messagesChunk = Chunk.appendAll(this.messagesChunk, Chunk.unsafeFromArray(this.messages))
|
|
266
|
-
this.messages = []
|
|
267
|
-
messages = Chunk.take(this.messagesChunk, n)
|
|
268
|
-
this.messagesChunk = Chunk.drop(this.messagesChunk, n)
|
|
269
|
-
} else {
|
|
270
|
-
return core.zipRight(this.awaitTake, this.takeN(n))
|
|
271
|
-
}
|
|
272
|
-
return core.succeed([messages, this.releaseCapacity()])
|
|
273
|
-
})
|
|
274
|
-
}
|
|
275
|
-
unsafeTake(): Exit<A, E | NoSuchElementException> | undefined {
|
|
276
|
-
if (this.state._tag === "Done") {
|
|
277
|
-
return core.exitZipRight(this.state.exit, core.exitFail(new NoSuchElementException()))
|
|
278
|
-
}
|
|
279
|
-
let message: A
|
|
280
|
-
if (this.messagesChunk.length > 0) {
|
|
281
|
-
message = Chunk.unsafeHead(this.messagesChunk)
|
|
282
|
-
this.messagesChunk = Chunk.drop(this.messagesChunk, 1)
|
|
283
|
-
} else if (this.messages.length > 0) {
|
|
284
|
-
message = this.messages[0]
|
|
285
|
-
this.messagesChunk = Chunk.drop(Chunk.unsafeFromArray(this.messages), 1)
|
|
286
|
-
this.messages = []
|
|
287
|
-
} else if (this.capacity <= 0 && this.state.offers.size > 0) {
|
|
288
|
-
this.capacity = 1
|
|
289
|
-
this.releaseCapacity()
|
|
290
|
-
this.capacity = 0
|
|
291
|
-
return this.messages.length > 0 ? core.exitSucceed(this.messages.pop()!) : undefined
|
|
292
|
-
} else {
|
|
293
|
-
return undefined
|
|
294
|
-
}
|
|
295
|
-
this.releaseCapacity()
|
|
296
|
-
return core.exitSucceed(message)
|
|
297
|
-
}
|
|
298
|
-
take: Effect<A, E | NoSuchElementException> = core.suspend(() =>
|
|
299
|
-
this.unsafeTake() ?? core.zipRight(this.awaitTake, this.take)
|
|
300
|
-
)
|
|
301
|
-
await: Effect<void, E> = core.asyncInterrupt<void, E>((resume) => {
|
|
302
|
-
if (this.state._tag === "Done") {
|
|
303
|
-
return resume(this.state.exit)
|
|
304
|
-
}
|
|
305
|
-
this.state.awaiters.add(resume)
|
|
306
|
-
return core.sync(() => {
|
|
307
|
-
if (this.state._tag !== "Done") {
|
|
308
|
-
this.state.awaiters.delete(resume)
|
|
309
|
-
}
|
|
310
|
-
})
|
|
311
|
-
})
|
|
312
|
-
unsafeSize(): Option.Option<number> {
|
|
313
|
-
const size = this.messages.length + this.messagesChunk.length
|
|
314
|
-
return this.state._tag === "Done" ? Option.none() : Option.some(size)
|
|
315
|
-
}
|
|
316
|
-
size = core.sync(() => this.unsafeSize())
|
|
317
|
-
|
|
318
|
-
commit() {
|
|
319
|
-
return this.takeAll
|
|
320
|
-
}
|
|
321
|
-
pipe() {
|
|
322
|
-
return pipeArguments(this, arguments)
|
|
323
|
-
}
|
|
324
|
-
toJSON() {
|
|
325
|
-
return {
|
|
326
|
-
_id: "effect/Mailbox",
|
|
327
|
-
state: this.state._tag,
|
|
328
|
-
size: this.unsafeSize().toJSON()
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
toString(): string {
|
|
332
|
-
return Inspectable.format(this)
|
|
333
|
-
}
|
|
334
|
-
[Inspectable.NodeInspectSymbol]() {
|
|
335
|
-
return Inspectable.format(this)
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private offerRemainingSingle(message: A) {
|
|
339
|
-
return core.asyncInterrupt<boolean>((resume) => {
|
|
340
|
-
if (this.state._tag !== "Open") {
|
|
341
|
-
return resume(exitFalse)
|
|
342
|
-
}
|
|
343
|
-
const entry: OfferEntry<A> = { _tag: "Single", message, resume }
|
|
344
|
-
this.state.offers.add(entry)
|
|
345
|
-
return core.sync(() => {
|
|
346
|
-
if (this.state._tag === "Open") {
|
|
347
|
-
this.state.offers.delete(entry)
|
|
348
|
-
}
|
|
349
|
-
})
|
|
350
|
-
})
|
|
351
|
-
}
|
|
352
|
-
private offerRemainingArray(remaining: Array<A>) {
|
|
353
|
-
return core.asyncInterrupt<Chunk.Chunk<A>>((resume) => {
|
|
354
|
-
if (this.state._tag !== "Open") {
|
|
355
|
-
return resume(core.exitSucceed(Chunk.unsafeFromArray(remaining)))
|
|
356
|
-
}
|
|
357
|
-
const entry: OfferEntry<A> = { _tag: "Array", remaining, offset: 0, resume }
|
|
358
|
-
this.state.offers.add(entry)
|
|
359
|
-
return core.sync(() => {
|
|
360
|
-
if (this.state._tag === "Open") {
|
|
361
|
-
this.state.offers.delete(entry)
|
|
362
|
-
}
|
|
363
|
-
})
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
private releaseCapacity(): boolean {
|
|
367
|
-
if (this.state._tag === "Done") {
|
|
368
|
-
return this.state.exit._tag === "Success"
|
|
369
|
-
} else if (this.state.offers.size === 0) {
|
|
370
|
-
if (this.state._tag === "Closing" && this.messages.length === 0 && this.messagesChunk.length === 0) {
|
|
371
|
-
this.finalize(this.state.exit)
|
|
372
|
-
return this.state.exit._tag === "Success"
|
|
373
|
-
}
|
|
374
|
-
return false
|
|
375
|
-
}
|
|
376
|
-
let n = this.capacity - this.messages.length - this.messagesChunk.length
|
|
377
|
-
for (const entry of this.state.offers) {
|
|
378
|
-
if (n === 0) return false
|
|
379
|
-
else if (entry._tag === "Single") {
|
|
380
|
-
this.messages.push(entry.message)
|
|
381
|
-
n--
|
|
382
|
-
entry.resume(exitTrue)
|
|
383
|
-
this.state.offers.delete(entry)
|
|
384
|
-
} else {
|
|
385
|
-
for (; entry.offset < entry.remaining.length; entry.offset++) {
|
|
386
|
-
if (n === 0) return false
|
|
387
|
-
this.messages.push(entry.remaining[entry.offset])
|
|
388
|
-
n--
|
|
389
|
-
}
|
|
390
|
-
entry.resume(exitEmpty)
|
|
391
|
-
this.state.offers.delete(entry)
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return false
|
|
395
|
-
}
|
|
396
|
-
private awaitTake = core.asyncInterrupt<void, E>((resume) => {
|
|
397
|
-
if (this.state._tag === "Done") {
|
|
398
|
-
return resume(this.state.exit)
|
|
399
|
-
}
|
|
400
|
-
this.state.takers.add(resume)
|
|
401
|
-
return core.sync(() => {
|
|
402
|
-
if (this.state._tag !== "Done") {
|
|
403
|
-
this.state.takers.delete(resume)
|
|
404
|
-
}
|
|
405
|
-
})
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
private scheduleRunning = false
|
|
409
|
-
private scheduleReleaseTaker() {
|
|
410
|
-
if (this.scheduleRunning) {
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
this.scheduleRunning = true
|
|
414
|
-
this.scheduler.scheduleTask(this.releaseTaker, 0)
|
|
415
|
-
}
|
|
416
|
-
private releaseTaker = () => {
|
|
417
|
-
this.scheduleRunning = false
|
|
418
|
-
if (this.state._tag === "Done") {
|
|
419
|
-
return
|
|
420
|
-
} else if (this.state.takers.size === 0) {
|
|
421
|
-
return
|
|
422
|
-
}
|
|
423
|
-
for (const taker of this.state.takers) {
|
|
424
|
-
this.state.takers.delete(taker)
|
|
425
|
-
taker(core.exitVoid)
|
|
426
|
-
if (this.messages.length + this.messagesChunk.length === 0) {
|
|
427
|
-
break
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
private unsafeTakeAll() {
|
|
433
|
-
if (this.messagesChunk.length > 0) {
|
|
434
|
-
const messages = this.messages.length > 0 ?
|
|
435
|
-
Chunk.appendAll(this.messagesChunk, Chunk.unsafeFromArray(this.messages)) :
|
|
436
|
-
this.messagesChunk
|
|
437
|
-
this.messagesChunk = empty
|
|
438
|
-
this.messages = []
|
|
439
|
-
return messages
|
|
440
|
-
} else if (this.messages.length > 0) {
|
|
441
|
-
const messages = Chunk.unsafeFromArray(this.messages)
|
|
442
|
-
this.messages = []
|
|
443
|
-
return messages
|
|
444
|
-
} else if (this.state._tag !== "Done" && this.state.offers.size > 0) {
|
|
445
|
-
this.capacity = 1
|
|
446
|
-
this.releaseCapacity()
|
|
447
|
-
this.capacity = 0
|
|
448
|
-
return Chunk.of(this.messages.pop()!)
|
|
449
|
-
}
|
|
450
|
-
return empty
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
private finalize(exit: Exit<void, E>) {
|
|
454
|
-
if (this.state._tag === "Done") {
|
|
455
|
-
return
|
|
456
|
-
}
|
|
457
|
-
const openState = this.state
|
|
458
|
-
this.state = { _tag: "Done", exit }
|
|
459
|
-
for (const taker of openState.takers) {
|
|
460
|
-
taker(exit)
|
|
461
|
-
}
|
|
462
|
-
openState.takers.clear()
|
|
463
|
-
for (const awaiter of openState.awaiters) {
|
|
464
|
-
awaiter(exit)
|
|
465
|
-
}
|
|
466
|
-
openState.awaiters.clear()
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/** @internal */
|
|
471
|
-
export const make = <A, E = never>(
|
|
472
|
-
capacity?: number | {
|
|
473
|
-
readonly capacity?: number | undefined
|
|
474
|
-
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
|
475
|
-
} | undefined
|
|
476
|
-
): Effect<Api.Mailbox<A, E>> =>
|
|
477
|
-
core.withFiberRuntime((fiber) =>
|
|
478
|
-
core.succeed(
|
|
479
|
-
new MailboxImpl<A, E>(
|
|
480
|
-
fiber.currentScheduler,
|
|
481
|
-
typeof capacity === "number" ? capacity : capacity?.capacity ?? Number.POSITIVE_INFINITY,
|
|
482
|
-
typeof capacity === "number" ? "suspend" : capacity?.strategy ?? "suspend"
|
|
483
|
-
)
|
|
484
|
-
)
|
|
485
|
-
)
|
|
486
|
-
|
|
487
|
-
/** @internal */
|
|
488
|
-
export const into: {
|
|
489
|
-
<A, E>(
|
|
490
|
-
self: Api.Mailbox<A, E>
|
|
491
|
-
): <AX, EX extends E, RX>(effect: Effect<AX, EX, RX>) => Effect<boolean, never, RX>
|
|
492
|
-
<AX, E, EX extends E, RX, A>(
|
|
493
|
-
effect: Effect<AX, EX, RX>,
|
|
494
|
-
self: Api.Mailbox<A, E>
|
|
495
|
-
): Effect<boolean, never, RX>
|
|
496
|
-
} = dual(
|
|
497
|
-
2,
|
|
498
|
-
<AX, E, EX extends E, RX, A>(
|
|
499
|
-
effect: Effect<AX, EX, RX>,
|
|
500
|
-
self: Api.Mailbox<A, E>
|
|
501
|
-
): Effect<boolean, never, RX> =>
|
|
502
|
-
core.uninterruptibleMask((restore) =>
|
|
503
|
-
core.matchCauseEffect(restore(effect), {
|
|
504
|
-
onFailure: (cause) => self.failCause(cause),
|
|
505
|
-
onSuccess: (_) => self.end
|
|
506
|
-
})
|
|
507
|
-
)
|
|
508
|
-
)
|
|
509
|
-
|
|
510
|
-
/** @internal */
|
|
511
|
-
export const toChannel = <A, E>(self: Api.ReadonlyMailbox<A, E>): Channel<Chunk.Chunk<A>, unknown, E> => {
|
|
512
|
-
const loop: Channel<Chunk.Chunk<A>, unknown, E> = coreChannel.flatMap(self.takeAll, ([messages, done]) =>
|
|
513
|
-
done
|
|
514
|
-
? messages.length === 0 ? coreChannel.void : coreChannel.write(messages)
|
|
515
|
-
: channel.zipRight(coreChannel.write(messages), loop))
|
|
516
|
-
return loop
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/** @internal */
|
|
520
|
-
export const toStream = <A, E>(self: Api.ReadonlyMailbox<A, E>): Stream<A, E> => stream.fromChannel(toChannel(self))
|
|
521
|
-
|
|
522
|
-
/** @internal */
|
|
523
|
-
export const fromStream: {
|
|
524
|
-
(options?: {
|
|
525
|
-
readonly capacity?: number | undefined
|
|
526
|
-
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
|
527
|
-
}): <A, E, R>(self: Stream<A, E, R>) => Effect<Api.ReadonlyMailbox<A, E>, never, R | Scope>
|
|
528
|
-
<A, E, R>(
|
|
529
|
-
self: Stream<A, E, R>,
|
|
530
|
-
options?: {
|
|
531
|
-
readonly capacity?: number | undefined
|
|
532
|
-
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
|
533
|
-
}
|
|
534
|
-
): Effect<Api.ReadonlyMailbox<A, E>, never, R | Scope>
|
|
535
|
-
} = dual((args) => stream.isStream(args[0]), <A, E, R>(
|
|
536
|
-
self: Stream<A, E, R>,
|
|
537
|
-
options?: {
|
|
538
|
-
readonly capacity?: number | undefined
|
|
539
|
-
readonly strategy?: "suspend" | "dropping" | "sliding" | undefined
|
|
540
|
-
}
|
|
541
|
-
): Effect<Api.ReadonlyMailbox<A, E>, never, R | Scope> =>
|
|
542
|
-
core.tap(
|
|
543
|
-
fiberRuntime.acquireRelease(
|
|
544
|
-
make<A, E>(options),
|
|
545
|
-
(mailbox) => mailbox.shutdown
|
|
546
|
-
),
|
|
547
|
-
(mailbox) => {
|
|
548
|
-
const writer: Channel<never, Chunk.Chunk<A>, never, E> = coreChannel.readWithCause({
|
|
549
|
-
onInput: (input: Chunk.Chunk<A>) => coreChannel.flatMap(mailbox.offerAll(input), () => writer),
|
|
550
|
-
onFailure: (cause: Cause<E>) => mailbox.failCause(cause),
|
|
551
|
-
onDone: () => mailbox.end
|
|
552
|
-
})
|
|
553
|
-
return fiberRuntime.scopeWith((scope) =>
|
|
554
|
-
stream.toChannel(self).pipe(
|
|
555
|
-
coreChannel.pipeTo(writer),
|
|
556
|
-
channelExecutor.runIn(scope),
|
|
557
|
-
circular.forkIn(scope)
|
|
558
|
-
)
|
|
559
|
-
)
|
|
560
|
-
}
|
|
561
|
-
))
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type * as Effect from "../Effect.js"
|
|
2
|
-
import * as Effectable from "../Effectable.js"
|
|
3
|
-
import type { Exit } from "../Exit.js"
|
|
4
|
-
import type * as Fiber from "../Fiber.js"
|
|
5
|
-
import type * as Layer from "../Layer.js"
|
|
6
|
-
import type * as M from "../ManagedRuntime.js"
|
|
7
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
8
|
-
import { hasProperty } from "../Predicate.js"
|
|
9
|
-
import type * as Runtime from "../Runtime.js"
|
|
10
|
-
import * as Scope from "../Scope.js"
|
|
11
|
-
import type { Mutable } from "../Types.js"
|
|
12
|
-
import * as core from "./core.js"
|
|
13
|
-
import * as fiberRuntime from "./fiberRuntime.js"
|
|
14
|
-
import * as internalLayer from "./layer.js"
|
|
15
|
-
import * as circular from "./managedRuntime/circular.js"
|
|
16
|
-
import * as internalRuntime from "./runtime.js"
|
|
17
|
-
|
|
18
|
-
interface ManagedRuntimeImpl<R, E> extends M.ManagedRuntime<R, E> {
|
|
19
|
-
readonly scope: Scope.CloseableScope
|
|
20
|
-
cachedRuntime: Runtime.Runtime<R> | undefined
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** @internal */
|
|
24
|
-
export const isManagedRuntime = (u: unknown): u is M.ManagedRuntime<unknown, unknown> => hasProperty(u, circular.TypeId)
|
|
25
|
-
|
|
26
|
-
function provide<R, ER, A, E>(
|
|
27
|
-
managed: ManagedRuntimeImpl<R, ER>,
|
|
28
|
-
effect: Effect.Effect<A, E, R>
|
|
29
|
-
): Effect.Effect<A, E | ER> {
|
|
30
|
-
return core.flatMap(
|
|
31
|
-
managed.runtimeEffect,
|
|
32
|
-
(rt) =>
|
|
33
|
-
core.withFiberRuntime((fiber) => {
|
|
34
|
-
fiber.setFiberRefs(rt.fiberRefs)
|
|
35
|
-
fiber.currentRuntimeFlags = rt.runtimeFlags
|
|
36
|
-
return core.provideContext(effect, rt.context)
|
|
37
|
-
})
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const ManagedRuntimeProto = {
|
|
42
|
-
...Effectable.CommitPrototype,
|
|
43
|
-
[circular.TypeId]: circular.TypeId,
|
|
44
|
-
pipe() {
|
|
45
|
-
return pipeArguments(this, arguments)
|
|
46
|
-
},
|
|
47
|
-
commit(this: ManagedRuntimeImpl<unknown, unknown>) {
|
|
48
|
-
return this.runtimeEffect
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @internal */
|
|
53
|
-
export const make = <R, ER>(
|
|
54
|
-
layer: Layer.Layer<R, ER, never>,
|
|
55
|
-
memoMap?: Layer.MemoMap
|
|
56
|
-
): M.ManagedRuntime<R, ER> => {
|
|
57
|
-
memoMap = memoMap ?? internalLayer.unsafeMakeMemoMap()
|
|
58
|
-
const scope = internalRuntime.unsafeRunSyncEffect(fiberRuntime.scopeMake())
|
|
59
|
-
let buildFiber: Fiber.RuntimeFiber<Runtime.Runtime<R>, ER> | undefined
|
|
60
|
-
const runtimeEffect = core.withFiberRuntime<Runtime.Runtime<R>, ER>((fiber) => {
|
|
61
|
-
if (!buildFiber) {
|
|
62
|
-
buildFiber = internalRuntime.unsafeForkEffect(
|
|
63
|
-
core.tap(
|
|
64
|
-
Scope.extend(
|
|
65
|
-
internalLayer.toRuntimeWithMemoMap(layer, memoMap),
|
|
66
|
-
scope
|
|
67
|
-
),
|
|
68
|
-
(rt) => {
|
|
69
|
-
self.cachedRuntime = rt
|
|
70
|
-
}
|
|
71
|
-
),
|
|
72
|
-
{ scope, scheduler: fiber.currentScheduler }
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
return core.flatten(buildFiber.await)
|
|
76
|
-
})
|
|
77
|
-
const self: ManagedRuntimeImpl<R, ER> = Object.assign(Object.create(ManagedRuntimeProto), {
|
|
78
|
-
memoMap,
|
|
79
|
-
scope,
|
|
80
|
-
runtimeEffect,
|
|
81
|
-
cachedRuntime: undefined,
|
|
82
|
-
runtime() {
|
|
83
|
-
return self.cachedRuntime === undefined ?
|
|
84
|
-
internalRuntime.unsafeRunPromiseEffect(self.runtimeEffect) :
|
|
85
|
-
Promise.resolve(self.cachedRuntime)
|
|
86
|
-
},
|
|
87
|
-
dispose(): Promise<void> {
|
|
88
|
-
return internalRuntime.unsafeRunPromiseEffect(self.disposeEffect)
|
|
89
|
-
},
|
|
90
|
-
disposeEffect: core.suspend(() => {
|
|
91
|
-
;(self as Mutable<ManagedRuntimeImpl<R, ER>>).runtimeEffect = core.die("ManagedRuntime disposed")
|
|
92
|
-
self.cachedRuntime = undefined
|
|
93
|
-
return Scope.close(self.scope, core.exitVoid)
|
|
94
|
-
}),
|
|
95
|
-
runFork<A, E>(effect: Effect.Effect<A, E, R>, options?: Runtime.RunForkOptions): Fiber.RuntimeFiber<A, E | ER> {
|
|
96
|
-
return self.cachedRuntime === undefined ?
|
|
97
|
-
internalRuntime.unsafeForkEffect(provide(self, effect), options) :
|
|
98
|
-
internalRuntime.unsafeFork(self.cachedRuntime)(effect, options)
|
|
99
|
-
},
|
|
100
|
-
runSyncExit<A, E>(effect: Effect.Effect<A, E, R>): Exit<A, E | ER> {
|
|
101
|
-
return self.cachedRuntime === undefined ?
|
|
102
|
-
internalRuntime.unsafeRunSyncExitEffect(provide(self, effect)) :
|
|
103
|
-
internalRuntime.unsafeRunSyncExit(self.cachedRuntime)(effect)
|
|
104
|
-
},
|
|
105
|
-
runSync<A, E>(effect: Effect.Effect<A, E, R>): A {
|
|
106
|
-
return self.cachedRuntime === undefined ?
|
|
107
|
-
internalRuntime.unsafeRunSyncEffect(provide(self, effect)) :
|
|
108
|
-
internalRuntime.unsafeRunSync(self.cachedRuntime)(effect)
|
|
109
|
-
},
|
|
110
|
-
runPromiseExit<A, E>(effect: Effect.Effect<A, E, R>, options?: {
|
|
111
|
-
readonly signal?: AbortSignal | undefined
|
|
112
|
-
}): Promise<Exit<A, E | ER>> {
|
|
113
|
-
return self.cachedRuntime === undefined ?
|
|
114
|
-
internalRuntime.unsafeRunPromiseExitEffect(provide(self, effect), options) :
|
|
115
|
-
internalRuntime.unsafeRunPromiseExit(self.cachedRuntime)(effect, options)
|
|
116
|
-
},
|
|
117
|
-
runCallback<A, E>(
|
|
118
|
-
effect: Effect.Effect<A, E, R>,
|
|
119
|
-
options?: Runtime.RunCallbackOptions<A, E | ER> | undefined
|
|
120
|
-
): Runtime.Cancel<A, E | ER> {
|
|
121
|
-
return self.cachedRuntime === undefined ?
|
|
122
|
-
internalRuntime.unsafeRunCallback(internalRuntime.defaultRuntime)(provide(self, effect), options) :
|
|
123
|
-
internalRuntime.unsafeRunCallback(self.cachedRuntime)(effect, options)
|
|
124
|
-
},
|
|
125
|
-
runPromise<A, E>(effect: Effect.Effect<A, E, R>, options?: {
|
|
126
|
-
readonly signal?: AbortSignal | undefined
|
|
127
|
-
}): Promise<A> {
|
|
128
|
-
return self.cachedRuntime === undefined ?
|
|
129
|
-
internalRuntime.unsafeRunPromiseEffect(provide(self, effect), options) :
|
|
130
|
-
internalRuntime.unsafeRunPromise(self.cachedRuntime)(effect, options)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
return self
|
|
134
|
-
}
|