@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/core.ts
DELETED
|
@@ -1,3273 +0,0 @@
|
|
|
1
|
-
import * as Arr from "../Array.js"
|
|
2
|
-
import type * as Cause from "../Cause.js"
|
|
3
|
-
import * as Chunk from "../Chunk.js"
|
|
4
|
-
import * as Context from "../Context.js"
|
|
5
|
-
import type * as Deferred from "../Deferred.js"
|
|
6
|
-
import type * as Differ from "../Differ.js"
|
|
7
|
-
import * as Duration from "../Duration.js"
|
|
8
|
-
import type * as Effect from "../Effect.js"
|
|
9
|
-
import * as Either from "../Either.js"
|
|
10
|
-
import * as Equal from "../Equal.js"
|
|
11
|
-
import type * as ExecutionStrategy from "../ExecutionStrategy.js"
|
|
12
|
-
import type * as Exit from "../Exit.js"
|
|
13
|
-
import type * as Fiber from "../Fiber.js"
|
|
14
|
-
import * as FiberId from "../FiberId.js"
|
|
15
|
-
import type * as FiberRef from "../FiberRef.js"
|
|
16
|
-
import type * as FiberStatus from "../FiberStatus.js"
|
|
17
|
-
import type { LazyArg } from "../Function.js"
|
|
18
|
-
import { dual, identity, pipe } from "../Function.js"
|
|
19
|
-
import { globalValue } from "../GlobalValue.js"
|
|
20
|
-
import * as Hash from "../Hash.js"
|
|
21
|
-
import * as HashMap from "../HashMap.js"
|
|
22
|
-
import type * as HashSet from "../HashSet.js"
|
|
23
|
-
import { format, NodeInspectSymbol, toJSON } from "../Inspectable.js"
|
|
24
|
-
import * as List from "../List.js"
|
|
25
|
-
import type * as LogLevel from "../LogLevel.js"
|
|
26
|
-
import type * as LogSpan from "../LogSpan.js"
|
|
27
|
-
import type * as MetricLabel from "../MetricLabel.js"
|
|
28
|
-
import * as MutableRef from "../MutableRef.js"
|
|
29
|
-
import * as Option from "../Option.js"
|
|
30
|
-
import { pipeArguments } from "../Pipeable.js"
|
|
31
|
-
import { hasProperty, isObject, isPromiseLike, type Predicate, type Refinement } from "../Predicate.js"
|
|
32
|
-
import type * as Request from "../Request.js"
|
|
33
|
-
import type * as BlockedRequests from "../RequestBlock.js"
|
|
34
|
-
import type * as RequestResolver from "../RequestResolver.js"
|
|
35
|
-
import type * as RuntimeFlags from "../RuntimeFlags.js"
|
|
36
|
-
import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch.js"
|
|
37
|
-
import type * as Scope from "../Scope.js"
|
|
38
|
-
import type * as Tracer from "../Tracer.js"
|
|
39
|
-
import type { NoInfer, NotFunction } from "../Types.js"
|
|
40
|
-
import { internalCall, YieldWrap } from "../Utils.js"
|
|
41
|
-
import * as blockedRequests_ from "./blockedRequests.js"
|
|
42
|
-
import * as internalCause from "./cause.js"
|
|
43
|
-
import * as deferred from "./deferred.js"
|
|
44
|
-
import * as internalDiffer from "./differ.js"
|
|
45
|
-
import { CommitPrototype, effectVariance, StructuralCommitPrototype } from "./effectable.js"
|
|
46
|
-
import { getBugErrorMessage } from "./errors.js"
|
|
47
|
-
import type * as FiberRuntime from "./fiberRuntime.js"
|
|
48
|
-
import type * as fiberScope from "./fiberScope.js"
|
|
49
|
-
import * as DeferredOpCodes from "./opCodes/deferred.js"
|
|
50
|
-
import * as OpCodes from "./opCodes/effect.js"
|
|
51
|
-
import * as runtimeFlags_ from "./runtimeFlags.js"
|
|
52
|
-
import { SingleShotGen } from "./singleShotGen.js"
|
|
53
|
-
|
|
54
|
-
// -----------------------------------------------------------------------------
|
|
55
|
-
// Effect
|
|
56
|
-
// -----------------------------------------------------------------------------
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
export const blocked = <A, E>(
|
|
62
|
-
blockedRequests: BlockedRequests.RequestBlock,
|
|
63
|
-
_continue: Effect.Effect<A, E>
|
|
64
|
-
): Effect.Blocked<A, E> => {
|
|
65
|
-
const effect = new EffectPrimitive("Blocked") as any
|
|
66
|
-
effect.effect_instruction_i0 = blockedRequests
|
|
67
|
-
effect.effect_instruction_i1 = _continue
|
|
68
|
-
return effect
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
export const runRequestBlock = (
|
|
75
|
-
blockedRequests: BlockedRequests.RequestBlock
|
|
76
|
-
): Effect.Effect<void> => {
|
|
77
|
-
const effect = new EffectPrimitive("RunBlocked") as any
|
|
78
|
-
effect.effect_instruction_i0 = blockedRequests
|
|
79
|
-
return effect
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** @internal */
|
|
83
|
-
export const EffectTypeId: Effect.EffectTypeId = Symbol.for("effect/Effect") as Effect.EffectTypeId
|
|
84
|
-
|
|
85
|
-
/** @internal */
|
|
86
|
-
export type Primitive =
|
|
87
|
-
| Async
|
|
88
|
-
| Commit
|
|
89
|
-
| Failure
|
|
90
|
-
| OnFailure
|
|
91
|
-
| OnSuccess
|
|
92
|
-
| OnStep
|
|
93
|
-
| OnSuccessAndFailure
|
|
94
|
-
| Success
|
|
95
|
-
| Sync
|
|
96
|
-
| UpdateRuntimeFlags
|
|
97
|
-
| While
|
|
98
|
-
| FromIterator
|
|
99
|
-
| WithRuntime
|
|
100
|
-
| Yield
|
|
101
|
-
| OpTag
|
|
102
|
-
| Blocked
|
|
103
|
-
| RunBlocked
|
|
104
|
-
| Either.Either<any, any>
|
|
105
|
-
| Option.Option<any>
|
|
106
|
-
|
|
107
|
-
/** @internal */
|
|
108
|
-
export type Continuation =
|
|
109
|
-
| OnSuccess
|
|
110
|
-
| OnStep
|
|
111
|
-
| OnSuccessAndFailure
|
|
112
|
-
| OnFailure
|
|
113
|
-
| While
|
|
114
|
-
| FromIterator
|
|
115
|
-
| RevertFlags
|
|
116
|
-
|
|
117
|
-
/** @internal */
|
|
118
|
-
export class RevertFlags {
|
|
119
|
-
readonly _op = OpCodes.OP_REVERT_FLAGS
|
|
120
|
-
constructor(
|
|
121
|
-
readonly patch: RuntimeFlagsPatch.RuntimeFlagsPatch,
|
|
122
|
-
readonly op: Primitive & { _op: OpCodes.OP_UPDATE_RUNTIME_FLAGS }
|
|
123
|
-
) {
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class EffectPrimitive {
|
|
128
|
-
public effect_instruction_i0 = undefined
|
|
129
|
-
public effect_instruction_i1 = undefined
|
|
130
|
-
public effect_instruction_i2 = undefined
|
|
131
|
-
public trace = undefined;
|
|
132
|
-
[EffectTypeId] = effectVariance
|
|
133
|
-
constructor(readonly _op: Primitive["_op"]) {}
|
|
134
|
-
[Equal.symbol](this: {}, that: unknown) {
|
|
135
|
-
return this === that
|
|
136
|
-
}
|
|
137
|
-
[Hash.symbol](this: {}) {
|
|
138
|
-
return Hash.cached(this, Hash.random(this))
|
|
139
|
-
}
|
|
140
|
-
pipe() {
|
|
141
|
-
return pipeArguments(this, arguments)
|
|
142
|
-
}
|
|
143
|
-
toJSON() {
|
|
144
|
-
return {
|
|
145
|
-
_id: "Effect",
|
|
146
|
-
_op: this._op,
|
|
147
|
-
effect_instruction_i0: toJSON(this.effect_instruction_i0),
|
|
148
|
-
effect_instruction_i1: toJSON(this.effect_instruction_i1),
|
|
149
|
-
effect_instruction_i2: toJSON(this.effect_instruction_i2)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
toString() {
|
|
153
|
-
return format(this.toJSON())
|
|
154
|
-
}
|
|
155
|
-
[NodeInspectSymbol]() {
|
|
156
|
-
return this.toJSON()
|
|
157
|
-
}
|
|
158
|
-
[Symbol.iterator]() {
|
|
159
|
-
return new SingleShotGen(new YieldWrap(this))
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** @internal */
|
|
164
|
-
class EffectPrimitiveFailure {
|
|
165
|
-
public effect_instruction_i0 = undefined
|
|
166
|
-
public effect_instruction_i1 = undefined
|
|
167
|
-
public effect_instruction_i2 = undefined
|
|
168
|
-
public trace = undefined;
|
|
169
|
-
[EffectTypeId] = effectVariance
|
|
170
|
-
constructor(readonly _op: Primitive["_op"]) {
|
|
171
|
-
// @ts-expect-error
|
|
172
|
-
this._tag = _op
|
|
173
|
-
}
|
|
174
|
-
[Equal.symbol](this: {}, that: unknown) {
|
|
175
|
-
return exitIsExit(that) && that._op === "Failure" &&
|
|
176
|
-
// @ts-expect-error
|
|
177
|
-
Equal.equals(this.effect_instruction_i0, that.effect_instruction_i0)
|
|
178
|
-
}
|
|
179
|
-
[Hash.symbol](this: {}) {
|
|
180
|
-
return pipe(
|
|
181
|
-
// @ts-expect-error
|
|
182
|
-
Hash.string(this._tag),
|
|
183
|
-
// @ts-expect-error
|
|
184
|
-
Hash.combine(Hash.hash(this.effect_instruction_i0)),
|
|
185
|
-
Hash.cached(this)
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
get cause() {
|
|
189
|
-
return this.effect_instruction_i0
|
|
190
|
-
}
|
|
191
|
-
pipe() {
|
|
192
|
-
return pipeArguments(this, arguments)
|
|
193
|
-
}
|
|
194
|
-
toJSON() {
|
|
195
|
-
return {
|
|
196
|
-
_id: "Exit",
|
|
197
|
-
_tag: this._op,
|
|
198
|
-
cause: (this.cause as any).toJSON()
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
toString() {
|
|
202
|
-
return format(this.toJSON())
|
|
203
|
-
}
|
|
204
|
-
[NodeInspectSymbol]() {
|
|
205
|
-
return this.toJSON()
|
|
206
|
-
}
|
|
207
|
-
[Symbol.iterator]() {
|
|
208
|
-
return new SingleShotGen(new YieldWrap(this))
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** @internal */
|
|
213
|
-
class EffectPrimitiveSuccess {
|
|
214
|
-
public effect_instruction_i0 = undefined
|
|
215
|
-
public effect_instruction_i1 = undefined
|
|
216
|
-
public effect_instruction_i2 = undefined
|
|
217
|
-
public trace = undefined;
|
|
218
|
-
[EffectTypeId] = effectVariance
|
|
219
|
-
constructor(readonly _op: Primitive["_op"]) {
|
|
220
|
-
// @ts-expect-error
|
|
221
|
-
this._tag = _op
|
|
222
|
-
}
|
|
223
|
-
[Equal.symbol](this: {}, that: unknown) {
|
|
224
|
-
return exitIsExit(that) && that._op === "Success" &&
|
|
225
|
-
// @ts-expect-error
|
|
226
|
-
Equal.equals(this.effect_instruction_i0, that.effect_instruction_i0)
|
|
227
|
-
}
|
|
228
|
-
[Hash.symbol](this: {}) {
|
|
229
|
-
return pipe(
|
|
230
|
-
// @ts-expect-error
|
|
231
|
-
Hash.string(this._tag),
|
|
232
|
-
// @ts-expect-error
|
|
233
|
-
Hash.combine(Hash.hash(this.effect_instruction_i0)),
|
|
234
|
-
Hash.cached(this)
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
get value() {
|
|
238
|
-
return this.effect_instruction_i0
|
|
239
|
-
}
|
|
240
|
-
pipe() {
|
|
241
|
-
return pipeArguments(this, arguments)
|
|
242
|
-
}
|
|
243
|
-
toJSON() {
|
|
244
|
-
return {
|
|
245
|
-
_id: "Exit",
|
|
246
|
-
_tag: this._op,
|
|
247
|
-
value: toJSON(this.value)
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
toString() {
|
|
251
|
-
return format(this.toJSON())
|
|
252
|
-
}
|
|
253
|
-
[NodeInspectSymbol]() {
|
|
254
|
-
return this.toJSON()
|
|
255
|
-
}
|
|
256
|
-
[Symbol.iterator]() {
|
|
257
|
-
return new SingleShotGen(new YieldWrap(this))
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/** @internal */
|
|
262
|
-
export type Op<Tag extends string, Body = {}> = Effect.Effect<never> & Body & {
|
|
263
|
-
readonly _op: Tag
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/** @internal */
|
|
267
|
-
export interface Async extends
|
|
268
|
-
Op<OpCodes.OP_ASYNC, {
|
|
269
|
-
effect_instruction_i0(resume: (effect: Primitive) => void): void
|
|
270
|
-
readonly effect_instruction_i1: FiberId.FiberId
|
|
271
|
-
}>
|
|
272
|
-
{}
|
|
273
|
-
|
|
274
|
-
/** @internal */
|
|
275
|
-
export interface Blocked<out E = any, out A = any> extends
|
|
276
|
-
Op<"Blocked", {
|
|
277
|
-
readonly effect_instruction_i0: BlockedRequests.RequestBlock
|
|
278
|
-
readonly effect_instruction_i1: Effect.Effect<A, E>
|
|
279
|
-
}>
|
|
280
|
-
{}
|
|
281
|
-
|
|
282
|
-
/** @internal */
|
|
283
|
-
export interface RunBlocked extends
|
|
284
|
-
Op<"RunBlocked", {
|
|
285
|
-
readonly effect_instruction_i0: BlockedRequests.RequestBlock
|
|
286
|
-
}>
|
|
287
|
-
{}
|
|
288
|
-
|
|
289
|
-
/** @internal */
|
|
290
|
-
export interface Failure extends
|
|
291
|
-
Op<OpCodes.OP_FAILURE, {
|
|
292
|
-
readonly effect_instruction_i0: Cause.Cause<unknown>
|
|
293
|
-
}>
|
|
294
|
-
{}
|
|
295
|
-
|
|
296
|
-
/** @internal */
|
|
297
|
-
export interface OpTag extends Op<OpCodes.OP_TAG, {}> {}
|
|
298
|
-
|
|
299
|
-
/** @internal */
|
|
300
|
-
export interface Commit extends
|
|
301
|
-
Op<OpCodes.OP_COMMIT, {
|
|
302
|
-
commit(): Effect.Effect<unknown, unknown, unknown>
|
|
303
|
-
}>
|
|
304
|
-
{}
|
|
305
|
-
|
|
306
|
-
/** @internal */
|
|
307
|
-
export interface OnFailure extends
|
|
308
|
-
Op<OpCodes.OP_ON_FAILURE, {
|
|
309
|
-
readonly effect_instruction_i0: Primitive
|
|
310
|
-
effect_instruction_i1(a: Cause.Cause<unknown>): Primitive
|
|
311
|
-
}>
|
|
312
|
-
{}
|
|
313
|
-
|
|
314
|
-
/** @internal */
|
|
315
|
-
export interface OnSuccess extends
|
|
316
|
-
Op<OpCodes.OP_ON_SUCCESS, {
|
|
317
|
-
readonly effect_instruction_i0: Primitive
|
|
318
|
-
effect_instruction_i1(a: unknown): Primitive
|
|
319
|
-
}>
|
|
320
|
-
{}
|
|
321
|
-
|
|
322
|
-
/** @internal */
|
|
323
|
-
export interface OnStep extends Op<"OnStep", { readonly effect_instruction_i0: Primitive }> {}
|
|
324
|
-
|
|
325
|
-
/** @internal */
|
|
326
|
-
export interface OnSuccessAndFailure extends
|
|
327
|
-
Op<OpCodes.OP_ON_SUCCESS_AND_FAILURE, {
|
|
328
|
-
readonly effect_instruction_i0: Primitive
|
|
329
|
-
effect_instruction_i1(a: Cause.Cause<unknown>): Primitive
|
|
330
|
-
effect_instruction_i2(a: unknown): Primitive
|
|
331
|
-
}>
|
|
332
|
-
{}
|
|
333
|
-
|
|
334
|
-
/** @internal */
|
|
335
|
-
export interface Success extends
|
|
336
|
-
Op<OpCodes.OP_SUCCESS, {
|
|
337
|
-
readonly effect_instruction_i0: unknown
|
|
338
|
-
}>
|
|
339
|
-
{}
|
|
340
|
-
|
|
341
|
-
/** @internal */
|
|
342
|
-
export interface Sync extends
|
|
343
|
-
Op<OpCodes.OP_SYNC, {
|
|
344
|
-
effect_instruction_i0(): unknown
|
|
345
|
-
}>
|
|
346
|
-
{}
|
|
347
|
-
|
|
348
|
-
/** @internal */
|
|
349
|
-
export interface UpdateRuntimeFlags extends
|
|
350
|
-
Op<OpCodes.OP_UPDATE_RUNTIME_FLAGS, {
|
|
351
|
-
readonly effect_instruction_i0: RuntimeFlagsPatch.RuntimeFlagsPatch
|
|
352
|
-
readonly effect_instruction_i1?: (oldRuntimeFlags: RuntimeFlags.RuntimeFlags) => Primitive
|
|
353
|
-
}>
|
|
354
|
-
{}
|
|
355
|
-
|
|
356
|
-
/** @internal */
|
|
357
|
-
export interface While extends
|
|
358
|
-
Op<OpCodes.OP_WHILE, {
|
|
359
|
-
effect_instruction_i0(): boolean
|
|
360
|
-
effect_instruction_i1(): Primitive
|
|
361
|
-
effect_instruction_i2(a: unknown): void
|
|
362
|
-
}>
|
|
363
|
-
{}
|
|
364
|
-
|
|
365
|
-
/** @internal */
|
|
366
|
-
export interface FromIterator extends
|
|
367
|
-
Op<OpCodes.OP_ITERATOR, {
|
|
368
|
-
effect_instruction_i0: Iterator<YieldWrap<Primitive>, any>
|
|
369
|
-
}>
|
|
370
|
-
{}
|
|
371
|
-
|
|
372
|
-
/** @internal */
|
|
373
|
-
export interface WithRuntime extends
|
|
374
|
-
Op<OpCodes.OP_WITH_RUNTIME, {
|
|
375
|
-
effect_instruction_i0(fiber: FiberRuntime.FiberRuntime<unknown, unknown>, status: FiberStatus.Running): Primitive
|
|
376
|
-
}>
|
|
377
|
-
{}
|
|
378
|
-
|
|
379
|
-
/** @internal */
|
|
380
|
-
export interface Yield extends Op<OpCodes.OP_YIELD> {}
|
|
381
|
-
|
|
382
|
-
/** @internal */
|
|
383
|
-
export const isEffect = (u: unknown): u is Effect.Effect<unknown, unknown, unknown> => hasProperty(u, EffectTypeId)
|
|
384
|
-
|
|
385
|
-
/* @internal */
|
|
386
|
-
export const withFiberRuntime = <A, E = never, R = never>(
|
|
387
|
-
withRuntime: (fiber: FiberRuntime.FiberRuntime<A, E>, status: FiberStatus.Running) => Effect.Effect<A, E, R>
|
|
388
|
-
): Effect.Effect<A, E, R> => {
|
|
389
|
-
const effect = new EffectPrimitive(OpCodes.OP_WITH_RUNTIME) as any
|
|
390
|
-
effect.effect_instruction_i0 = withRuntime
|
|
391
|
-
return effect
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/* @internal */
|
|
395
|
-
export const acquireUseRelease: {
|
|
396
|
-
<A2, E2, R2, A, X, R3>(
|
|
397
|
-
use: (a: A) => Effect.Effect<A2, E2, R2>,
|
|
398
|
-
release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>
|
|
399
|
-
): <E, R>(acquire: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2 | E, R2 | R3 | R>
|
|
400
|
-
<A, E, R, A2, E2, R2, X, R3>(
|
|
401
|
-
acquire: Effect.Effect<A, E, R>,
|
|
402
|
-
use: (a: A) => Effect.Effect<A2, E2, R2>,
|
|
403
|
-
release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>
|
|
404
|
-
): Effect.Effect<A2, E | E2, R | R2 | R3>
|
|
405
|
-
} = dual(3, <A, E, R, A2, E2, R2, X, R3>(
|
|
406
|
-
acquire: Effect.Effect<A, E, R>,
|
|
407
|
-
use: (a: A) => Effect.Effect<A2, E2, R2>,
|
|
408
|
-
release: (a: A, exit: Exit.Exit<A2, E2>) => Effect.Effect<X, never, R3>
|
|
409
|
-
): Effect.Effect<A2, E | E2, R | R2 | R3> =>
|
|
410
|
-
uninterruptibleMask((restore) =>
|
|
411
|
-
flatMap(
|
|
412
|
-
acquire,
|
|
413
|
-
(a) =>
|
|
414
|
-
flatMap(exit(suspend(() => restore(use(a)))), (exit): Effect.Effect<A2, E | E2, R | R2 | R3> => {
|
|
415
|
-
return suspend(() => release(a, exit)).pipe(
|
|
416
|
-
matchCauseEffect({
|
|
417
|
-
onFailure: (cause) => {
|
|
418
|
-
switch (exit._tag) {
|
|
419
|
-
case OpCodes.OP_FAILURE:
|
|
420
|
-
return failCause(internalCause.sequential(exit.effect_instruction_i0, cause))
|
|
421
|
-
case OpCodes.OP_SUCCESS:
|
|
422
|
-
return failCause(cause)
|
|
423
|
-
}
|
|
424
|
-
},
|
|
425
|
-
onSuccess: () => exit
|
|
426
|
-
})
|
|
427
|
-
)
|
|
428
|
-
})
|
|
429
|
-
)
|
|
430
|
-
))
|
|
431
|
-
|
|
432
|
-
/* @internal */
|
|
433
|
-
export const as: {
|
|
434
|
-
<B>(value: B): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>
|
|
435
|
-
<A, E, R, B>(self: Effect.Effect<A, E, R>, value: B): Effect.Effect<B, E, R>
|
|
436
|
-
} = dual(
|
|
437
|
-
2,
|
|
438
|
-
<A, E, R, B>(self: Effect.Effect<A, E, R>, value: B): Effect.Effect<B, E, R> => flatMap(self, () => succeed(value))
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
/* @internal */
|
|
442
|
-
export const asVoid = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<void, E, R> => as(self, void 0)
|
|
443
|
-
|
|
444
|
-
/* @internal */
|
|
445
|
-
export const custom: {
|
|
446
|
-
<X, A, E, R>(i0: X, body: (this: { effect_instruction_i0: X }) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
|
|
447
|
-
<X, Y, A, E, R>(
|
|
448
|
-
i0: X,
|
|
449
|
-
i1: Y,
|
|
450
|
-
body: (this: { effect_instruction_i0: X; effect_instruction_i1: Y }) => Effect.Effect<A, E, R>
|
|
451
|
-
): Effect.Effect<A, E, R>
|
|
452
|
-
<X, Y, Z, A, E, R>(
|
|
453
|
-
i0: X,
|
|
454
|
-
i1: Y,
|
|
455
|
-
i2: Z,
|
|
456
|
-
body: (
|
|
457
|
-
this: { effect_instruction_i0: X; effect_instruction_i1: Y; effect_instruction_i2: Z }
|
|
458
|
-
) => Effect.Effect<A, E, R>
|
|
459
|
-
): Effect.Effect<A, E, R>
|
|
460
|
-
} = function() {
|
|
461
|
-
const wrapper = new EffectPrimitive(OpCodes.OP_COMMIT) as any
|
|
462
|
-
switch (arguments.length) {
|
|
463
|
-
case 2: {
|
|
464
|
-
wrapper.effect_instruction_i0 = arguments[0]
|
|
465
|
-
wrapper.commit = arguments[1]
|
|
466
|
-
break
|
|
467
|
-
}
|
|
468
|
-
case 3: {
|
|
469
|
-
wrapper.effect_instruction_i0 = arguments[0]
|
|
470
|
-
wrapper.effect_instruction_i1 = arguments[1]
|
|
471
|
-
wrapper.commit = arguments[2]
|
|
472
|
-
break
|
|
473
|
-
}
|
|
474
|
-
case 4: {
|
|
475
|
-
wrapper.effect_instruction_i0 = arguments[0]
|
|
476
|
-
wrapper.effect_instruction_i1 = arguments[1]
|
|
477
|
-
wrapper.effect_instruction_i2 = arguments[2]
|
|
478
|
-
wrapper.commit = arguments[3]
|
|
479
|
-
break
|
|
480
|
-
}
|
|
481
|
-
default: {
|
|
482
|
-
throw new Error(getBugErrorMessage("you're not supposed to end up here"))
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
return wrapper
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/* @internal */
|
|
489
|
-
export const unsafeAsync = <A, E = never, R = never>(
|
|
490
|
-
register: (
|
|
491
|
-
callback: (_: Effect.Effect<A, E, R>) => void
|
|
492
|
-
) => void | Effect.Effect<void, never, R>,
|
|
493
|
-
blockingOn: FiberId.FiberId = FiberId.none
|
|
494
|
-
): Effect.Effect<A, E, R> => {
|
|
495
|
-
const effect = new EffectPrimitive(OpCodes.OP_ASYNC) as any
|
|
496
|
-
let cancelerRef: Effect.Effect<void, never, R> | void = undefined
|
|
497
|
-
effect.effect_instruction_i0 = (resume: (_: Effect.Effect<A, E, R>) => void) => {
|
|
498
|
-
cancelerRef = register(resume)
|
|
499
|
-
}
|
|
500
|
-
effect.effect_instruction_i1 = blockingOn
|
|
501
|
-
return onInterrupt(effect, (_) => isEffect(cancelerRef) ? cancelerRef : void_)
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/* @internal */
|
|
505
|
-
export const asyncInterrupt = <A, E = never, R = never>(
|
|
506
|
-
register: (
|
|
507
|
-
callback: (_: Effect.Effect<A, E, R>) => void
|
|
508
|
-
) => void | Effect.Effect<void, never, R>,
|
|
509
|
-
blockingOn: FiberId.FiberId = FiberId.none
|
|
510
|
-
): Effect.Effect<A, E, R> => suspend(() => unsafeAsync(register, blockingOn))
|
|
511
|
-
|
|
512
|
-
const async_ = <A, E = never, R = never>(
|
|
513
|
-
resume: (
|
|
514
|
-
callback: (_: Effect.Effect<A, E, R>) => void,
|
|
515
|
-
signal: AbortSignal
|
|
516
|
-
) => void | Effect.Effect<void, never, R>,
|
|
517
|
-
blockingOn: FiberId.FiberId = FiberId.none
|
|
518
|
-
): Effect.Effect<A, E, R> => {
|
|
519
|
-
return custom(resume, function() {
|
|
520
|
-
let backingResume: ((_: Effect.Effect<A, E, R>) => void) | undefined = undefined
|
|
521
|
-
let pendingEffect: Effect.Effect<A, E, R> | undefined = undefined
|
|
522
|
-
function proxyResume(effect: Effect.Effect<A, E, R>) {
|
|
523
|
-
if (backingResume) {
|
|
524
|
-
backingResume(effect)
|
|
525
|
-
} else if (pendingEffect === undefined) {
|
|
526
|
-
pendingEffect = effect
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
const effect = new EffectPrimitive(OpCodes.OP_ASYNC) as any
|
|
530
|
-
effect.effect_instruction_i0 = (resume: (_: Effect.Effect<A, E, R>) => void) => {
|
|
531
|
-
backingResume = resume
|
|
532
|
-
if (pendingEffect) {
|
|
533
|
-
resume(pendingEffect)
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
effect.effect_instruction_i1 = blockingOn
|
|
537
|
-
let cancelerRef: Effect.Effect<void, never, R> | void = undefined
|
|
538
|
-
let controllerRef: AbortController | void = undefined
|
|
539
|
-
if (this.effect_instruction_i0.length !== 1) {
|
|
540
|
-
controllerRef = new AbortController()
|
|
541
|
-
cancelerRef = internalCall(() => this.effect_instruction_i0(proxyResume, controllerRef!.signal))
|
|
542
|
-
} else {
|
|
543
|
-
cancelerRef = internalCall(() => (this.effect_instruction_i0 as any)(proxyResume))
|
|
544
|
-
}
|
|
545
|
-
return (cancelerRef || controllerRef) ?
|
|
546
|
-
onInterrupt(effect, (_) => {
|
|
547
|
-
if (controllerRef) {
|
|
548
|
-
controllerRef.abort()
|
|
549
|
-
}
|
|
550
|
-
return cancelerRef ?? void_
|
|
551
|
-
}) :
|
|
552
|
-
effect
|
|
553
|
-
})
|
|
554
|
-
}
|
|
555
|
-
export {
|
|
556
|
-
/** @internal */
|
|
557
|
-
async_ as async
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/* @internal */
|
|
561
|
-
export const catchAllCause = dual<
|
|
562
|
-
<E, A2, E2, R2>(
|
|
563
|
-
f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
|
|
564
|
-
) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>,
|
|
565
|
-
<A, E, R, A2, E2, R2>(
|
|
566
|
-
self: Effect.Effect<A, E, R>,
|
|
567
|
-
f: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
|
|
568
|
-
) => Effect.Effect<A2 | A, E2, R2 | R>
|
|
569
|
-
>(2, (self, f) => {
|
|
570
|
-
const effect = new EffectPrimitive(OpCodes.OP_ON_FAILURE) as any
|
|
571
|
-
effect.effect_instruction_i0 = self
|
|
572
|
-
effect.effect_instruction_i1 = f
|
|
573
|
-
return effect
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
/* @internal */
|
|
577
|
-
export const catchAll: {
|
|
578
|
-
<E, A2, E2, R2>(
|
|
579
|
-
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
580
|
-
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>
|
|
581
|
-
<A, E, R, A2, E2, R2>(
|
|
582
|
-
self: Effect.Effect<A, E, R>,
|
|
583
|
-
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
584
|
-
): Effect.Effect<A2 | A, E2, R2 | R>
|
|
585
|
-
} = dual(
|
|
586
|
-
2,
|
|
587
|
-
<A, E, R, A2, E2, R2>(
|
|
588
|
-
self: Effect.Effect<A, E, R>,
|
|
589
|
-
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
590
|
-
): Effect.Effect<A2 | A, E2, R2 | R> => matchEffect(self, { onFailure: f, onSuccess: succeed })
|
|
591
|
-
)
|
|
592
|
-
|
|
593
|
-
/* @internal */
|
|
594
|
-
export const catchIf: {
|
|
595
|
-
<E, EB extends E, A2, E2, R2>(
|
|
596
|
-
refinement: Refinement<NoInfer<E>, EB>,
|
|
597
|
-
f: (e: EB) => Effect.Effect<A2, E2, R2>
|
|
598
|
-
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2 | Exclude<E, EB>, R2 | R>
|
|
599
|
-
<E, A2, E2, R2>(
|
|
600
|
-
predicate: Predicate<NoInfer<E>>,
|
|
601
|
-
f: (e: NoInfer<E>) => Effect.Effect<A2, E2, R2>
|
|
602
|
-
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E | E2, R2 | R>
|
|
603
|
-
<A, E, R, EB extends E, A2, E2, R2>(
|
|
604
|
-
self: Effect.Effect<A, E, R>,
|
|
605
|
-
refinement: Refinement<E, EB>,
|
|
606
|
-
f: (e: EB) => Effect.Effect<A2, E2, R2>
|
|
607
|
-
): Effect.Effect<A2 | A, E2 | Exclude<E, EB>, R2 | R>
|
|
608
|
-
<A, E, R, A2, E2, R2>(
|
|
609
|
-
self: Effect.Effect<A, E, R>,
|
|
610
|
-
predicate: Predicate<E>,
|
|
611
|
-
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
612
|
-
): Effect.Effect<A | A2, E | E2, R | R2>
|
|
613
|
-
} = dual(3, <A, E, R, A2, E2, R2>(
|
|
614
|
-
self: Effect.Effect<A, E, R>,
|
|
615
|
-
predicate: Predicate<E>,
|
|
616
|
-
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
617
|
-
): Effect.Effect<A | A2, E | E2, R | R2> =>
|
|
618
|
-
catchAllCause(self, (cause): Effect.Effect<A | A2, E | E2, R | R2> => {
|
|
619
|
-
const either = internalCause.failureOrCause(cause)
|
|
620
|
-
switch (either._tag) {
|
|
621
|
-
case "Left":
|
|
622
|
-
return predicate(either.left) ? f(either.left) : failCause(cause)
|
|
623
|
-
case "Right":
|
|
624
|
-
return failCause(either.right)
|
|
625
|
-
}
|
|
626
|
-
}))
|
|
627
|
-
|
|
628
|
-
/* @internal */
|
|
629
|
-
export const catchSome = dual<
|
|
630
|
-
<E, A2, E2, R2>(
|
|
631
|
-
pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>
|
|
632
|
-
) => <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E | E2, R2 | R>,
|
|
633
|
-
<A, E, R, A2, E2, R2>(
|
|
634
|
-
self: Effect.Effect<A, E, R>,
|
|
635
|
-
pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>
|
|
636
|
-
) => Effect.Effect<A2 | A, E | E2, R2 | R>
|
|
637
|
-
>(2, <A, E, R, A2, E2, R2>(
|
|
638
|
-
self: Effect.Effect<A, E, R>,
|
|
639
|
-
pf: (e: NoInfer<E>) => Option.Option<Effect.Effect<A2, E2, R2>>
|
|
640
|
-
) =>
|
|
641
|
-
catchAllCause(self, (cause): Effect.Effect<A2 | A, E | E2, R2 | R> => {
|
|
642
|
-
const either = internalCause.failureOrCause(cause)
|
|
643
|
-
switch (either._tag) {
|
|
644
|
-
case "Left":
|
|
645
|
-
return pipe(pf(either.left), Option.getOrElse(() => failCause(cause)))
|
|
646
|
-
case "Right":
|
|
647
|
-
return failCause(either.right)
|
|
648
|
-
}
|
|
649
|
-
}))
|
|
650
|
-
|
|
651
|
-
/* @internal */
|
|
652
|
-
export const checkInterruptible = <A, E, R>(
|
|
653
|
-
f: (isInterruptible: boolean) => Effect.Effect<A, E, R>
|
|
654
|
-
): Effect.Effect<A, E, R> => withFiberRuntime((_, status) => f(runtimeFlags_.interruption(status.runtimeFlags)))
|
|
655
|
-
|
|
656
|
-
const originalSymbol = Symbol.for("effect/OriginalAnnotation")
|
|
657
|
-
|
|
658
|
-
/* @internal */
|
|
659
|
-
export const originalInstance = <E>(obj: E): E => {
|
|
660
|
-
if (hasProperty(obj, originalSymbol)) {
|
|
661
|
-
// @ts-expect-error
|
|
662
|
-
return obj[originalSymbol]
|
|
663
|
-
}
|
|
664
|
-
return obj
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
/* @internal */
|
|
668
|
-
export const capture = <E>(obj: E & object, span: Option.Option<Tracer.Span>): E => {
|
|
669
|
-
if (Option.isSome(span)) {
|
|
670
|
-
return new Proxy(obj, {
|
|
671
|
-
has(target, p) {
|
|
672
|
-
return p === internalCause.spanSymbol || p === originalSymbol || p in target
|
|
673
|
-
},
|
|
674
|
-
get(target, p) {
|
|
675
|
-
if (p === internalCause.spanSymbol) {
|
|
676
|
-
return span.value
|
|
677
|
-
}
|
|
678
|
-
if (p === originalSymbol) {
|
|
679
|
-
return obj
|
|
680
|
-
}
|
|
681
|
-
// @ts-expect-error
|
|
682
|
-
return target[p]
|
|
683
|
-
}
|
|
684
|
-
})
|
|
685
|
-
}
|
|
686
|
-
return obj
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
/* @internal */
|
|
690
|
-
export const die = (defect: unknown): Effect.Effect<never> =>
|
|
691
|
-
isObject(defect) && !(internalCause.spanSymbol in defect) ?
|
|
692
|
-
withFiberRuntime((fiber) => failCause(internalCause.die(capture(defect, currentSpanFromFiber(fiber)))))
|
|
693
|
-
: failCause(internalCause.die(defect))
|
|
694
|
-
|
|
695
|
-
/* @internal */
|
|
696
|
-
export const dieMessage = (message: string): Effect.Effect<never> =>
|
|
697
|
-
failCauseSync(() => internalCause.die(new RuntimeException(message)))
|
|
698
|
-
|
|
699
|
-
/* @internal */
|
|
700
|
-
export const dieSync = (evaluate: LazyArg<unknown>): Effect.Effect<never> => flatMap(sync(evaluate), die)
|
|
701
|
-
|
|
702
|
-
/* @internal */
|
|
703
|
-
export const either = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<Either.Either<A, E>, never, R> =>
|
|
704
|
-
matchEffect(self, {
|
|
705
|
-
onFailure: (e) => succeed(Either.left(e)),
|
|
706
|
-
onSuccess: (a) => succeed(Either.right(a))
|
|
707
|
-
})
|
|
708
|
-
|
|
709
|
-
/* @internal */
|
|
710
|
-
export const exit = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<Exit.Exit<A, E>, never, R> =>
|
|
711
|
-
matchCause(self, {
|
|
712
|
-
onFailure: exitFailCause,
|
|
713
|
-
onSuccess: exitSucceed
|
|
714
|
-
})
|
|
715
|
-
|
|
716
|
-
/* @internal */
|
|
717
|
-
export const fail = <E>(error: E): Effect.Effect<never, E> =>
|
|
718
|
-
isObject(error) && !(internalCause.spanSymbol in error) ?
|
|
719
|
-
withFiberRuntime((fiber) => failCause(internalCause.fail(capture(error, currentSpanFromFiber(fiber)))))
|
|
720
|
-
: failCause(internalCause.fail(error))
|
|
721
|
-
|
|
722
|
-
/* @internal */
|
|
723
|
-
export const failSync = <E>(evaluate: LazyArg<E>): Effect.Effect<never, E> => flatMap(sync(evaluate), fail)
|
|
724
|
-
|
|
725
|
-
/* @internal */
|
|
726
|
-
export const failCause = <E>(cause: Cause.Cause<E>): Effect.Effect<never, E> => {
|
|
727
|
-
const effect = new EffectPrimitiveFailure(OpCodes.OP_FAILURE) as any
|
|
728
|
-
effect.effect_instruction_i0 = cause
|
|
729
|
-
return effect
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/* @internal */
|
|
733
|
-
export const failCauseSync = <E>(
|
|
734
|
-
evaluate: LazyArg<Cause.Cause<E>>
|
|
735
|
-
): Effect.Effect<never, E> => flatMap(sync(evaluate), failCause)
|
|
736
|
-
|
|
737
|
-
/* @internal */
|
|
738
|
-
export const fiberId: Effect.Effect<FiberId.FiberId> = withFiberRuntime((state) => succeed(state.id()))
|
|
739
|
-
|
|
740
|
-
/* @internal */
|
|
741
|
-
export const fiberIdWith = <A, E, R>(
|
|
742
|
-
f: (descriptor: FiberId.Runtime) => Effect.Effect<A, E, R>
|
|
743
|
-
): Effect.Effect<A, E, R> => withFiberRuntime((state) => f(state.id()))
|
|
744
|
-
|
|
745
|
-
/* @internal */
|
|
746
|
-
export const flatMap = dual<
|
|
747
|
-
<A, B, E1, R1>(
|
|
748
|
-
f: (a: A) => Effect.Effect<B, E1, R1>
|
|
749
|
-
) => <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E1 | E, R1 | R>,
|
|
750
|
-
<A, E, R, B, E1, R1>(
|
|
751
|
-
self: Effect.Effect<A, E, R>,
|
|
752
|
-
f: (a: A) => Effect.Effect<B, E1, R1>
|
|
753
|
-
) => Effect.Effect<B, E | E1, R | R1>
|
|
754
|
-
>(
|
|
755
|
-
2,
|
|
756
|
-
(self, f) => {
|
|
757
|
-
const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS) as any
|
|
758
|
-
effect.effect_instruction_i0 = self
|
|
759
|
-
effect.effect_instruction_i1 = f
|
|
760
|
-
return effect
|
|
761
|
-
}
|
|
762
|
-
)
|
|
763
|
-
|
|
764
|
-
/* @internal */
|
|
765
|
-
export const andThen: {
|
|
766
|
-
<A, X>(
|
|
767
|
-
f: (a: NoInfer<A>) => X
|
|
768
|
-
): <E, R>(
|
|
769
|
-
self: Effect.Effect<A, E, R>
|
|
770
|
-
) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
|
|
771
|
-
: [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
|
|
772
|
-
: Effect.Effect<X, E, R>
|
|
773
|
-
<X>(
|
|
774
|
-
f: NotFunction<X>
|
|
775
|
-
): <A, E, R>(
|
|
776
|
-
self: Effect.Effect<A, E, R>
|
|
777
|
-
) => [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
|
|
778
|
-
: [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
|
|
779
|
-
: Effect.Effect<X, E, R>
|
|
780
|
-
<A, E, R, X>(
|
|
781
|
-
self: Effect.Effect<A, E, R>,
|
|
782
|
-
f: (a: NoInfer<A>) => X
|
|
783
|
-
): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
|
|
784
|
-
: [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
|
|
785
|
-
: Effect.Effect<X, E, R>
|
|
786
|
-
<A, E, R, X>(
|
|
787
|
-
self: Effect.Effect<A, E, R>,
|
|
788
|
-
f: NotFunction<X>
|
|
789
|
-
): [X] extends [Effect.Effect<infer A1, infer E1, infer R1>] ? Effect.Effect<A1, E | E1, R | R1>
|
|
790
|
-
: [X] extends [PromiseLike<infer A1>] ? Effect.Effect<A1, E | Cause.UnknownException, R>
|
|
791
|
-
: Effect.Effect<X, E, R>
|
|
792
|
-
} = dual(2, (self, f) =>
|
|
793
|
-
flatMap(self, (a) => {
|
|
794
|
-
const b = typeof f === "function" ? (f as any)(a) : f
|
|
795
|
-
if (isEffect(b)) {
|
|
796
|
-
return b
|
|
797
|
-
} else if (isPromiseLike(b)) {
|
|
798
|
-
return unsafeAsync<any, Cause.UnknownException>((resume) => {
|
|
799
|
-
b.then((a) => resume(succeed(a)), (e) =>
|
|
800
|
-
resume(fail(new UnknownException(e, "An unknown error occurred in Effect.andThen"))))
|
|
801
|
-
})
|
|
802
|
-
}
|
|
803
|
-
return succeed(b)
|
|
804
|
-
}))
|
|
805
|
-
|
|
806
|
-
/* @internal */
|
|
807
|
-
export const step = <A, E, R>(
|
|
808
|
-
self: Effect.Effect<A, E, R>
|
|
809
|
-
): Effect.Effect<Exit.Exit<A, E> | Effect.Blocked<A, E>, never, R> => {
|
|
810
|
-
const effect = new EffectPrimitive("OnStep") as any
|
|
811
|
-
effect.effect_instruction_i0 = self
|
|
812
|
-
return effect
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
/* @internal */
|
|
816
|
-
export const flatten = <A, E1, R1, E, R>(
|
|
817
|
-
self: Effect.Effect<Effect.Effect<A, E1, R1>, E, R>
|
|
818
|
-
): Effect.Effect<A, E | E1, R | R1> => flatMap(self, identity)
|
|
819
|
-
|
|
820
|
-
/* @internal */
|
|
821
|
-
export const flip = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<E, A, R> =>
|
|
822
|
-
matchEffect(self, { onFailure: succeed, onSuccess: fail })
|
|
823
|
-
|
|
824
|
-
/* @internal */
|
|
825
|
-
export const matchCause: {
|
|
826
|
-
<E, A2, A, A3>(
|
|
827
|
-
options: {
|
|
828
|
-
readonly onFailure: (cause: Cause.Cause<E>) => A2
|
|
829
|
-
readonly onSuccess: (a: A) => A3
|
|
830
|
-
}
|
|
831
|
-
): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, never, R>
|
|
832
|
-
<A, E, R, A2, A3>(
|
|
833
|
-
self: Effect.Effect<A, E, R>,
|
|
834
|
-
options: {
|
|
835
|
-
readonly onFailure: (cause: Cause.Cause<E>) => A2
|
|
836
|
-
readonly onSuccess: (a: A) => A3
|
|
837
|
-
}
|
|
838
|
-
): Effect.Effect<A2 | A3, never, R>
|
|
839
|
-
} = dual(2, <A, E, R, A2, A3>(
|
|
840
|
-
self: Effect.Effect<A, E, R>,
|
|
841
|
-
options: {
|
|
842
|
-
readonly onFailure: (cause: Cause.Cause<E>) => A2
|
|
843
|
-
readonly onSuccess: (a: A) => A3
|
|
844
|
-
}
|
|
845
|
-
): Effect.Effect<A2 | A3, never, R> =>
|
|
846
|
-
matchCauseEffect(self, {
|
|
847
|
-
onFailure: (cause) => succeed(options.onFailure(cause)),
|
|
848
|
-
onSuccess: (a) => succeed(options.onSuccess(a))
|
|
849
|
-
}))
|
|
850
|
-
|
|
851
|
-
/* @internal */
|
|
852
|
-
export const matchCauseEffect: {
|
|
853
|
-
<E, A2, E2, R2, A, A3, E3, R3>(
|
|
854
|
-
options: {
|
|
855
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
|
|
856
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
857
|
-
}
|
|
858
|
-
): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>
|
|
859
|
-
<A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
860
|
-
self: Effect.Effect<A, E, R>,
|
|
861
|
-
options: {
|
|
862
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
|
|
863
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
864
|
-
}
|
|
865
|
-
): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>
|
|
866
|
-
} = dual(2, <A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
867
|
-
self: Effect.Effect<A, E, R>,
|
|
868
|
-
options: {
|
|
869
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R2>
|
|
870
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
871
|
-
}
|
|
872
|
-
): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R> => {
|
|
873
|
-
const effect = new EffectPrimitive(OpCodes.OP_ON_SUCCESS_AND_FAILURE) as any
|
|
874
|
-
effect.effect_instruction_i0 = self
|
|
875
|
-
effect.effect_instruction_i1 = options.onFailure
|
|
876
|
-
effect.effect_instruction_i2 = options.onSuccess
|
|
877
|
-
return effect
|
|
878
|
-
})
|
|
879
|
-
|
|
880
|
-
/* @internal */
|
|
881
|
-
export const matchEffect: {
|
|
882
|
-
<E, A2, E2, R2, A, A3, E3, R3>(
|
|
883
|
-
options: {
|
|
884
|
-
readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>
|
|
885
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
886
|
-
}
|
|
887
|
-
): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>
|
|
888
|
-
<A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
889
|
-
self: Effect.Effect<A, E, R>,
|
|
890
|
-
options: {
|
|
891
|
-
readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>
|
|
892
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
893
|
-
}
|
|
894
|
-
): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R>
|
|
895
|
-
} = dual(2, <A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
896
|
-
self: Effect.Effect<A, E, R>,
|
|
897
|
-
options: {
|
|
898
|
-
readonly onFailure: (e: E) => Effect.Effect<A2, E2, R2>
|
|
899
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
900
|
-
}
|
|
901
|
-
): Effect.Effect<A2 | A3, E2 | E3, R2 | R3 | R> =>
|
|
902
|
-
matchCauseEffect(self, {
|
|
903
|
-
onFailure: (cause) => {
|
|
904
|
-
const defects = internalCause.defects(cause)
|
|
905
|
-
if (defects.length > 0) {
|
|
906
|
-
return failCause(internalCause.electFailures(cause))
|
|
907
|
-
}
|
|
908
|
-
const failures = internalCause.failures(cause)
|
|
909
|
-
if (failures.length > 0) {
|
|
910
|
-
return options.onFailure(Chunk.unsafeHead(failures))
|
|
911
|
-
}
|
|
912
|
-
return failCause(cause as Cause.Cause<never>)
|
|
913
|
-
},
|
|
914
|
-
onSuccess: options.onSuccess
|
|
915
|
-
}))
|
|
916
|
-
|
|
917
|
-
/* @internal */
|
|
918
|
-
export const forEachSequential: {
|
|
919
|
-
<A, B, E, R>(f: (a: A, i: number) => Effect.Effect<B, E, R>): (self: Iterable<A>) => Effect.Effect<Array<B>, E, R>
|
|
920
|
-
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<Array<B>, E, R>
|
|
921
|
-
} = dual(
|
|
922
|
-
2,
|
|
923
|
-
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<Array<B>, E, R> =>
|
|
924
|
-
suspend(() => {
|
|
925
|
-
const arr = Arr.fromIterable(self)
|
|
926
|
-
const ret = Arr.allocate<B>(arr.length)
|
|
927
|
-
let i = 0
|
|
928
|
-
return as(
|
|
929
|
-
whileLoop({
|
|
930
|
-
while: () => i < arr.length,
|
|
931
|
-
body: () => f(arr[i], i),
|
|
932
|
-
step: (b) => {
|
|
933
|
-
ret[i++] = b
|
|
934
|
-
}
|
|
935
|
-
}),
|
|
936
|
-
ret as Array<B>
|
|
937
|
-
)
|
|
938
|
-
})
|
|
939
|
-
)
|
|
940
|
-
|
|
941
|
-
/* @internal */
|
|
942
|
-
export const forEachSequentialDiscard: {
|
|
943
|
-
<A, B, E, R>(f: (a: A, i: number) => Effect.Effect<B, E, R>): (self: Iterable<A>) => Effect.Effect<void, E, R>
|
|
944
|
-
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<void, E, R>
|
|
945
|
-
} = dual(
|
|
946
|
-
2,
|
|
947
|
-
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<void, E, R> =>
|
|
948
|
-
suspend(() => {
|
|
949
|
-
const arr = Arr.fromIterable(self)
|
|
950
|
-
let i = 0
|
|
951
|
-
return whileLoop({
|
|
952
|
-
while: () => i < arr.length,
|
|
953
|
-
body: () => f(arr[i], i),
|
|
954
|
-
step: () => {
|
|
955
|
-
i++
|
|
956
|
-
}
|
|
957
|
-
})
|
|
958
|
-
})
|
|
959
|
-
)
|
|
960
|
-
|
|
961
|
-
/* @internal */
|
|
962
|
-
export const if_ = dual<
|
|
963
|
-
<A1, E1, R1, A2, E2, R2>(
|
|
964
|
-
options: {
|
|
965
|
-
readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>
|
|
966
|
-
readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
967
|
-
}
|
|
968
|
-
) => <E = never, R = never>(
|
|
969
|
-
self: Effect.Effect<boolean, E, R> | boolean
|
|
970
|
-
) => Effect.Effect<A1 | A2, E | E1 | E2, R | R1 | R2>,
|
|
971
|
-
<A1, E1, R1, A2, E2, R2, E = never, R = never>(
|
|
972
|
-
self: Effect.Effect<boolean, E, R> | boolean,
|
|
973
|
-
options: {
|
|
974
|
-
readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>
|
|
975
|
-
readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
976
|
-
}
|
|
977
|
-
) => Effect.Effect<A1 | A2, E1 | E2 | E, R1 | R2 | R>
|
|
978
|
-
>(
|
|
979
|
-
(args) => typeof args[0] === "boolean" || isEffect(args[0]),
|
|
980
|
-
<A1, E1, R1, A2, E2, R2, E = never, R = never>(
|
|
981
|
-
self: Effect.Effect<boolean, E, R> | boolean,
|
|
982
|
-
options: {
|
|
983
|
-
readonly onTrue: LazyArg<Effect.Effect<A1, E1, R1>>
|
|
984
|
-
readonly onFalse: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
985
|
-
}
|
|
986
|
-
): Effect.Effect<A1 | A2, E1 | E2 | E, R1 | R2 | R> =>
|
|
987
|
-
isEffect(self)
|
|
988
|
-
? flatMap(self, (b): Effect.Effect<A1 | A2, E1 | E2, R1 | R2> => (b ? options.onTrue() : options.onFalse()))
|
|
989
|
-
: self
|
|
990
|
-
? options.onTrue()
|
|
991
|
-
: options.onFalse()
|
|
992
|
-
)
|
|
993
|
-
|
|
994
|
-
/* @internal */
|
|
995
|
-
export const interrupt: Effect.Effect<never> = flatMap(fiberId, (fiberId) => interruptWith(fiberId))
|
|
996
|
-
|
|
997
|
-
/* @internal */
|
|
998
|
-
export const interruptWith = (fiberId: FiberId.FiberId): Effect.Effect<never> =>
|
|
999
|
-
failCause(internalCause.interrupt(fiberId))
|
|
1000
|
-
|
|
1001
|
-
/* @internal */
|
|
1002
|
-
export const interruptible = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => {
|
|
1003
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1004
|
-
effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(runtimeFlags_.Interruption)
|
|
1005
|
-
effect.effect_instruction_i1 = () => self
|
|
1006
|
-
return effect
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
/* @internal */
|
|
1010
|
-
export const interruptibleMask = <A, E, R>(
|
|
1011
|
-
f: (restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Effect.Effect<A, E, R>
|
|
1012
|
-
): Effect.Effect<A, E, R> =>
|
|
1013
|
-
custom(f, function() {
|
|
1014
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1015
|
-
effect.effect_instruction_i0 = RuntimeFlagsPatch.enable(runtimeFlags_.Interruption)
|
|
1016
|
-
effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>
|
|
1017
|
-
runtimeFlags_.interruption(oldFlags)
|
|
1018
|
-
? internalCall(() => this.effect_instruction_i0(interruptible))
|
|
1019
|
-
: internalCall(() => this.effect_instruction_i0(uninterruptible))
|
|
1020
|
-
return effect
|
|
1021
|
-
})
|
|
1022
|
-
|
|
1023
|
-
/* @internal */
|
|
1024
|
-
export const intoDeferred: {
|
|
1025
|
-
<A, E>(deferred: Deferred.Deferred<A, E>): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<boolean, never, R>
|
|
1026
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, deferred: Deferred.Deferred<A, E>): Effect.Effect<boolean, never, R>
|
|
1027
|
-
} = dual(
|
|
1028
|
-
2,
|
|
1029
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, deferred: Deferred.Deferred<A, E>): Effect.Effect<boolean, never, R> =>
|
|
1030
|
-
uninterruptibleMask((restore) =>
|
|
1031
|
-
flatMap(
|
|
1032
|
-
exit(restore(self)),
|
|
1033
|
-
(exit) => deferredDone(deferred, exit)
|
|
1034
|
-
)
|
|
1035
|
-
)
|
|
1036
|
-
)
|
|
1037
|
-
|
|
1038
|
-
/* @internal */
|
|
1039
|
-
export const map: {
|
|
1040
|
-
<A, B>(f: (a: A) => B): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E, R>
|
|
1041
|
-
<A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R>
|
|
1042
|
-
} = dual(
|
|
1043
|
-
2,
|
|
1044
|
-
<A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R> =>
|
|
1045
|
-
flatMap(self, (a) => sync(() => f(a)))
|
|
1046
|
-
)
|
|
1047
|
-
|
|
1048
|
-
/* @internal */
|
|
1049
|
-
export const mapBoth: {
|
|
1050
|
-
<E, E2, A, A2>(
|
|
1051
|
-
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
|
1052
|
-
): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2, E2, R>
|
|
1053
|
-
<A, E, R, E2, A2>(
|
|
1054
|
-
self: Effect.Effect<A, E, R>,
|
|
1055
|
-
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
|
1056
|
-
): Effect.Effect<A2, E2, R>
|
|
1057
|
-
} = dual(2, <A, E, R, E2, A2>(
|
|
1058
|
-
self: Effect.Effect<A, E, R>,
|
|
1059
|
-
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
|
1060
|
-
): Effect.Effect<A2, E2, R> =>
|
|
1061
|
-
matchEffect(self, {
|
|
1062
|
-
onFailure: (e) => failSync(() => options.onFailure(e)),
|
|
1063
|
-
onSuccess: (a) => sync(() => options.onSuccess(a))
|
|
1064
|
-
}))
|
|
1065
|
-
|
|
1066
|
-
/* @internal */
|
|
1067
|
-
export const mapError: {
|
|
1068
|
-
<E, E2>(f: (e: E) => E2): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2, R>
|
|
1069
|
-
<A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R>
|
|
1070
|
-
} = dual(
|
|
1071
|
-
2,
|
|
1072
|
-
<A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R> =>
|
|
1073
|
-
matchCauseEffect(self, {
|
|
1074
|
-
onFailure: (cause) => {
|
|
1075
|
-
const either = internalCause.failureOrCause(cause)
|
|
1076
|
-
switch (either._tag) {
|
|
1077
|
-
case "Left": {
|
|
1078
|
-
return failSync(() => f(either.left))
|
|
1079
|
-
}
|
|
1080
|
-
case "Right": {
|
|
1081
|
-
return failCause(either.right)
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
},
|
|
1085
|
-
onSuccess: succeed
|
|
1086
|
-
})
|
|
1087
|
-
)
|
|
1088
|
-
|
|
1089
|
-
/* @internal */
|
|
1090
|
-
export const onError: {
|
|
1091
|
-
<E, X, R2>(
|
|
1092
|
-
cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>
|
|
1093
|
-
): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>
|
|
1094
|
-
<A, E, R, X, R2>(
|
|
1095
|
-
self: Effect.Effect<A, E, R>,
|
|
1096
|
-
cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>
|
|
1097
|
-
): Effect.Effect<A, E, R2 | R>
|
|
1098
|
-
} = dual(2, <A, E, R, X, R2>(
|
|
1099
|
-
self: Effect.Effect<A, E, R>,
|
|
1100
|
-
cleanup: (cause: Cause.Cause<E>) => Effect.Effect<X, never, R2>
|
|
1101
|
-
): Effect.Effect<A, E, R2 | R> =>
|
|
1102
|
-
onExit(self, (exit) => exitIsSuccess(exit) ? void_ : cleanup(exit.effect_instruction_i0)))
|
|
1103
|
-
|
|
1104
|
-
/* @internal */
|
|
1105
|
-
export const onExit: {
|
|
1106
|
-
<A, E, X, R2>(
|
|
1107
|
-
cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>
|
|
1108
|
-
): <R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>
|
|
1109
|
-
<A, E, R, X, R2>(
|
|
1110
|
-
self: Effect.Effect<A, E, R>,
|
|
1111
|
-
cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>
|
|
1112
|
-
): Effect.Effect<A, E, R2 | R>
|
|
1113
|
-
} = dual(2, <A, E, R, X, R2>(
|
|
1114
|
-
self: Effect.Effect<A, E, R>,
|
|
1115
|
-
cleanup: (exit: Exit.Exit<A, E>) => Effect.Effect<X, never, R2>
|
|
1116
|
-
): Effect.Effect<A, E, R2 | R> =>
|
|
1117
|
-
uninterruptibleMask((restore) =>
|
|
1118
|
-
matchCauseEffect(restore(self), {
|
|
1119
|
-
onFailure: (cause1) => {
|
|
1120
|
-
const result = exitFailCause(cause1)
|
|
1121
|
-
return matchCauseEffect(cleanup(result), {
|
|
1122
|
-
onFailure: (cause2) => exitFailCause(internalCause.sequential(cause1, cause2)),
|
|
1123
|
-
onSuccess: () => result
|
|
1124
|
-
})
|
|
1125
|
-
},
|
|
1126
|
-
onSuccess: (success) => {
|
|
1127
|
-
const result = exitSucceed(success)
|
|
1128
|
-
return zipRight(cleanup(result), result)
|
|
1129
|
-
}
|
|
1130
|
-
})
|
|
1131
|
-
))
|
|
1132
|
-
|
|
1133
|
-
/* @internal */
|
|
1134
|
-
export const onInterrupt: {
|
|
1135
|
-
<X, R2>(
|
|
1136
|
-
cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>
|
|
1137
|
-
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2 | R>
|
|
1138
|
-
<A, E, R, X, R2>(
|
|
1139
|
-
self: Effect.Effect<A, E, R>,
|
|
1140
|
-
cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>
|
|
1141
|
-
): Effect.Effect<A, E, R2 | R>
|
|
1142
|
-
} = dual(2, <A, E, R, X, R2>(
|
|
1143
|
-
self: Effect.Effect<A, E, R>,
|
|
1144
|
-
cleanup: (interruptors: HashSet.HashSet<FiberId.FiberId>) => Effect.Effect<X, never, R2>
|
|
1145
|
-
): Effect.Effect<A, E, R2 | R> =>
|
|
1146
|
-
onExit(
|
|
1147
|
-
self,
|
|
1148
|
-
exitMatch({
|
|
1149
|
-
onFailure: (cause) =>
|
|
1150
|
-
internalCause.isInterruptedOnly(cause)
|
|
1151
|
-
? asVoid(cleanup(internalCause.interruptors(cause)))
|
|
1152
|
-
: void_,
|
|
1153
|
-
onSuccess: () => void_
|
|
1154
|
-
})
|
|
1155
|
-
))
|
|
1156
|
-
|
|
1157
|
-
/* @internal */
|
|
1158
|
-
export const orElse: {
|
|
1159
|
-
<A2, E2, R2>(
|
|
1160
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
1161
|
-
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A, E2, R2 | R>
|
|
1162
|
-
<A, E, R, A2, E2, R2>(
|
|
1163
|
-
self: Effect.Effect<A, E, R>,
|
|
1164
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
1165
|
-
): Effect.Effect<A2 | A, E2, R2 | R>
|
|
1166
|
-
} = dual(
|
|
1167
|
-
2,
|
|
1168
|
-
<A, E, R, A2, E2, R2>(
|
|
1169
|
-
self: Effect.Effect<A, E, R>,
|
|
1170
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>
|
|
1171
|
-
): Effect.Effect<A2 | A, E2, R2 | R> => attemptOrElse(self, that, succeed)
|
|
1172
|
-
)
|
|
1173
|
-
|
|
1174
|
-
/* @internal */
|
|
1175
|
-
export const orDie = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, never, R> => orDieWith(self, identity)
|
|
1176
|
-
|
|
1177
|
-
/* @internal */
|
|
1178
|
-
export const orDieWith: {
|
|
1179
|
-
<E>(f: (error: E) => unknown): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, never, R>
|
|
1180
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, f: (error: E) => unknown): Effect.Effect<A, never, R>
|
|
1181
|
-
} = dual(
|
|
1182
|
-
2,
|
|
1183
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, f: (error: E) => unknown): Effect.Effect<A, never, R> =>
|
|
1184
|
-
matchEffect(self, {
|
|
1185
|
-
onFailure: (e) => die(f(e)),
|
|
1186
|
-
onSuccess: succeed
|
|
1187
|
-
})
|
|
1188
|
-
)
|
|
1189
|
-
|
|
1190
|
-
/* @internal */
|
|
1191
|
-
export const partitionMap: <A, A1, A2>(
|
|
1192
|
-
elements: Iterable<A>,
|
|
1193
|
-
f: (a: A) => Either.Either<A2, A1>
|
|
1194
|
-
) => [left: Array<A1>, right: Array<A2>] = Arr.partitionMap
|
|
1195
|
-
/* @internal */
|
|
1196
|
-
export const runtimeFlags: Effect.Effect<RuntimeFlags.RuntimeFlags> = withFiberRuntime((_, status) =>
|
|
1197
|
-
succeed(status.runtimeFlags)
|
|
1198
|
-
)
|
|
1199
|
-
|
|
1200
|
-
/* @internal */
|
|
1201
|
-
export const succeed = <A>(value: A): Effect.Effect<A> => {
|
|
1202
|
-
const effect = new EffectPrimitiveSuccess(OpCodes.OP_SUCCESS) as any
|
|
1203
|
-
effect.effect_instruction_i0 = value
|
|
1204
|
-
return effect
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
/* @internal */
|
|
1208
|
-
export const suspend = <A, E, R>(evaluate: LazyArg<Effect.Effect<A, E, R>>): Effect.Effect<A, E, R> => {
|
|
1209
|
-
const effect = new EffectPrimitive(OpCodes.OP_COMMIT) as any
|
|
1210
|
-
effect.commit = evaluate
|
|
1211
|
-
return effect
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/* @internal */
|
|
1215
|
-
export const sync = <A>(thunk: LazyArg<A>): Effect.Effect<A> => {
|
|
1216
|
-
const effect = new EffectPrimitive(OpCodes.OP_SYNC) as any
|
|
1217
|
-
effect.effect_instruction_i0 = thunk
|
|
1218
|
-
return effect
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
/* @internal */
|
|
1222
|
-
export const tap = dual<
|
|
1223
|
-
{
|
|
1224
|
-
<A, X>(
|
|
1225
|
-
f: (a: NoInfer<A>) => X
|
|
1226
|
-
): <E, R>(
|
|
1227
|
-
self: Effect.Effect<A, E, R>
|
|
1228
|
-
) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
|
|
1229
|
-
: [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
|
|
1230
|
-
: Effect.Effect<A, E, R>
|
|
1231
|
-
<A, X, E1, R1>(
|
|
1232
|
-
f: (a: NoInfer<A>) => Effect.Effect<X, E1, R1>,
|
|
1233
|
-
options: { onlyEffect: true }
|
|
1234
|
-
): <E, R>(
|
|
1235
|
-
self: Effect.Effect<A, E, R>
|
|
1236
|
-
) => Effect.Effect<A, E | E1, R | R1>
|
|
1237
|
-
<X>(
|
|
1238
|
-
f: NotFunction<X>
|
|
1239
|
-
): <A, E, R>(
|
|
1240
|
-
self: Effect.Effect<A, E, R>
|
|
1241
|
-
) => [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
|
|
1242
|
-
: [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
|
|
1243
|
-
: Effect.Effect<A, E, R>
|
|
1244
|
-
<X, E1, R1>(
|
|
1245
|
-
f: Effect.Effect<X, E1, R1>,
|
|
1246
|
-
options: { onlyEffect: true }
|
|
1247
|
-
): <A, E, R>(
|
|
1248
|
-
self: Effect.Effect<A, E, R>
|
|
1249
|
-
) => Effect.Effect<A, E | E1, R | R1>
|
|
1250
|
-
},
|
|
1251
|
-
{
|
|
1252
|
-
<A, E, R, X>(
|
|
1253
|
-
self: Effect.Effect<A, E, R>,
|
|
1254
|
-
f: (a: NoInfer<A>) => X
|
|
1255
|
-
): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
|
|
1256
|
-
: [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
|
|
1257
|
-
: Effect.Effect<A, E, R>
|
|
1258
|
-
<A, E, R, X, E1, R1>(
|
|
1259
|
-
self: Effect.Effect<A, E, R>,
|
|
1260
|
-
f: (a: NoInfer<A>) => Effect.Effect<X, E1, R1>,
|
|
1261
|
-
options: { onlyEffect: true }
|
|
1262
|
-
): Effect.Effect<A, E | E1, R | R1>
|
|
1263
|
-
<A, E, R, X>(
|
|
1264
|
-
self: Effect.Effect<A, E, R>,
|
|
1265
|
-
f: NotFunction<X>
|
|
1266
|
-
): [X] extends [Effect.Effect<infer _A1, infer E1, infer R1>] ? Effect.Effect<A, E | E1, R | R1>
|
|
1267
|
-
: [X] extends [PromiseLike<infer _A1>] ? Effect.Effect<A, E | Cause.UnknownException, R>
|
|
1268
|
-
: Effect.Effect<A, E, R>
|
|
1269
|
-
<A, E, R, X, E1, R1>(
|
|
1270
|
-
self: Effect.Effect<A, E, R>,
|
|
1271
|
-
f: Effect.Effect<X, E1, R1>,
|
|
1272
|
-
options: { onlyEffect: true }
|
|
1273
|
-
): Effect.Effect<A, E | E1, R | R1>
|
|
1274
|
-
}
|
|
1275
|
-
>(
|
|
1276
|
-
(args) => args.length === 3 || args.length === 2 && !(isObject(args[1]) && "onlyEffect" in args[1]),
|
|
1277
|
-
<A, E, R, X>(self: Effect.Effect<A, E, R>, f: X) =>
|
|
1278
|
-
flatMap(self, (a) => {
|
|
1279
|
-
const b = typeof f === "function" ? (f as any)(a) : f
|
|
1280
|
-
if (isEffect(b)) {
|
|
1281
|
-
return as(b, a)
|
|
1282
|
-
} else if (isPromiseLike(b)) {
|
|
1283
|
-
return unsafeAsync<any, Cause.UnknownException>((resume) => {
|
|
1284
|
-
b.then((_) => resume(succeed(a)), (e) =>
|
|
1285
|
-
resume(fail(new UnknownException(e, "An unknown error occurred in Effect.tap"))))
|
|
1286
|
-
})
|
|
1287
|
-
}
|
|
1288
|
-
return succeed(a)
|
|
1289
|
-
})
|
|
1290
|
-
)
|
|
1291
|
-
|
|
1292
|
-
/* @internal */
|
|
1293
|
-
export const transplant = <A, E, R>(
|
|
1294
|
-
f: (grafter: <A2, E2, R2>(effect: Effect.Effect<A2, E2, R2>) => Effect.Effect<A2, E2, R2>) => Effect.Effect<A, E, R>
|
|
1295
|
-
): Effect.Effect<A, E, R> =>
|
|
1296
|
-
withFiberRuntime<A, E, R>((state) => {
|
|
1297
|
-
const scopeOverride = state.getFiberRef(currentForkScopeOverride)
|
|
1298
|
-
const scope = pipe(scopeOverride, Option.getOrElse(() => state.scope()))
|
|
1299
|
-
return f(fiberRefLocally(currentForkScopeOverride, Option.some(scope)))
|
|
1300
|
-
})
|
|
1301
|
-
|
|
1302
|
-
/* @internal */
|
|
1303
|
-
export const attemptOrElse: {
|
|
1304
|
-
<A2, E2, R2, A, A3, E3, R3>(
|
|
1305
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>,
|
|
1306
|
-
onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
1307
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3>
|
|
1308
|
-
<A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
1309
|
-
self: Effect.Effect<A, E, R>,
|
|
1310
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>,
|
|
1311
|
-
onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
1312
|
-
): Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3>
|
|
1313
|
-
} = dual(3, <A, E, R, A2, E2, R2, A3, E3, R3>(
|
|
1314
|
-
self: Effect.Effect<A, E, R>,
|
|
1315
|
-
that: LazyArg<Effect.Effect<A2, E2, R2>>,
|
|
1316
|
-
onSuccess: (a: A) => Effect.Effect<A3, E3, R3>
|
|
1317
|
-
): Effect.Effect<A2 | A3, E2 | E3, R | R2 | R3> =>
|
|
1318
|
-
matchCauseEffect(self, {
|
|
1319
|
-
onFailure: (cause) => {
|
|
1320
|
-
const defects = internalCause.defects(cause)
|
|
1321
|
-
if (defects.length > 0) {
|
|
1322
|
-
return failCause(Option.getOrThrow(internalCause.keepDefectsAndElectFailures(cause)))
|
|
1323
|
-
}
|
|
1324
|
-
return that()
|
|
1325
|
-
},
|
|
1326
|
-
onSuccess
|
|
1327
|
-
}))
|
|
1328
|
-
|
|
1329
|
-
/* @internal */
|
|
1330
|
-
export const uninterruptible: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> = <A, E, R>(
|
|
1331
|
-
self: Effect.Effect<A, E, R>
|
|
1332
|
-
): Effect.Effect<A, E, R> => {
|
|
1333
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1334
|
-
effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(runtimeFlags_.Interruption)
|
|
1335
|
-
effect.effect_instruction_i1 = () => self
|
|
1336
|
-
return effect
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
/* @internal */
|
|
1340
|
-
export const uninterruptibleMask = <A, E, R>(
|
|
1341
|
-
f: (restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Effect.Effect<A, E, R>
|
|
1342
|
-
): Effect.Effect<A, E, R> =>
|
|
1343
|
-
custom(f, function() {
|
|
1344
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1345
|
-
effect.effect_instruction_i0 = RuntimeFlagsPatch.disable(runtimeFlags_.Interruption)
|
|
1346
|
-
effect.effect_instruction_i1 = (oldFlags: RuntimeFlags.RuntimeFlags) =>
|
|
1347
|
-
runtimeFlags_.interruption(oldFlags)
|
|
1348
|
-
? internalCall(() => this.effect_instruction_i0(interruptible))
|
|
1349
|
-
: internalCall(() => this.effect_instruction_i0(uninterruptible))
|
|
1350
|
-
return effect
|
|
1351
|
-
})
|
|
1352
|
-
|
|
1353
|
-
const void_: Effect.Effect<void> = succeed(void 0)
|
|
1354
|
-
export {
|
|
1355
|
-
/* @internal */
|
|
1356
|
-
void_ as void
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
/* @internal */
|
|
1360
|
-
export const updateRuntimeFlags = (patch: RuntimeFlagsPatch.RuntimeFlagsPatch): Effect.Effect<void> => {
|
|
1361
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1362
|
-
effect.effect_instruction_i0 = patch
|
|
1363
|
-
effect.effect_instruction_i1 = void 0
|
|
1364
|
-
return effect
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
/* @internal */
|
|
1368
|
-
export const whenEffect: {
|
|
1369
|
-
<E, R>(
|
|
1370
|
-
condition: Effect.Effect<boolean, E, R>
|
|
1371
|
-
): <A, E2, R2>(
|
|
1372
|
-
effect: Effect.Effect<A, E2, R2>
|
|
1373
|
-
) => Effect.Effect<Option.Option<A>, E | E2, R | R2>
|
|
1374
|
-
<A, E2, R2, E, R>(
|
|
1375
|
-
self: Effect.Effect<A, E2, R2>,
|
|
1376
|
-
condition: Effect.Effect<boolean, E, R>
|
|
1377
|
-
): Effect.Effect<Option.Option<A>, E | E2, R | R2>
|
|
1378
|
-
} = dual(2, <A, E2, R2, E, R>(
|
|
1379
|
-
self: Effect.Effect<A, E2, R2>,
|
|
1380
|
-
condition: Effect.Effect<boolean, E, R>
|
|
1381
|
-
): Effect.Effect<Option.Option<A>, E | E2, R | R2> =>
|
|
1382
|
-
flatMap(condition, (b) => {
|
|
1383
|
-
if (b) {
|
|
1384
|
-
return pipe(self, map(Option.some))
|
|
1385
|
-
}
|
|
1386
|
-
return succeed(Option.none())
|
|
1387
|
-
}))
|
|
1388
|
-
|
|
1389
|
-
/* @internal */
|
|
1390
|
-
export const whileLoop = <A, E, R>(
|
|
1391
|
-
options: {
|
|
1392
|
-
readonly while: LazyArg<boolean>
|
|
1393
|
-
readonly body: LazyArg<Effect.Effect<A, E, R>>
|
|
1394
|
-
readonly step: (a: A) => void
|
|
1395
|
-
}
|
|
1396
|
-
): Effect.Effect<void, E, R> => {
|
|
1397
|
-
const effect = new EffectPrimitive(OpCodes.OP_WHILE) as any
|
|
1398
|
-
effect.effect_instruction_i0 = options.while
|
|
1399
|
-
effect.effect_instruction_i1 = options.body
|
|
1400
|
-
effect.effect_instruction_i2 = options.step
|
|
1401
|
-
return effect
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
/* @internal */
|
|
1405
|
-
export const fromIterator = <Eff extends YieldWrap<Effect.Effect<any, any, any>>, AEff>(
|
|
1406
|
-
iterator: LazyArg<Iterator<Eff, AEff, never>>
|
|
1407
|
-
): Effect.Effect<
|
|
1408
|
-
AEff,
|
|
1409
|
-
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
|
|
1410
|
-
[Eff] extends [never] ? never : [Eff] extends [YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
|
|
1411
|
-
> =>
|
|
1412
|
-
suspend(() => {
|
|
1413
|
-
const effect = new EffectPrimitive(OpCodes.OP_ITERATOR) as any
|
|
1414
|
-
effect.effect_instruction_i0 = iterator()
|
|
1415
|
-
return effect
|
|
1416
|
-
})
|
|
1417
|
-
|
|
1418
|
-
/* @internal */
|
|
1419
|
-
export const gen: typeof Effect.gen = function() {
|
|
1420
|
-
const f = arguments.length === 1 ? arguments[0] : arguments[1].bind(arguments[0])
|
|
1421
|
-
return fromIterator(() => f(pipe))
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
/** @internal */
|
|
1425
|
-
export const fnUntraced: Effect.fn.Untraced = (body: Function, ...pipeables: Array<any>) =>
|
|
1426
|
-
Object.defineProperty(
|
|
1427
|
-
pipeables.length === 0
|
|
1428
|
-
? function(this: any, ...args: Array<any>) {
|
|
1429
|
-
return fromIterator(() => body.apply(this, args))
|
|
1430
|
-
}
|
|
1431
|
-
: function(this: any, ...args: Array<any>) {
|
|
1432
|
-
let effect = fromIterator(() => body.apply(this, args))
|
|
1433
|
-
for (const x of pipeables) {
|
|
1434
|
-
effect = x(effect, ...args)
|
|
1435
|
-
}
|
|
1436
|
-
return effect
|
|
1437
|
-
},
|
|
1438
|
-
"length",
|
|
1439
|
-
{ value: body.length, configurable: true }
|
|
1440
|
-
)
|
|
1441
|
-
|
|
1442
|
-
/* @internal */
|
|
1443
|
-
export const withConcurrency = dual<
|
|
1444
|
-
(concurrency: number | "unbounded") => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1445
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, concurrency: number | "unbounded") => Effect.Effect<A, E, R>
|
|
1446
|
-
>(2, (self, concurrency) => fiberRefLocally(self, currentConcurrency, concurrency))
|
|
1447
|
-
|
|
1448
|
-
/* @internal */
|
|
1449
|
-
export const withRequestBatching = dual<
|
|
1450
|
-
(requestBatching: boolean) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1451
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, requestBatching: boolean) => Effect.Effect<A, E, R>
|
|
1452
|
-
>(2, (self, requestBatching) => fiberRefLocally(self, currentRequestBatching, requestBatching))
|
|
1453
|
-
|
|
1454
|
-
/* @internal */
|
|
1455
|
-
export const withRuntimeFlags = dual<
|
|
1456
|
-
(update: RuntimeFlagsPatch.RuntimeFlagsPatch) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1457
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, update: RuntimeFlagsPatch.RuntimeFlagsPatch) => Effect.Effect<A, E, R>
|
|
1458
|
-
>(2, (self, update) => {
|
|
1459
|
-
const effect = new EffectPrimitive(OpCodes.OP_UPDATE_RUNTIME_FLAGS) as any
|
|
1460
|
-
effect.effect_instruction_i0 = update
|
|
1461
|
-
effect.effect_instruction_i1 = () => self
|
|
1462
|
-
return effect
|
|
1463
|
-
})
|
|
1464
|
-
|
|
1465
|
-
/** @internal */
|
|
1466
|
-
export const withTracerEnabled = dual<
|
|
1467
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1468
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1469
|
-
>(2, (effect, enabled) =>
|
|
1470
|
-
fiberRefLocally(
|
|
1471
|
-
effect,
|
|
1472
|
-
currentTracerEnabled,
|
|
1473
|
-
enabled
|
|
1474
|
-
))
|
|
1475
|
-
|
|
1476
|
-
/** @internal */
|
|
1477
|
-
export const withTracerTiming = dual<
|
|
1478
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1479
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1480
|
-
>(2, (effect, enabled) =>
|
|
1481
|
-
fiberRefLocally(
|
|
1482
|
-
effect,
|
|
1483
|
-
currentTracerTimingEnabled,
|
|
1484
|
-
enabled
|
|
1485
|
-
))
|
|
1486
|
-
|
|
1487
|
-
/** @internal */
|
|
1488
|
-
export const withCaptureStackTraces = dual<
|
|
1489
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1490
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1491
|
-
>(2, (effect, enabled) =>
|
|
1492
|
-
fiberRefLocally(
|
|
1493
|
-
effect,
|
|
1494
|
-
currentCaptureStackTraces,
|
|
1495
|
-
enabled
|
|
1496
|
-
))
|
|
1497
|
-
|
|
1498
|
-
/** @internal */
|
|
1499
|
-
export const withCaptureOperations = dual<
|
|
1500
|
-
(enabled: boolean) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
1501
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean) => Effect.Effect<A, E, R>
|
|
1502
|
-
>(2, (effect, enabled) =>
|
|
1503
|
-
fiberRefLocally(
|
|
1504
|
-
effect,
|
|
1505
|
-
currentCaptureOperations,
|
|
1506
|
-
enabled
|
|
1507
|
-
))
|
|
1508
|
-
|
|
1509
|
-
/* @internal */
|
|
1510
|
-
export const yieldNow = (options?: {
|
|
1511
|
-
readonly priority?: number | undefined
|
|
1512
|
-
}): Effect.Effect<void> => {
|
|
1513
|
-
const effect = new EffectPrimitive(OpCodes.OP_YIELD) as any
|
|
1514
|
-
return typeof options?.priority !== "undefined" ?
|
|
1515
|
-
withSchedulingPriority(effect, options.priority) :
|
|
1516
|
-
effect
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
/* @internal */
|
|
1520
|
-
export const zip = dual<
|
|
1521
|
-
<A2, E2, R2>(
|
|
1522
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1523
|
-
) => <A, E, R>(
|
|
1524
|
-
self: Effect.Effect<A, E, R>
|
|
1525
|
-
) => Effect.Effect<[A, A2], E | E2, R | R2>,
|
|
1526
|
-
<A, E, R, A2, E2, R2>(
|
|
1527
|
-
self: Effect.Effect<A, E, R>,
|
|
1528
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1529
|
-
) => Effect.Effect<[A, A2], E | E2, R | R2>
|
|
1530
|
-
>(2, <A, E, R, A2, E2, R2>(
|
|
1531
|
-
self: Effect.Effect<A, E, R>,
|
|
1532
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1533
|
-
): Effect.Effect<[A, A2], E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => [a, b])))
|
|
1534
|
-
|
|
1535
|
-
/* @internal */
|
|
1536
|
-
export const zipFlatten: {
|
|
1537
|
-
<A2, E2, R2>(
|
|
1538
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1539
|
-
): <A extends ReadonlyArray<any>, E, R>(
|
|
1540
|
-
self: Effect.Effect<A, E, R>
|
|
1541
|
-
) => Effect.Effect<[...A, A2], E | E2, R | R2>
|
|
1542
|
-
<A extends ReadonlyArray<any>, E, R, A2, E2, R2>(
|
|
1543
|
-
self: Effect.Effect<A, E, R>,
|
|
1544
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1545
|
-
): Effect.Effect<[...A, A2], E | E2, R | R2>
|
|
1546
|
-
} = dual(2, <A extends ReadonlyArray<any>, E, R, A2, E2, R2>(
|
|
1547
|
-
self: Effect.Effect<A, E, R>,
|
|
1548
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1549
|
-
): Effect.Effect<[...A, A2], E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => [...a, b])))
|
|
1550
|
-
|
|
1551
|
-
/* @internal */
|
|
1552
|
-
export const zipLeft: {
|
|
1553
|
-
<A2, E2, R2>(
|
|
1554
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1555
|
-
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2, R | R2>
|
|
1556
|
-
<A, E, R, A2, E2, R2>(
|
|
1557
|
-
self: Effect.Effect<A, E, R>,
|
|
1558
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1559
|
-
): Effect.Effect<A, E | E2, R | R2>
|
|
1560
|
-
} = dual(2, <A, E, R, A2, E2, R2>(
|
|
1561
|
-
self: Effect.Effect<A, E, R>,
|
|
1562
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1563
|
-
): Effect.Effect<A, E | E2, R | R2> => flatMap(self, (a) => as(that, a)))
|
|
1564
|
-
|
|
1565
|
-
/* @internal */
|
|
1566
|
-
export const zipRight: {
|
|
1567
|
-
<A2, E2, R2>(
|
|
1568
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1569
|
-
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A2, E | E2, R | R2>
|
|
1570
|
-
<A, E, R, A2, E2, R2>(
|
|
1571
|
-
self: Effect.Effect<A, E, R>,
|
|
1572
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1573
|
-
): Effect.Effect<A2, E | E2, R | R2>
|
|
1574
|
-
} = dual(2, <A, E, R, A2, E2, R2>(
|
|
1575
|
-
self: Effect.Effect<A, E, R>,
|
|
1576
|
-
that: Effect.Effect<A2, E2, R2>
|
|
1577
|
-
): Effect.Effect<A2, E | E2, R | R2> => flatMap(self, () => that))
|
|
1578
|
-
|
|
1579
|
-
/* @internal */
|
|
1580
|
-
export const zipWith: {
|
|
1581
|
-
<A2, E2, R2, A, B>(
|
|
1582
|
-
that: Effect.Effect<A2, E2, R2>,
|
|
1583
|
-
f: (a: A, b: A2) => B
|
|
1584
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B, E | E2, R | R2>
|
|
1585
|
-
<A, E, R, A2, E2, R2, B>(
|
|
1586
|
-
self: Effect.Effect<A, E, R>,
|
|
1587
|
-
that: Effect.Effect<A2, E2, R2>,
|
|
1588
|
-
f: (a: A, b: A2) => B
|
|
1589
|
-
): Effect.Effect<B, E | E2, R | R2>
|
|
1590
|
-
} = dual(3, <A, E, R, A2, E2, R2, B>(
|
|
1591
|
-
self: Effect.Effect<A, E, R>,
|
|
1592
|
-
that: Effect.Effect<A2, E2, R2>,
|
|
1593
|
-
f: (a: A, b: A2) => B
|
|
1594
|
-
): Effect.Effect<B, E | E2, R | R2> => flatMap(self, (a) => map(that, (b) => f(a, b))))
|
|
1595
|
-
|
|
1596
|
-
/* @internal */
|
|
1597
|
-
export const never: Effect.Effect<never> = asyncInterrupt<never>(() => {
|
|
1598
|
-
const interval = setInterval(() => {
|
|
1599
|
-
//
|
|
1600
|
-
}, 2 ** 31 - 1)
|
|
1601
|
-
return sync(() => clearInterval(interval))
|
|
1602
|
-
})
|
|
1603
|
-
|
|
1604
|
-
// -----------------------------------------------------------------------------
|
|
1605
|
-
// Fiber
|
|
1606
|
-
// -----------------------------------------------------------------------------
|
|
1607
|
-
|
|
1608
|
-
/* @internal */
|
|
1609
|
-
export const interruptFiber = <A, E>(self: Fiber.Fiber<A, E>): Effect.Effect<Exit.Exit<A, E>> =>
|
|
1610
|
-
flatMap(fiberId, (fiberId) => pipe(self, interruptAsFiber(fiberId)))
|
|
1611
|
-
|
|
1612
|
-
/* @internal */
|
|
1613
|
-
export const interruptAsFiber = dual<
|
|
1614
|
-
(fiberId: FiberId.FiberId) => <A, E>(self: Fiber.Fiber<A, E>) => Effect.Effect<Exit.Exit<A, E>>,
|
|
1615
|
-
<A, E>(self: Fiber.Fiber<A, E>, fiberId: FiberId.FiberId) => Effect.Effect<Exit.Exit<A, E>>
|
|
1616
|
-
>(2, (self, fiberId) => flatMap(self.interruptAsFork(fiberId), () => self.await))
|
|
1617
|
-
|
|
1618
|
-
// -----------------------------------------------------------------------------
|
|
1619
|
-
// LogLevel
|
|
1620
|
-
// -----------------------------------------------------------------------------
|
|
1621
|
-
|
|
1622
|
-
/** @internal */
|
|
1623
|
-
export const logLevelAll: LogLevel.LogLevel = {
|
|
1624
|
-
_tag: "All",
|
|
1625
|
-
syslog: 0,
|
|
1626
|
-
label: "ALL",
|
|
1627
|
-
ordinal: Number.MIN_SAFE_INTEGER,
|
|
1628
|
-
pipe() {
|
|
1629
|
-
return pipeArguments(this, arguments)
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
/** @internal */
|
|
1634
|
-
export const logLevelFatal: LogLevel.LogLevel = {
|
|
1635
|
-
_tag: "Fatal",
|
|
1636
|
-
syslog: 2,
|
|
1637
|
-
label: "FATAL",
|
|
1638
|
-
ordinal: 50000,
|
|
1639
|
-
pipe() {
|
|
1640
|
-
return pipeArguments(this, arguments)
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
/** @internal */
|
|
1645
|
-
export const logLevelError: LogLevel.LogLevel = {
|
|
1646
|
-
_tag: "Error",
|
|
1647
|
-
syslog: 3,
|
|
1648
|
-
label: "ERROR",
|
|
1649
|
-
ordinal: 40000,
|
|
1650
|
-
pipe() {
|
|
1651
|
-
return pipeArguments(this, arguments)
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
/** @internal */
|
|
1656
|
-
export const logLevelWarning: LogLevel.LogLevel = {
|
|
1657
|
-
_tag: "Warning",
|
|
1658
|
-
syslog: 4,
|
|
1659
|
-
label: "WARN",
|
|
1660
|
-
ordinal: 30000,
|
|
1661
|
-
pipe() {
|
|
1662
|
-
return pipeArguments(this, arguments)
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
/** @internal */
|
|
1667
|
-
export const logLevelInfo: LogLevel.LogLevel = {
|
|
1668
|
-
_tag: "Info",
|
|
1669
|
-
syslog: 6,
|
|
1670
|
-
label: "INFO",
|
|
1671
|
-
ordinal: 20000,
|
|
1672
|
-
pipe() {
|
|
1673
|
-
return pipeArguments(this, arguments)
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
/** @internal */
|
|
1678
|
-
export const logLevelDebug: LogLevel.LogLevel = {
|
|
1679
|
-
_tag: "Debug",
|
|
1680
|
-
syslog: 7,
|
|
1681
|
-
label: "DEBUG",
|
|
1682
|
-
ordinal: 10000,
|
|
1683
|
-
pipe() {
|
|
1684
|
-
return pipeArguments(this, arguments)
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
/** @internal */
|
|
1689
|
-
export const logLevelTrace: LogLevel.LogLevel = {
|
|
1690
|
-
_tag: "Trace",
|
|
1691
|
-
syslog: 7,
|
|
1692
|
-
label: "TRACE",
|
|
1693
|
-
ordinal: 0,
|
|
1694
|
-
pipe() {
|
|
1695
|
-
return pipeArguments(this, arguments)
|
|
1696
|
-
}
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
/** @internal */
|
|
1700
|
-
export const logLevelNone: LogLevel.LogLevel = {
|
|
1701
|
-
_tag: "None",
|
|
1702
|
-
syslog: 7,
|
|
1703
|
-
label: "OFF",
|
|
1704
|
-
ordinal: Number.MAX_SAFE_INTEGER,
|
|
1705
|
-
pipe() {
|
|
1706
|
-
return pipeArguments(this, arguments)
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
/** @internal */
|
|
1711
|
-
export const allLogLevels: ReadonlyArray<LogLevel.LogLevel> = [
|
|
1712
|
-
logLevelAll,
|
|
1713
|
-
logLevelTrace,
|
|
1714
|
-
logLevelDebug,
|
|
1715
|
-
logLevelInfo,
|
|
1716
|
-
logLevelWarning,
|
|
1717
|
-
logLevelError,
|
|
1718
|
-
logLevelFatal,
|
|
1719
|
-
logLevelNone
|
|
1720
|
-
]
|
|
1721
|
-
|
|
1722
|
-
// -----------------------------------------------------------------------------
|
|
1723
|
-
// FiberRef
|
|
1724
|
-
// -----------------------------------------------------------------------------
|
|
1725
|
-
|
|
1726
|
-
/** @internal */
|
|
1727
|
-
const FiberRefSymbolKey = "effect/FiberRef"
|
|
1728
|
-
|
|
1729
|
-
/** @internal */
|
|
1730
|
-
export const FiberRefTypeId: FiberRef.FiberRefTypeId = Symbol.for(
|
|
1731
|
-
FiberRefSymbolKey
|
|
1732
|
-
) as FiberRef.FiberRefTypeId
|
|
1733
|
-
|
|
1734
|
-
const fiberRefVariance = {
|
|
1735
|
-
/* c8 ignore next */
|
|
1736
|
-
_A: (_: any) => _
|
|
1737
|
-
}
|
|
1738
|
-
|
|
1739
|
-
/* @internal */
|
|
1740
|
-
export const fiberRefGet = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<A> =>
|
|
1741
|
-
withFiberRuntime((fiber) => exitSucceed(fiber.getFiberRef(self)))
|
|
1742
|
-
|
|
1743
|
-
/* @internal */
|
|
1744
|
-
export const fiberRefGetAndSet = dual<
|
|
1745
|
-
<A>(value: A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,
|
|
1746
|
-
<A>(self: FiberRef.FiberRef<A>, value: A) => Effect.Effect<A>
|
|
1747
|
-
>(2, (self, value) => fiberRefModify(self, (v) => [v, value] as const))
|
|
1748
|
-
|
|
1749
|
-
/* @internal */
|
|
1750
|
-
export const fiberRefGetAndUpdate = dual<
|
|
1751
|
-
<A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,
|
|
1752
|
-
<A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<A>
|
|
1753
|
-
>(2, (self, f) => fiberRefModify(self, (v) => [v, f(v)] as const))
|
|
1754
|
-
|
|
1755
|
-
/* @internal */
|
|
1756
|
-
export const fiberRefGetAndUpdateSome = dual<
|
|
1757
|
-
<A>(
|
|
1758
|
-
pf: (a: A) => Option.Option<A>
|
|
1759
|
-
) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,
|
|
1760
|
-
<A>(
|
|
1761
|
-
self: FiberRef.FiberRef<A>,
|
|
1762
|
-
pf: (a: A) => Option.Option<A>
|
|
1763
|
-
) => Effect.Effect<A>
|
|
1764
|
-
>(2, (self, pf) => fiberRefModify(self, (v) => [v, Option.getOrElse(pf(v), () => v)] as const))
|
|
1765
|
-
|
|
1766
|
-
/* @internal */
|
|
1767
|
-
export const fiberRefGetWith = dual<
|
|
1768
|
-
<B, E, R, A>(f: (a: A) => Effect.Effect<B, E, R>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<B, E, R>,
|
|
1769
|
-
<A, B, E, R>(self: FiberRef.FiberRef<A>, f: (a: A) => Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>
|
|
1770
|
-
>(2, (self, f) => flatMap(fiberRefGet(self), f))
|
|
1771
|
-
|
|
1772
|
-
/* @internal */
|
|
1773
|
-
export const fiberRefSet = dual<
|
|
1774
|
-
<A>(value: A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,
|
|
1775
|
-
<A>(self: FiberRef.FiberRef<A>, value: A) => Effect.Effect<void>
|
|
1776
|
-
>(2, (self, value) => fiberRefModify(self, () => [void 0, value] as const))
|
|
1777
|
-
|
|
1778
|
-
/* @internal */
|
|
1779
|
-
export const fiberRefDelete = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<void> =>
|
|
1780
|
-
withFiberRuntime((state) => {
|
|
1781
|
-
state.unsafeDeleteFiberRef(self)
|
|
1782
|
-
return void_
|
|
1783
|
-
})
|
|
1784
|
-
|
|
1785
|
-
/* @internal */
|
|
1786
|
-
export const fiberRefReset = <A>(self: FiberRef.FiberRef<A>): Effect.Effect<void> => fiberRefSet(self, self.initial)
|
|
1787
|
-
|
|
1788
|
-
/* @internal */
|
|
1789
|
-
export const fiberRefModify = dual<
|
|
1790
|
-
<A, B>(f: (a: A) => readonly [B, A]) => (self: FiberRef.FiberRef<A>) => Effect.Effect<B>,
|
|
1791
|
-
<A, B>(self: FiberRef.FiberRef<A>, f: (a: A) => readonly [B, A]) => Effect.Effect<B>
|
|
1792
|
-
>(2, <A, B>(
|
|
1793
|
-
self: FiberRef.FiberRef<A>,
|
|
1794
|
-
f: (a: A) => readonly [B, A]
|
|
1795
|
-
): Effect.Effect<B> =>
|
|
1796
|
-
withFiberRuntime((state) => {
|
|
1797
|
-
const [b, a] = f(state.getFiberRef(self) as A)
|
|
1798
|
-
state.setFiberRef(self, a)
|
|
1799
|
-
return succeed(b)
|
|
1800
|
-
}))
|
|
1801
|
-
|
|
1802
|
-
/* @internal */
|
|
1803
|
-
export const fiberRefModifySome = <A, B>(
|
|
1804
|
-
self: FiberRef.FiberRef<A>,
|
|
1805
|
-
def: B,
|
|
1806
|
-
f: (a: A) => Option.Option<readonly [B, A]>
|
|
1807
|
-
): Effect.Effect<B> => fiberRefModify(self, (v) => Option.getOrElse(f(v), () => [def, v] as const))
|
|
1808
|
-
|
|
1809
|
-
/* @internal */
|
|
1810
|
-
export const fiberRefUpdate = dual<
|
|
1811
|
-
<A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,
|
|
1812
|
-
<A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<void>
|
|
1813
|
-
>(2, (self, f) => fiberRefModify(self, (v) => [void 0, f(v)] as const))
|
|
1814
|
-
|
|
1815
|
-
/* @internal */
|
|
1816
|
-
export const fiberRefUpdateSome = dual<
|
|
1817
|
-
<A>(pf: (a: A) => Option.Option<A>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<void>,
|
|
1818
|
-
<A>(self: FiberRef.FiberRef<A>, pf: (a: A) => Option.Option<A>) => Effect.Effect<void>
|
|
1819
|
-
>(2, (self, pf) => fiberRefModify(self, (v) => [void 0, Option.getOrElse(pf(v), () => v)] as const))
|
|
1820
|
-
|
|
1821
|
-
/* @internal */
|
|
1822
|
-
export const fiberRefUpdateAndGet = dual<
|
|
1823
|
-
<A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,
|
|
1824
|
-
<A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<A>
|
|
1825
|
-
>(2, (self, f) =>
|
|
1826
|
-
fiberRefModify(self, (v) => {
|
|
1827
|
-
const result = f(v)
|
|
1828
|
-
return [result, result] as const
|
|
1829
|
-
}))
|
|
1830
|
-
|
|
1831
|
-
/* @internal */
|
|
1832
|
-
export const fiberRefUpdateSomeAndGet = dual<
|
|
1833
|
-
<A>(pf: (a: A) => Option.Option<A>) => (self: FiberRef.FiberRef<A>) => Effect.Effect<A>,
|
|
1834
|
-
<A>(self: FiberRef.FiberRef<A>, pf: (a: A) => Option.Option<A>) => Effect.Effect<A>
|
|
1835
|
-
>(2, (self, pf) =>
|
|
1836
|
-
fiberRefModify(self, (v) => {
|
|
1837
|
-
const result = Option.getOrElse(pf(v), () => v)
|
|
1838
|
-
return [result, result] as const
|
|
1839
|
-
}))
|
|
1840
|
-
|
|
1841
|
-
// circular
|
|
1842
|
-
/** @internal */
|
|
1843
|
-
const RequestResolverSymbolKey = "effect/RequestResolver"
|
|
1844
|
-
|
|
1845
|
-
/** @internal */
|
|
1846
|
-
export const RequestResolverTypeId: RequestResolver.RequestResolverTypeId = Symbol.for(
|
|
1847
|
-
RequestResolverSymbolKey
|
|
1848
|
-
) as RequestResolver.RequestResolverTypeId
|
|
1849
|
-
|
|
1850
|
-
const requestResolverVariance = {
|
|
1851
|
-
/* c8 ignore next */
|
|
1852
|
-
_A: (_: unknown) => _,
|
|
1853
|
-
/* c8 ignore next */
|
|
1854
|
-
_R: (_: never) => _
|
|
1855
|
-
}
|
|
1856
|
-
|
|
1857
|
-
/** @internal */
|
|
1858
|
-
export class RequestResolverImpl<in A, out R> implements RequestResolver.RequestResolver<A, R> {
|
|
1859
|
-
readonly [RequestResolverTypeId] = requestResolverVariance
|
|
1860
|
-
constructor(
|
|
1861
|
-
readonly runAll: (
|
|
1862
|
-
requests: Array<Array<Request.Entry<A>>>
|
|
1863
|
-
) => Effect.Effect<void, never, R>,
|
|
1864
|
-
readonly target?: unknown
|
|
1865
|
-
) {
|
|
1866
|
-
}
|
|
1867
|
-
[Hash.symbol](): number {
|
|
1868
|
-
return Hash.cached(this, this.target ? Hash.hash(this.target) : Hash.random(this))
|
|
1869
|
-
}
|
|
1870
|
-
[Equal.symbol](that: unknown): boolean {
|
|
1871
|
-
return this.target ?
|
|
1872
|
-
isRequestResolver(that) && Equal.equals(this.target, (that as RequestResolverImpl<any, any>).target) :
|
|
1873
|
-
this === that
|
|
1874
|
-
}
|
|
1875
|
-
identified(...ids: Array<unknown>): RequestResolver.RequestResolver<A, R> {
|
|
1876
|
-
return new RequestResolverImpl(this.runAll, Chunk.fromIterable(ids))
|
|
1877
|
-
}
|
|
1878
|
-
pipe() {
|
|
1879
|
-
return pipeArguments(this, arguments)
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
/** @internal */
|
|
1884
|
-
export const isRequestResolver = (u: unknown): u is RequestResolver.RequestResolver<unknown, unknown> =>
|
|
1885
|
-
hasProperty(u, RequestResolverTypeId)
|
|
1886
|
-
|
|
1887
|
-
// end
|
|
1888
|
-
|
|
1889
|
-
/** @internal */
|
|
1890
|
-
export const resolverLocally = dual<
|
|
1891
|
-
<A>(
|
|
1892
|
-
self: FiberRef.FiberRef<A>,
|
|
1893
|
-
value: A
|
|
1894
|
-
) => <R, B extends Request.Request<any, any>>(
|
|
1895
|
-
use: RequestResolver.RequestResolver<B, R>
|
|
1896
|
-
) => RequestResolver.RequestResolver<B, R>,
|
|
1897
|
-
<R, B extends Request.Request<any, any>, A>(
|
|
1898
|
-
use: RequestResolver.RequestResolver<B, R>,
|
|
1899
|
-
self: FiberRef.FiberRef<A>,
|
|
1900
|
-
value: A
|
|
1901
|
-
) => RequestResolver.RequestResolver<B, R>
|
|
1902
|
-
>(3, <R, B extends Request.Request<any, any>, A>(
|
|
1903
|
-
use: RequestResolver.RequestResolver<B, R>,
|
|
1904
|
-
self: FiberRef.FiberRef<A>,
|
|
1905
|
-
value: A
|
|
1906
|
-
): RequestResolver.RequestResolver<B, R> =>
|
|
1907
|
-
new RequestResolverImpl<B, R>(
|
|
1908
|
-
(requests) =>
|
|
1909
|
-
fiberRefLocally(
|
|
1910
|
-
use.runAll(requests),
|
|
1911
|
-
self,
|
|
1912
|
-
value
|
|
1913
|
-
),
|
|
1914
|
-
Chunk.make("Locally", use, self, value)
|
|
1915
|
-
))
|
|
1916
|
-
|
|
1917
|
-
/** @internal */
|
|
1918
|
-
export const requestBlockLocally = <A>(
|
|
1919
|
-
self: BlockedRequests.RequestBlock,
|
|
1920
|
-
ref: FiberRef.FiberRef<A>,
|
|
1921
|
-
value: A
|
|
1922
|
-
): BlockedRequests.RequestBlock => blockedRequests_.reduce(self, LocallyReducer(ref, value))
|
|
1923
|
-
|
|
1924
|
-
const LocallyReducer = <A>(
|
|
1925
|
-
ref: FiberRef.FiberRef<A>,
|
|
1926
|
-
value: A
|
|
1927
|
-
): BlockedRequests.RequestBlock.Reducer<BlockedRequests.RequestBlock> => ({
|
|
1928
|
-
emptyCase: () => blockedRequests_.empty,
|
|
1929
|
-
parCase: (left, right) => blockedRequests_.par(left, right),
|
|
1930
|
-
seqCase: (left, right) => blockedRequests_.seq(left, right),
|
|
1931
|
-
singleCase: (dataSource, blockedRequest) =>
|
|
1932
|
-
blockedRequests_.single(
|
|
1933
|
-
resolverLocally(dataSource, ref, value),
|
|
1934
|
-
blockedRequest as any
|
|
1935
|
-
)
|
|
1936
|
-
})
|
|
1937
|
-
|
|
1938
|
-
/* @internal */
|
|
1939
|
-
export const fiberRefLocally: {
|
|
1940
|
-
<A>(self: FiberRef.FiberRef<A>, value: A): <B, E, R>(use: Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>
|
|
1941
|
-
<B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, value: A): Effect.Effect<B, E, R>
|
|
1942
|
-
} = dual(
|
|
1943
|
-
3,
|
|
1944
|
-
<B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, value: A): Effect.Effect<B, E, R> =>
|
|
1945
|
-
acquireUseRelease(
|
|
1946
|
-
zipLeft(fiberRefGet(self), fiberRefSet(self, value)),
|
|
1947
|
-
() => use,
|
|
1948
|
-
(oldValue) => fiberRefSet(self, oldValue)
|
|
1949
|
-
)
|
|
1950
|
-
)
|
|
1951
|
-
|
|
1952
|
-
/* @internal */
|
|
1953
|
-
export const fiberRefLocallyWith = dual<
|
|
1954
|
-
<A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => <B, E, R>(use: Effect.Effect<B, E, R>) => Effect.Effect<B, E, R>,
|
|
1955
|
-
<B, E, R, A>(use: Effect.Effect<B, E, R>, self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<B, E, R>
|
|
1956
|
-
>(3, (use, self, f) => fiberRefGetWith(self, (a) => fiberRefLocally(use, self, f(a))))
|
|
1957
|
-
|
|
1958
|
-
/** @internal */
|
|
1959
|
-
export const fiberRefUnsafeMake = <Value>(
|
|
1960
|
-
initial: Value,
|
|
1961
|
-
options?: {
|
|
1962
|
-
readonly fork?: ((a: Value) => Value) | undefined
|
|
1963
|
-
readonly join?: ((left: Value, right: Value) => Value) | undefined
|
|
1964
|
-
}
|
|
1965
|
-
): FiberRef.FiberRef<Value> =>
|
|
1966
|
-
fiberRefUnsafeMakePatch(initial, {
|
|
1967
|
-
differ: internalDiffer.update(),
|
|
1968
|
-
fork: options?.fork ?? identity,
|
|
1969
|
-
join: options?.join
|
|
1970
|
-
})
|
|
1971
|
-
|
|
1972
|
-
/** @internal */
|
|
1973
|
-
export const fiberRefUnsafeMakeHashSet = <A>(
|
|
1974
|
-
initial: HashSet.HashSet<A>
|
|
1975
|
-
): FiberRef.FiberRef<HashSet.HashSet<A>> => {
|
|
1976
|
-
const differ = internalDiffer.hashSet<A>()
|
|
1977
|
-
return fiberRefUnsafeMakePatch(initial, {
|
|
1978
|
-
differ,
|
|
1979
|
-
fork: differ.empty
|
|
1980
|
-
})
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
/** @internal */
|
|
1984
|
-
export const fiberRefUnsafeMakeReadonlyArray = <A>(
|
|
1985
|
-
initial: ReadonlyArray<A>
|
|
1986
|
-
): FiberRef.FiberRef<ReadonlyArray<A>> => {
|
|
1987
|
-
const differ = internalDiffer.readonlyArray(internalDiffer.update<A>())
|
|
1988
|
-
return fiberRefUnsafeMakePatch(initial, {
|
|
1989
|
-
differ,
|
|
1990
|
-
fork: differ.empty
|
|
1991
|
-
})
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
/** @internal */
|
|
1995
|
-
export const fiberRefUnsafeMakeContext = <A>(
|
|
1996
|
-
initial: Context.Context<A>
|
|
1997
|
-
): FiberRef.FiberRef<Context.Context<A>> => {
|
|
1998
|
-
const differ = internalDiffer.environment<A>()
|
|
1999
|
-
return fiberRefUnsafeMakePatch(initial, {
|
|
2000
|
-
differ,
|
|
2001
|
-
fork: differ.empty
|
|
2002
|
-
})
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
/** @internal */
|
|
2006
|
-
export const fiberRefUnsafeMakePatch = <Value, Patch>(
|
|
2007
|
-
initial: Value,
|
|
2008
|
-
options: {
|
|
2009
|
-
readonly differ: Differ.Differ<Value, Patch>
|
|
2010
|
-
readonly fork: Patch
|
|
2011
|
-
readonly join?: ((oldV: Value, newV: Value) => Value) | undefined
|
|
2012
|
-
}
|
|
2013
|
-
): FiberRef.FiberRef<Value> => {
|
|
2014
|
-
const _fiberRef = {
|
|
2015
|
-
...CommitPrototype,
|
|
2016
|
-
[FiberRefTypeId]: fiberRefVariance,
|
|
2017
|
-
initial,
|
|
2018
|
-
commit() {
|
|
2019
|
-
return fiberRefGet(this)
|
|
2020
|
-
},
|
|
2021
|
-
diff: (oldValue: Value, newValue: Value) => options.differ.diff(oldValue, newValue),
|
|
2022
|
-
combine: (first: Patch, second: Patch) => options.differ.combine(first, second),
|
|
2023
|
-
patch: (patch: Patch) => (oldValue: Value) => options.differ.patch(patch, oldValue),
|
|
2024
|
-
fork: options.fork,
|
|
2025
|
-
join: options.join ?? ((_, n) => n)
|
|
2026
|
-
}
|
|
2027
|
-
return _fiberRef
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
/** @internal */
|
|
2031
|
-
export const fiberRefUnsafeMakeRuntimeFlags = (
|
|
2032
|
-
initial: RuntimeFlags.RuntimeFlags
|
|
2033
|
-
): FiberRef.FiberRef<RuntimeFlags.RuntimeFlags> =>
|
|
2034
|
-
fiberRefUnsafeMakePatch(initial, {
|
|
2035
|
-
differ: runtimeFlags_.differ,
|
|
2036
|
-
fork: runtimeFlags_.differ.empty
|
|
2037
|
-
})
|
|
2038
|
-
|
|
2039
|
-
/** @internal */
|
|
2040
|
-
export const currentContext: FiberRef.FiberRef<Context.Context<never>> = globalValue(
|
|
2041
|
-
Symbol.for("effect/FiberRef/currentContext"),
|
|
2042
|
-
() => fiberRefUnsafeMakeContext(Context.empty())
|
|
2043
|
-
)
|
|
2044
|
-
|
|
2045
|
-
/** @internal */
|
|
2046
|
-
export const currentSchedulingPriority: FiberRef.FiberRef<number> = globalValue(
|
|
2047
|
-
Symbol.for("effect/FiberRef/currentSchedulingPriority"),
|
|
2048
|
-
() => fiberRefUnsafeMake(0)
|
|
2049
|
-
)
|
|
2050
|
-
|
|
2051
|
-
/** @internal */
|
|
2052
|
-
export const currentMaxOpsBeforeYield: FiberRef.FiberRef<number> = globalValue(
|
|
2053
|
-
Symbol.for("effect/FiberRef/currentMaxOpsBeforeYield"),
|
|
2054
|
-
() => fiberRefUnsafeMake(2048)
|
|
2055
|
-
)
|
|
2056
|
-
|
|
2057
|
-
/** @internal */
|
|
2058
|
-
export const currentLogAnnotations: FiberRef.FiberRef<HashMap.HashMap<string, unknown>> = globalValue(
|
|
2059
|
-
Symbol.for("effect/FiberRef/currentLogAnnotation"),
|
|
2060
|
-
() => fiberRefUnsafeMake(HashMap.empty())
|
|
2061
|
-
)
|
|
2062
|
-
|
|
2063
|
-
/** @internal */
|
|
2064
|
-
export const currentLogLevel: FiberRef.FiberRef<LogLevel.LogLevel> = globalValue(
|
|
2065
|
-
Symbol.for("effect/FiberRef/currentLogLevel"),
|
|
2066
|
-
() => fiberRefUnsafeMake<LogLevel.LogLevel>(logLevelInfo)
|
|
2067
|
-
)
|
|
2068
|
-
|
|
2069
|
-
/** @internal */
|
|
2070
|
-
export const currentLogSpan: FiberRef.FiberRef<List.List<LogSpan.LogSpan>> = globalValue(
|
|
2071
|
-
Symbol.for("effect/FiberRef/currentLogSpan"),
|
|
2072
|
-
() => fiberRefUnsafeMake(List.empty<LogSpan.LogSpan>())
|
|
2073
|
-
)
|
|
2074
|
-
|
|
2075
|
-
/** @internal */
|
|
2076
|
-
export const withSchedulingPriority = dual<
|
|
2077
|
-
(priority: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
2078
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, priority: number) => Effect.Effect<A, E, R>
|
|
2079
|
-
>(2, (self, scheduler) => fiberRefLocally(self, currentSchedulingPriority, scheduler))
|
|
2080
|
-
|
|
2081
|
-
/** @internal */
|
|
2082
|
-
export const withMaxOpsBeforeYield = dual<
|
|
2083
|
-
(priority: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
2084
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, priority: number) => Effect.Effect<A, E, R>
|
|
2085
|
-
>(2, (self, scheduler) => fiberRefLocally(self, currentMaxOpsBeforeYield, scheduler))
|
|
2086
|
-
|
|
2087
|
-
/** @internal */
|
|
2088
|
-
export const currentConcurrency: FiberRef.FiberRef<"unbounded" | number> = globalValue(
|
|
2089
|
-
Symbol.for("effect/FiberRef/currentConcurrency"),
|
|
2090
|
-
() => fiberRefUnsafeMake<"unbounded" | number>("unbounded")
|
|
2091
|
-
)
|
|
2092
|
-
|
|
2093
|
-
/**
|
|
2094
|
-
* @internal
|
|
2095
|
-
*/
|
|
2096
|
-
export const currentRequestBatching = globalValue(
|
|
2097
|
-
Symbol.for("effect/FiberRef/currentRequestBatching"),
|
|
2098
|
-
() => fiberRefUnsafeMake(true)
|
|
2099
|
-
)
|
|
2100
|
-
|
|
2101
|
-
/** @internal */
|
|
2102
|
-
export const currentUnhandledErrorLogLevel: FiberRef.FiberRef<Option.Option<LogLevel.LogLevel>> = globalValue(
|
|
2103
|
-
Symbol.for("effect/FiberRef/currentUnhandledErrorLogLevel"),
|
|
2104
|
-
() => fiberRefUnsafeMake(Option.some<LogLevel.LogLevel>(logLevelDebug))
|
|
2105
|
-
)
|
|
2106
|
-
|
|
2107
|
-
/** @internal */
|
|
2108
|
-
export const currentVersionMismatchErrorLogLevel: FiberRef.FiberRef<Option.Option<LogLevel.LogLevel>> = globalValue(
|
|
2109
|
-
Symbol.for("effect/FiberRef/versionMismatchErrorLogLevel"),
|
|
2110
|
-
() => fiberRefUnsafeMake(Option.some<LogLevel.LogLevel>(logLevelWarning))
|
|
2111
|
-
)
|
|
2112
|
-
|
|
2113
|
-
/** @internal */
|
|
2114
|
-
export const withUnhandledErrorLogLevel = dual<
|
|
2115
|
-
(level: Option.Option<LogLevel.LogLevel>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
2116
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, level: Option.Option<LogLevel.LogLevel>) => Effect.Effect<A, E, R>
|
|
2117
|
-
>(2, (self, level) => fiberRefLocally(self, currentUnhandledErrorLogLevel, level))
|
|
2118
|
-
|
|
2119
|
-
/** @internal */
|
|
2120
|
-
export const currentMetricLabels: FiberRef.FiberRef<ReadonlyArray<MetricLabel.MetricLabel>> = globalValue(
|
|
2121
|
-
Symbol.for("effect/FiberRef/currentMetricLabels"),
|
|
2122
|
-
() => fiberRefUnsafeMakeReadonlyArray(Arr.empty())
|
|
2123
|
-
)
|
|
2124
|
-
|
|
2125
|
-
/* @internal */
|
|
2126
|
-
export const metricLabels: Effect.Effect<ReadonlyArray<MetricLabel.MetricLabel>> = fiberRefGet(
|
|
2127
|
-
currentMetricLabels
|
|
2128
|
-
)
|
|
2129
|
-
|
|
2130
|
-
/** @internal */
|
|
2131
|
-
export const currentForkScopeOverride: FiberRef.FiberRef<Option.Option<fiberScope.FiberScope>> = globalValue(
|
|
2132
|
-
Symbol.for("effect/FiberRef/currentForkScopeOverride"),
|
|
2133
|
-
() =>
|
|
2134
|
-
fiberRefUnsafeMake(Option.none(), {
|
|
2135
|
-
fork: () => Option.none() as Option.Option<fiberScope.FiberScope>,
|
|
2136
|
-
join: (parent, _) => parent
|
|
2137
|
-
})
|
|
2138
|
-
)
|
|
2139
|
-
|
|
2140
|
-
/** @internal */
|
|
2141
|
-
export const currentInterruptedCause: FiberRef.FiberRef<Cause.Cause<never>> = globalValue(
|
|
2142
|
-
Symbol.for("effect/FiberRef/currentInterruptedCause"),
|
|
2143
|
-
() =>
|
|
2144
|
-
fiberRefUnsafeMake(internalCause.empty, {
|
|
2145
|
-
fork: () => internalCause.empty,
|
|
2146
|
-
join: (parent, _) => parent
|
|
2147
|
-
})
|
|
2148
|
-
)
|
|
2149
|
-
|
|
2150
|
-
/** @internal */
|
|
2151
|
-
export const currentTracerEnabled: FiberRef.FiberRef<boolean> = globalValue(
|
|
2152
|
-
Symbol.for("effect/FiberRef/currentTracerEnabled"),
|
|
2153
|
-
() => fiberRefUnsafeMake(true)
|
|
2154
|
-
)
|
|
2155
|
-
|
|
2156
|
-
/** @internal */
|
|
2157
|
-
export const currentTracerTimingEnabled: FiberRef.FiberRef<boolean> = globalValue(
|
|
2158
|
-
Symbol.for("effect/FiberRef/currentTracerTiming"),
|
|
2159
|
-
() => fiberRefUnsafeMake(true)
|
|
2160
|
-
)
|
|
2161
|
-
|
|
2162
|
-
/** @internal */
|
|
2163
|
-
export const currentTracerSpanAnnotations: FiberRef.FiberRef<HashMap.HashMap<string, unknown>> = globalValue(
|
|
2164
|
-
Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"),
|
|
2165
|
-
() => fiberRefUnsafeMake(HashMap.empty())
|
|
2166
|
-
)
|
|
2167
|
-
|
|
2168
|
-
/** @internal */
|
|
2169
|
-
export const currentTracerSpanLinks: FiberRef.FiberRef<Chunk.Chunk<Tracer.SpanLink>> = globalValue(
|
|
2170
|
-
Symbol.for("effect/FiberRef/currentTracerSpanLinks"),
|
|
2171
|
-
() => fiberRefUnsafeMake(Chunk.empty())
|
|
2172
|
-
)
|
|
2173
|
-
|
|
2174
|
-
// -----------------------------------------------------------------------------
|
|
2175
|
-
// Source Location Capture
|
|
2176
|
-
// -----------------------------------------------------------------------------
|
|
2177
|
-
|
|
2178
|
-
/**
|
|
2179
|
-
* Represents a source code location captured from a stack trace.
|
|
2180
|
-
* @internal
|
|
2181
|
-
*/
|
|
2182
|
-
export interface SourceLocation {
|
|
2183
|
-
readonly file: string
|
|
2184
|
-
readonly line: number
|
|
2185
|
-
readonly column: number
|
|
2186
|
-
readonly functionName?: string
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
/**
|
|
2190
|
-
* Represents metadata for a high-level Effect operation.
|
|
2191
|
-
* Stored in the `trace` field of Effect primitives when operation tracing is enabled.
|
|
2192
|
-
* The `_tag` field identifies this as operation metadata for use by supervisors.
|
|
2193
|
-
* @internal
|
|
2194
|
-
*/
|
|
2195
|
-
export interface OperationMeta {
|
|
2196
|
-
readonly _tag: "OperationMeta" // Tag to identify operation metadata
|
|
2197
|
-
readonly op: string // Operation name: 'all', 'forEach', 'retry', etc.
|
|
2198
|
-
readonly count?: number // Item count for all/forEach
|
|
2199
|
-
readonly capturedAt: string // Stack trace captured at creation time
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
|
-
/**
|
|
2203
|
-
* Creates operation metadata for tracing high-level Effect operations.
|
|
2204
|
-
* @internal
|
|
2205
|
-
*/
|
|
2206
|
-
export const makeOperationMeta = (
|
|
2207
|
-
op: string,
|
|
2208
|
-
capturedAt: string,
|
|
2209
|
-
count?: number
|
|
2210
|
-
): OperationMeta => {
|
|
2211
|
-
const meta: OperationMeta = {
|
|
2212
|
-
_tag: "OperationMeta",
|
|
2213
|
-
op,
|
|
2214
|
-
capturedAt
|
|
2215
|
-
}
|
|
2216
|
-
if (count !== undefined) {
|
|
2217
|
-
(meta as { count?: number }).count = count
|
|
2218
|
-
}
|
|
2219
|
-
return meta
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
/**
|
|
2223
|
-
* FiberRef that controls whether operation tracing is enabled.
|
|
2224
|
-
* When enabled, high-level operations like Effect.all, Effect.forEach
|
|
2225
|
-
* capture their call site and store metadata in the trace field.
|
|
2226
|
-
* @internal
|
|
2227
|
-
*/
|
|
2228
|
-
export const currentCaptureOperations: FiberRef.FiberRef<boolean> = globalValue(
|
|
2229
|
-
Symbol.for("effect/FiberRef/currentCaptureOperations"),
|
|
2230
|
-
() => fiberRefUnsafeMake(false)
|
|
2231
|
-
)
|
|
2232
|
-
|
|
2233
|
-
/**
|
|
2234
|
-
* FiberRef that controls whether source location capture is enabled.
|
|
2235
|
-
* When enabled, `Effect.fork` captures the call site and stores it
|
|
2236
|
-
* in `currentSourceLocation` for use by Supervisors.
|
|
2237
|
-
* @internal
|
|
2238
|
-
*/
|
|
2239
|
-
export const currentCaptureStackTraces: FiberRef.FiberRef<boolean> = globalValue(
|
|
2240
|
-
Symbol.for("effect/FiberRef/currentCaptureStackTraces"),
|
|
2241
|
-
() => fiberRefUnsafeMake(false)
|
|
2242
|
-
)
|
|
2243
|
-
|
|
2244
|
-
/**
|
|
2245
|
-
* FiberRef that holds the captured source location for a fiber.
|
|
2246
|
-
* This is set by `Effect.fork` when `currentCaptureStackTraces` is enabled.
|
|
2247
|
-
* Each fiber gets its own location (not propagated to children).
|
|
2248
|
-
* @internal
|
|
2249
|
-
*/
|
|
2250
|
-
export const currentSourceLocation: FiberRef.FiberRef<SourceLocation | undefined> = globalValue(
|
|
2251
|
-
Symbol.for("effect/FiberRef/currentSourceLocation"),
|
|
2252
|
-
() =>
|
|
2253
|
-
fiberRefUnsafeMake<SourceLocation | undefined>(undefined, {
|
|
2254
|
-
fork: () => undefined, // Don't propagate - each fiber gets its own
|
|
2255
|
-
join: (parent, _) => parent
|
|
2256
|
-
})
|
|
2257
|
-
)
|
|
2258
|
-
|
|
2259
|
-
// -----------------------------------------------------------------------------
|
|
2260
|
-
// Scope
|
|
2261
|
-
// -----------------------------------------------------------------------------
|
|
2262
|
-
|
|
2263
|
-
/** @internal */
|
|
2264
|
-
export const ScopeTypeId: Scope.ScopeTypeId = Symbol.for("effect/Scope") as Scope.ScopeTypeId
|
|
2265
|
-
|
|
2266
|
-
/** @internal */
|
|
2267
|
-
export const CloseableScopeTypeId: Scope.CloseableScopeTypeId = Symbol.for(
|
|
2268
|
-
"effect/CloseableScope"
|
|
2269
|
-
) as Scope.CloseableScopeTypeId
|
|
2270
|
-
|
|
2271
|
-
/* @internal */
|
|
2272
|
-
export const scopeAddFinalizer = (
|
|
2273
|
-
self: Scope.Scope,
|
|
2274
|
-
finalizer: Effect.Effect<unknown>
|
|
2275
|
-
): Effect.Effect<void> => self.addFinalizer(() => asVoid(finalizer))
|
|
2276
|
-
|
|
2277
|
-
/* @internal */
|
|
2278
|
-
export const scopeAddFinalizerExit = (
|
|
2279
|
-
self: Scope.Scope,
|
|
2280
|
-
finalizer: Scope.Scope.Finalizer
|
|
2281
|
-
): Effect.Effect<void> => self.addFinalizer(finalizer)
|
|
2282
|
-
|
|
2283
|
-
/* @internal */
|
|
2284
|
-
export const scopeClose = (
|
|
2285
|
-
self: Scope.Scope.Closeable,
|
|
2286
|
-
exit: Exit.Exit<unknown, unknown>
|
|
2287
|
-
): Effect.Effect<void> => self.close(exit)
|
|
2288
|
-
|
|
2289
|
-
/* @internal */
|
|
2290
|
-
export const scopeFork = (
|
|
2291
|
-
self: Scope.Scope,
|
|
2292
|
-
strategy: ExecutionStrategy.ExecutionStrategy
|
|
2293
|
-
): Effect.Effect<Scope.Scope.Closeable> => self.fork(strategy)
|
|
2294
|
-
|
|
2295
|
-
// -----------------------------------------------------------------------------
|
|
2296
|
-
// Cause
|
|
2297
|
-
// -----------------------------------------------------------------------------
|
|
2298
|
-
|
|
2299
|
-
/** @internal */
|
|
2300
|
-
export const causeSquash = <E>(self: Cause.Cause<E>): unknown => {
|
|
2301
|
-
return causeSquashWith(identity)(self)
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
/** @internal */
|
|
2305
|
-
export const causeSquashWith = dual<
|
|
2306
|
-
<E>(f: (error: E) => unknown) => (self: Cause.Cause<E>) => unknown,
|
|
2307
|
-
<E>(self: Cause.Cause<E>, f: (error: E) => unknown) => unknown
|
|
2308
|
-
>(2, (self, f) => {
|
|
2309
|
-
const option = pipe(self, internalCause.failureOption, Option.map(f))
|
|
2310
|
-
switch (option._tag) {
|
|
2311
|
-
case "None": {
|
|
2312
|
-
return pipe(
|
|
2313
|
-
internalCause.defects(self),
|
|
2314
|
-
Chunk.head,
|
|
2315
|
-
Option.match({
|
|
2316
|
-
onNone: () => {
|
|
2317
|
-
const interrupts = Arr.fromIterable(internalCause.interruptors(self)).flatMap((fiberId) =>
|
|
2318
|
-
Arr.fromIterable(FiberId.ids(fiberId)).map((id) => `#${id}`)
|
|
2319
|
-
)
|
|
2320
|
-
return new InterruptedException(interrupts ? `Interrupted by fibers: ${interrupts.join(", ")}` : void 0)
|
|
2321
|
-
},
|
|
2322
|
-
onSome: identity
|
|
2323
|
-
})
|
|
2324
|
-
)
|
|
2325
|
-
}
|
|
2326
|
-
case "Some": {
|
|
2327
|
-
return option.value
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
})
|
|
2331
|
-
|
|
2332
|
-
// -----------------------------------------------------------------------------
|
|
2333
|
-
// Errors
|
|
2334
|
-
// -----------------------------------------------------------------------------
|
|
2335
|
-
|
|
2336
|
-
/** @internal */
|
|
2337
|
-
export const YieldableError: new(message?: string, options?: ErrorOptions) => Cause.YieldableError = (function() {
|
|
2338
|
-
class YieldableError extends globalThis.Error {
|
|
2339
|
-
commit() {
|
|
2340
|
-
return fail(this)
|
|
2341
|
-
}
|
|
2342
|
-
toJSON() {
|
|
2343
|
-
const obj = { ...this }
|
|
2344
|
-
if (this.message) obj.message = this.message
|
|
2345
|
-
if (this.cause) obj.cause = this.cause
|
|
2346
|
-
return obj
|
|
2347
|
-
}
|
|
2348
|
-
[NodeInspectSymbol]() {
|
|
2349
|
-
if (this.toString !== globalThis.Error.prototype.toString) {
|
|
2350
|
-
return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString()
|
|
2351
|
-
} else if ("Bun" in globalThis) {
|
|
2352
|
-
return internalCause.pretty(internalCause.fail(this), { renderErrorCause: true })
|
|
2353
|
-
}
|
|
2354
|
-
return this
|
|
2355
|
-
}
|
|
2356
|
-
}
|
|
2357
|
-
// @effect-diagnostics-next-line floatingEffect:off
|
|
2358
|
-
Object.assign(YieldableError.prototype, StructuralCommitPrototype)
|
|
2359
|
-
return YieldableError as any
|
|
2360
|
-
})()
|
|
2361
|
-
|
|
2362
|
-
const makeException = <T extends { _tag: string; message?: string }>(
|
|
2363
|
-
proto: Omit<T, keyof Cause.YieldableError | "_tag">,
|
|
2364
|
-
tag: T["_tag"]
|
|
2365
|
-
): new(message?: string | undefined) => T => {
|
|
2366
|
-
class Base extends YieldableError {
|
|
2367
|
-
readonly _tag = tag
|
|
2368
|
-
}
|
|
2369
|
-
Object.assign(Base.prototype, proto)
|
|
2370
|
-
;(Base.prototype as any).name = tag
|
|
2371
|
-
return Base as any
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
/** @internal */
|
|
2375
|
-
export const RuntimeExceptionTypeId: Cause.RuntimeExceptionTypeId = Symbol.for(
|
|
2376
|
-
"effect/Cause/errors/RuntimeException"
|
|
2377
|
-
) as Cause.RuntimeExceptionTypeId
|
|
2378
|
-
|
|
2379
|
-
/** @internal */
|
|
2380
|
-
export const RuntimeException = makeException<Cause.RuntimeException>({
|
|
2381
|
-
[RuntimeExceptionTypeId]: RuntimeExceptionTypeId
|
|
2382
|
-
}, "RuntimeException")
|
|
2383
|
-
|
|
2384
|
-
/** @internal */
|
|
2385
|
-
export const isRuntimeException = (u: unknown): u is Cause.RuntimeException => hasProperty(u, RuntimeExceptionTypeId)
|
|
2386
|
-
|
|
2387
|
-
/** @internal */
|
|
2388
|
-
export const InterruptedExceptionTypeId: Cause.InterruptedExceptionTypeId = Symbol.for(
|
|
2389
|
-
"effect/Cause/errors/InterruptedException"
|
|
2390
|
-
) as Cause.InterruptedExceptionTypeId
|
|
2391
|
-
|
|
2392
|
-
/** @internal */
|
|
2393
|
-
export const InterruptedException = makeException<Cause.InterruptedException>({
|
|
2394
|
-
[InterruptedExceptionTypeId]: InterruptedExceptionTypeId
|
|
2395
|
-
}, "InterruptedException")
|
|
2396
|
-
|
|
2397
|
-
/** @internal */
|
|
2398
|
-
export const isInterruptedException = (u: unknown): u is Cause.InterruptedException =>
|
|
2399
|
-
hasProperty(u, InterruptedExceptionTypeId)
|
|
2400
|
-
|
|
2401
|
-
/** @internal */
|
|
2402
|
-
export const IllegalArgumentExceptionTypeId: Cause.IllegalArgumentExceptionTypeId = Symbol.for(
|
|
2403
|
-
"effect/Cause/errors/IllegalArgument"
|
|
2404
|
-
) as Cause.IllegalArgumentExceptionTypeId
|
|
2405
|
-
|
|
2406
|
-
/** @internal */
|
|
2407
|
-
export const IllegalArgumentException = makeException<Cause.IllegalArgumentException>({
|
|
2408
|
-
[IllegalArgumentExceptionTypeId]: IllegalArgumentExceptionTypeId
|
|
2409
|
-
}, "IllegalArgumentException")
|
|
2410
|
-
|
|
2411
|
-
/** @internal */
|
|
2412
|
-
export const isIllegalArgumentException = (u: unknown): u is Cause.IllegalArgumentException =>
|
|
2413
|
-
hasProperty(u, IllegalArgumentExceptionTypeId)
|
|
2414
|
-
|
|
2415
|
-
/** @internal */
|
|
2416
|
-
export const NoSuchElementExceptionTypeId: Cause.NoSuchElementExceptionTypeId = Symbol.for(
|
|
2417
|
-
"effect/Cause/errors/NoSuchElement"
|
|
2418
|
-
) as Cause.NoSuchElementExceptionTypeId
|
|
2419
|
-
|
|
2420
|
-
/** @internal */
|
|
2421
|
-
export const NoSuchElementException = makeException<Cause.NoSuchElementException>({
|
|
2422
|
-
[NoSuchElementExceptionTypeId]: NoSuchElementExceptionTypeId
|
|
2423
|
-
}, "NoSuchElementException")
|
|
2424
|
-
|
|
2425
|
-
/** @internal */
|
|
2426
|
-
export const isNoSuchElementException = (u: unknown): u is Cause.NoSuchElementException =>
|
|
2427
|
-
hasProperty(u, NoSuchElementExceptionTypeId)
|
|
2428
|
-
|
|
2429
|
-
/** @internal */
|
|
2430
|
-
export const InvalidPubSubCapacityExceptionTypeId: Cause.InvalidPubSubCapacityExceptionTypeId = Symbol.for(
|
|
2431
|
-
"effect/Cause/errors/InvalidPubSubCapacityException"
|
|
2432
|
-
) as Cause.InvalidPubSubCapacityExceptionTypeId
|
|
2433
|
-
|
|
2434
|
-
/** @internal */
|
|
2435
|
-
export const InvalidPubSubCapacityException = makeException<Cause.InvalidPubSubCapacityException>({
|
|
2436
|
-
[InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
|
|
2437
|
-
}, "InvalidPubSubCapacityException")
|
|
2438
|
-
|
|
2439
|
-
/** @internal */
|
|
2440
|
-
export const ExceededCapacityExceptionTypeId: Cause.ExceededCapacityExceptionTypeId = Symbol.for(
|
|
2441
|
-
"effect/Cause/errors/ExceededCapacityException"
|
|
2442
|
-
) as Cause.ExceededCapacityExceptionTypeId
|
|
2443
|
-
|
|
2444
|
-
/** @internal */
|
|
2445
|
-
export const ExceededCapacityException = makeException<Cause.ExceededCapacityException>({
|
|
2446
|
-
[ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
|
|
2447
|
-
}, "ExceededCapacityException")
|
|
2448
|
-
|
|
2449
|
-
/** @internal */
|
|
2450
|
-
export const isExceededCapacityException = (u: unknown): u is Cause.ExceededCapacityException =>
|
|
2451
|
-
hasProperty(u, ExceededCapacityExceptionTypeId)
|
|
2452
|
-
|
|
2453
|
-
/** @internal */
|
|
2454
|
-
export const isInvalidCapacityError = (u: unknown): u is Cause.InvalidPubSubCapacityException =>
|
|
2455
|
-
hasProperty(u, InvalidPubSubCapacityExceptionTypeId)
|
|
2456
|
-
|
|
2457
|
-
/** @internal */
|
|
2458
|
-
export const TimeoutExceptionTypeId: Cause.TimeoutExceptionTypeId = Symbol.for(
|
|
2459
|
-
"effect/Cause/errors/Timeout"
|
|
2460
|
-
) as Cause.TimeoutExceptionTypeId
|
|
2461
|
-
|
|
2462
|
-
/** @internal */
|
|
2463
|
-
export const TimeoutException = makeException<Cause.TimeoutException>({
|
|
2464
|
-
[TimeoutExceptionTypeId]: TimeoutExceptionTypeId
|
|
2465
|
-
}, "TimeoutException")
|
|
2466
|
-
|
|
2467
|
-
/** @internal */
|
|
2468
|
-
export const timeoutExceptionFromDuration = (duration: Duration.DurationInput): Cause.TimeoutException =>
|
|
2469
|
-
new TimeoutException(`Operation timed out after '${Duration.format(duration)}'`)
|
|
2470
|
-
|
|
2471
|
-
/** @internal */
|
|
2472
|
-
export const isTimeoutException = (u: unknown): u is Cause.TimeoutException => hasProperty(u, TimeoutExceptionTypeId)
|
|
2473
|
-
|
|
2474
|
-
/** @internal */
|
|
2475
|
-
export const UnknownExceptionTypeId: Cause.UnknownExceptionTypeId = Symbol.for(
|
|
2476
|
-
"effect/Cause/errors/UnknownException"
|
|
2477
|
-
) as Cause.UnknownExceptionTypeId
|
|
2478
|
-
|
|
2479
|
-
/** @internal */
|
|
2480
|
-
export const UnknownException: new(cause: unknown, message?: string | undefined) => Cause.UnknownException =
|
|
2481
|
-
(function() {
|
|
2482
|
-
class UnknownException extends YieldableError {
|
|
2483
|
-
readonly _tag = "UnknownException"
|
|
2484
|
-
readonly error: unknown
|
|
2485
|
-
constructor(cause: unknown, message?: string) {
|
|
2486
|
-
super(message ?? "An unknown error occurred", { cause })
|
|
2487
|
-
this.error = cause
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2490
|
-
Object.assign(UnknownException.prototype, {
|
|
2491
|
-
[UnknownExceptionTypeId]: UnknownExceptionTypeId,
|
|
2492
|
-
name: "UnknownException"
|
|
2493
|
-
})
|
|
2494
|
-
return UnknownException as any
|
|
2495
|
-
})()
|
|
2496
|
-
|
|
2497
|
-
/** @internal */
|
|
2498
|
-
export const isUnknownException = (u: unknown): u is Cause.UnknownException => hasProperty(u, UnknownExceptionTypeId)
|
|
2499
|
-
|
|
2500
|
-
// -----------------------------------------------------------------------------
|
|
2501
|
-
// Exit
|
|
2502
|
-
// -----------------------------------------------------------------------------
|
|
2503
|
-
|
|
2504
|
-
/** @internal */
|
|
2505
|
-
export const exitIsExit = (u: unknown): u is Exit.Exit<unknown, unknown> =>
|
|
2506
|
-
isEffect(u) && "_tag" in u && (u._tag === "Success" || u._tag === "Failure")
|
|
2507
|
-
|
|
2508
|
-
/** @internal */
|
|
2509
|
-
export const exitIsFailure = <A, E>(self: Exit.Exit<A, E>): self is Exit.Failure<A, E> => self._tag === "Failure"
|
|
2510
|
-
|
|
2511
|
-
/** @internal */
|
|
2512
|
-
export const exitIsSuccess = <A, E>(self: Exit.Exit<A, E>): self is Exit.Success<A, E> => self._tag === "Success"
|
|
2513
|
-
|
|
2514
|
-
/** @internal */
|
|
2515
|
-
export const exitIsInterrupted = <A, E>(self: Exit.Exit<A, E>): boolean => {
|
|
2516
|
-
switch (self._tag) {
|
|
2517
|
-
case OpCodes.OP_FAILURE:
|
|
2518
|
-
return internalCause.isInterrupted(self.effect_instruction_i0)
|
|
2519
|
-
case OpCodes.OP_SUCCESS:
|
|
2520
|
-
return false
|
|
2521
|
-
}
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
/** @internal */
|
|
2525
|
-
export const exitAs = dual<
|
|
2526
|
-
<A2>(value: A2) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E>,
|
|
2527
|
-
<A, E, A2>(self: Exit.Exit<A, E>, value: A2) => Exit.Exit<A2, E>
|
|
2528
|
-
>(2, <A, E, A2>(self: Exit.Exit<A, E>, value: A2): Exit.Exit<A2, E> => {
|
|
2529
|
-
switch (self._tag) {
|
|
2530
|
-
case OpCodes.OP_FAILURE: {
|
|
2531
|
-
return exitFailCause(self.effect_instruction_i0)
|
|
2532
|
-
}
|
|
2533
|
-
case OpCodes.OP_SUCCESS: {
|
|
2534
|
-
return exitSucceed(value) as Exit.Exit<A2, E>
|
|
2535
|
-
}
|
|
2536
|
-
}
|
|
2537
|
-
})
|
|
2538
|
-
|
|
2539
|
-
/** @internal */
|
|
2540
|
-
export const exitAsVoid = <A, E>(self: Exit.Exit<A, E>): Exit.Exit<void, E> => exitAs(self, void 0)
|
|
2541
|
-
|
|
2542
|
-
/** @internal */
|
|
2543
|
-
export const exitCauseOption = <A, E>(self: Exit.Exit<A, E>): Option.Option<Cause.Cause<E>> => {
|
|
2544
|
-
switch (self._tag) {
|
|
2545
|
-
case OpCodes.OP_FAILURE:
|
|
2546
|
-
return Option.some(self.effect_instruction_i0)
|
|
2547
|
-
case OpCodes.OP_SUCCESS:
|
|
2548
|
-
return Option.none()
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
|
|
2552
|
-
/** @internal */
|
|
2553
|
-
export const exitCollectAll = <A, E>(
|
|
2554
|
-
exits: Iterable<Exit.Exit<A, E>>,
|
|
2555
|
-
options?: {
|
|
2556
|
-
readonly parallel?: boolean | undefined
|
|
2557
|
-
}
|
|
2558
|
-
): Option.Option<Exit.Exit<Array<A>, E>> =>
|
|
2559
|
-
exitCollectAllInternal(exits, options?.parallel ? internalCause.parallel : internalCause.sequential)
|
|
2560
|
-
|
|
2561
|
-
/** @internal */
|
|
2562
|
-
export const exitDie = (defect: unknown): Exit.Exit<never> =>
|
|
2563
|
-
exitFailCause(internalCause.die(defect)) as Exit.Exit<never>
|
|
2564
|
-
|
|
2565
|
-
/** @internal */
|
|
2566
|
-
export const exitExists: {
|
|
2567
|
-
<A, B extends A>(refinement: Refinement<NoInfer<A>, B>): <E>(self: Exit.Exit<A, E>) => self is Exit.Exit<B>
|
|
2568
|
-
<A>(predicate: Predicate<NoInfer<A>>): <E>(self: Exit.Exit<A, E>) => boolean
|
|
2569
|
-
<A, E, B extends A>(self: Exit.Exit<A, E>, refinement: Refinement<A, B>): self is Exit.Exit<B>
|
|
2570
|
-
<A, E>(self: Exit.Exit<A, E>, predicate: Predicate<A>): boolean
|
|
2571
|
-
} = dual(2, <A, E, B extends A>(self: Exit.Exit<A, E>, refinement: Refinement<A, B>): self is Exit.Exit<B> => {
|
|
2572
|
-
switch (self._tag) {
|
|
2573
|
-
case OpCodes.OP_FAILURE:
|
|
2574
|
-
return false
|
|
2575
|
-
case OpCodes.OP_SUCCESS:
|
|
2576
|
-
return refinement(self.effect_instruction_i0)
|
|
2577
|
-
}
|
|
2578
|
-
})
|
|
2579
|
-
|
|
2580
|
-
/** @internal */
|
|
2581
|
-
export const exitFail = <E>(error: E): Exit.Exit<never, E> =>
|
|
2582
|
-
exitFailCause(internalCause.fail(error)) as Exit.Exit<never, E>
|
|
2583
|
-
|
|
2584
|
-
/** @internal */
|
|
2585
|
-
export const exitFailCause = <E>(cause: Cause.Cause<E>): Exit.Exit<never, E> => {
|
|
2586
|
-
const effect = new EffectPrimitiveFailure(OpCodes.OP_FAILURE) as any
|
|
2587
|
-
effect.effect_instruction_i0 = cause
|
|
2588
|
-
return effect
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
/** @internal */
|
|
2592
|
-
export const exitFlatMap = dual<
|
|
2593
|
-
<A, A2, E2>(f: (a: A) => Exit.Exit<A2, E2>) => <E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,
|
|
2594
|
-
<A, E, E2, A2>(self: Exit.Exit<A, E>, f: (a: A) => Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>
|
|
2595
|
-
>(2, <A, E, E2, A2>(self: Exit.Exit<A, E>, f: (a: A) => Exit.Exit<A2, E2>): Exit.Exit<A2, E | E2> => {
|
|
2596
|
-
switch (self._tag) {
|
|
2597
|
-
case OpCodes.OP_FAILURE: {
|
|
2598
|
-
return exitFailCause(self.effect_instruction_i0)
|
|
2599
|
-
}
|
|
2600
|
-
case OpCodes.OP_SUCCESS: {
|
|
2601
|
-
return f(self.effect_instruction_i0)
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
})
|
|
2605
|
-
|
|
2606
|
-
/** @internal */
|
|
2607
|
-
export const exitFlatMapEffect: {
|
|
2608
|
-
<A, E, A2, E2, R>(
|
|
2609
|
-
f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>
|
|
2610
|
-
): (self: Exit.Exit<A, E>) => Effect.Effect<Exit.Exit<A2, E>, E2, R>
|
|
2611
|
-
<A, E, A2, E2, R>(
|
|
2612
|
-
self: Exit.Exit<A, E>,
|
|
2613
|
-
f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>
|
|
2614
|
-
): Effect.Effect<Exit.Exit<A2, E>, E2, R>
|
|
2615
|
-
} = dual(2, <A, E, A2, E2, R>(
|
|
2616
|
-
self: Exit.Exit<A, E>,
|
|
2617
|
-
f: (a: A) => Effect.Effect<Exit.Exit<A2, E>, E2, R>
|
|
2618
|
-
): Effect.Effect<Exit.Exit<A2, E>, E2, R> => {
|
|
2619
|
-
switch (self._tag) {
|
|
2620
|
-
case OpCodes.OP_FAILURE: {
|
|
2621
|
-
return succeed(exitFailCause(self.effect_instruction_i0))
|
|
2622
|
-
}
|
|
2623
|
-
case OpCodes.OP_SUCCESS: {
|
|
2624
|
-
return f(self.effect_instruction_i0)
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
})
|
|
2628
|
-
|
|
2629
|
-
/** @internal */
|
|
2630
|
-
export const exitFlatten = <A, E, E2>(
|
|
2631
|
-
self: Exit.Exit<Exit.Exit<A, E>, E2>
|
|
2632
|
-
): Exit.Exit<A, E | E2> => pipe(self, exitFlatMap(identity))
|
|
2633
|
-
|
|
2634
|
-
/** @internal */
|
|
2635
|
-
export const exitForEachEffect: {
|
|
2636
|
-
<A, B, E2, R>(
|
|
2637
|
-
f: (a: A) => Effect.Effect<B, E2, R>
|
|
2638
|
-
): <E>(self: Exit.Exit<A, E>) => Effect.Effect<Exit.Exit<B, E | E2>, never, R>
|
|
2639
|
-
<A, E, B, E2, R>(
|
|
2640
|
-
self: Exit.Exit<A, E>,
|
|
2641
|
-
f: (a: A) => Effect.Effect<B, E2, R>
|
|
2642
|
-
): Effect.Effect<Exit.Exit<B, E | E2>, never, R>
|
|
2643
|
-
} = dual(2, <A, E, B, E2, R>(
|
|
2644
|
-
self: Exit.Exit<A, E>,
|
|
2645
|
-
f: (a: A) => Effect.Effect<B, E2, R>
|
|
2646
|
-
): Effect.Effect<Exit.Exit<B, E | E2>, never, R> => {
|
|
2647
|
-
switch (self._tag) {
|
|
2648
|
-
case OpCodes.OP_FAILURE: {
|
|
2649
|
-
return succeed(exitFailCause(self.effect_instruction_i0))
|
|
2650
|
-
}
|
|
2651
|
-
case OpCodes.OP_SUCCESS: {
|
|
2652
|
-
return exit(f(self.effect_instruction_i0))
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
})
|
|
2656
|
-
|
|
2657
|
-
/** @internal */
|
|
2658
|
-
export const exitFromEither = <R, L>(either: Either.Either<R, L>): Exit.Exit<R, L> => {
|
|
2659
|
-
switch (either._tag) {
|
|
2660
|
-
case "Left":
|
|
2661
|
-
return exitFail(either.left)
|
|
2662
|
-
case "Right":
|
|
2663
|
-
return exitSucceed(either.right)
|
|
2664
|
-
}
|
|
2665
|
-
}
|
|
2666
|
-
|
|
2667
|
-
/** @internal */
|
|
2668
|
-
export const exitFromOption = <A>(option: Option.Option<A>): Exit.Exit<A, void> => {
|
|
2669
|
-
switch (option._tag) {
|
|
2670
|
-
case "None":
|
|
2671
|
-
return exitFail(void 0)
|
|
2672
|
-
case "Some":
|
|
2673
|
-
return exitSucceed(option.value)
|
|
2674
|
-
}
|
|
2675
|
-
}
|
|
2676
|
-
|
|
2677
|
-
/** @internal */
|
|
2678
|
-
export const exitGetOrElse = dual<
|
|
2679
|
-
<E, A2>(orElse: (cause: Cause.Cause<E>) => A2) => <A>(self: Exit.Exit<A, E>) => A | A2,
|
|
2680
|
-
<A, E, A2>(self: Exit.Exit<A, E>, orElse: (cause: Cause.Cause<E>) => A2) => A | A2
|
|
2681
|
-
>(2, (self, orElse) => {
|
|
2682
|
-
switch (self._tag) {
|
|
2683
|
-
case OpCodes.OP_FAILURE:
|
|
2684
|
-
return orElse(self.effect_instruction_i0)
|
|
2685
|
-
case OpCodes.OP_SUCCESS:
|
|
2686
|
-
return self.effect_instruction_i0
|
|
2687
|
-
}
|
|
2688
|
-
})
|
|
2689
|
-
|
|
2690
|
-
/** @internal */
|
|
2691
|
-
export const exitInterrupt = (fiberId: FiberId.FiberId): Exit.Exit<never> =>
|
|
2692
|
-
exitFailCause(internalCause.interrupt(fiberId))
|
|
2693
|
-
|
|
2694
|
-
/** @internal */
|
|
2695
|
-
export const exitMap = dual<
|
|
2696
|
-
<A, B>(f: (a: A) => B) => <E>(self: Exit.Exit<A, E>) => Exit.Exit<B, E>,
|
|
2697
|
-
<A, E, B>(self: Exit.Exit<A, E>, f: (a: A) => B) => Exit.Exit<B, E>
|
|
2698
|
-
>(2, (self, f) => {
|
|
2699
|
-
switch (self._tag) {
|
|
2700
|
-
case OpCodes.OP_FAILURE:
|
|
2701
|
-
return exitFailCause(self.effect_instruction_i0)
|
|
2702
|
-
case OpCodes.OP_SUCCESS:
|
|
2703
|
-
return exitSucceed(f(self.effect_instruction_i0))
|
|
2704
|
-
}
|
|
2705
|
-
})
|
|
2706
|
-
|
|
2707
|
-
/** @internal */
|
|
2708
|
-
export const exitMapBoth = dual<
|
|
2709
|
-
<E, A, E2, A2>(
|
|
2710
|
-
options: {
|
|
2711
|
-
readonly onFailure: (e: E) => E2
|
|
2712
|
-
readonly onSuccess: (a: A) => A2
|
|
2713
|
-
}
|
|
2714
|
-
) => (self: Exit.Exit<A, E>) => Exit.Exit<A2, E2>,
|
|
2715
|
-
<A, E, E2, A2>(
|
|
2716
|
-
self: Exit.Exit<A, E>,
|
|
2717
|
-
options: {
|
|
2718
|
-
readonly onFailure: (e: E) => E2
|
|
2719
|
-
readonly onSuccess: (a: A) => A2
|
|
2720
|
-
}
|
|
2721
|
-
) => Exit.Exit<A2, E2>
|
|
2722
|
-
>(2, (self, { onFailure, onSuccess }) => {
|
|
2723
|
-
switch (self._tag) {
|
|
2724
|
-
case OpCodes.OP_FAILURE:
|
|
2725
|
-
return exitFailCause(pipe(self.effect_instruction_i0, internalCause.map(onFailure)))
|
|
2726
|
-
case OpCodes.OP_SUCCESS:
|
|
2727
|
-
return exitSucceed(onSuccess(self.effect_instruction_i0))
|
|
2728
|
-
}
|
|
2729
|
-
})
|
|
2730
|
-
|
|
2731
|
-
/** @internal */
|
|
2732
|
-
export const exitMapError = dual<
|
|
2733
|
-
<E, E2>(f: (e: E) => E2) => <A>(self: Exit.Exit<A, E>) => Exit.Exit<A, E2>,
|
|
2734
|
-
<A, E, E2>(self: Exit.Exit<A, E>, f: (e: E) => E2) => Exit.Exit<A, E2>
|
|
2735
|
-
>(2, (self, f) => {
|
|
2736
|
-
switch (self._tag) {
|
|
2737
|
-
case OpCodes.OP_FAILURE:
|
|
2738
|
-
return exitFailCause(pipe(self.effect_instruction_i0, internalCause.map(f)))
|
|
2739
|
-
case OpCodes.OP_SUCCESS:
|
|
2740
|
-
return exitSucceed(self.effect_instruction_i0)
|
|
2741
|
-
}
|
|
2742
|
-
})
|
|
2743
|
-
|
|
2744
|
-
/** @internal */
|
|
2745
|
-
export const exitMapErrorCause = dual<
|
|
2746
|
-
<E, E2>(f: (cause: Cause.Cause<E>) => Cause.Cause<E2>) => <A>(self: Exit.Exit<A, E>) => Exit.Exit<A, E2>,
|
|
2747
|
-
<E, A, E2>(self: Exit.Exit<A, E>, f: (cause: Cause.Cause<E>) => Cause.Cause<E2>) => Exit.Exit<A, E2>
|
|
2748
|
-
>(2, (self, f) => {
|
|
2749
|
-
switch (self._tag) {
|
|
2750
|
-
case OpCodes.OP_FAILURE:
|
|
2751
|
-
return exitFailCause(f(self.effect_instruction_i0))
|
|
2752
|
-
case OpCodes.OP_SUCCESS:
|
|
2753
|
-
return exitSucceed(self.effect_instruction_i0)
|
|
2754
|
-
}
|
|
2755
|
-
})
|
|
2756
|
-
|
|
2757
|
-
/** @internal */
|
|
2758
|
-
export const exitMatch = dual<
|
|
2759
|
-
<E, A, Z1, Z2>(options: {
|
|
2760
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Z1
|
|
2761
|
-
readonly onSuccess: (a: A) => Z2
|
|
2762
|
-
}) => (self: Exit.Exit<A, E>) => Z1 | Z2,
|
|
2763
|
-
<A, E, Z1, Z2>(self: Exit.Exit<A, E>, options: {
|
|
2764
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Z1
|
|
2765
|
-
readonly onSuccess: (a: A) => Z2
|
|
2766
|
-
}) => Z1 | Z2
|
|
2767
|
-
>(2, (self, { onFailure, onSuccess }) => {
|
|
2768
|
-
switch (self._tag) {
|
|
2769
|
-
case OpCodes.OP_FAILURE:
|
|
2770
|
-
return onFailure(self.effect_instruction_i0)
|
|
2771
|
-
case OpCodes.OP_SUCCESS:
|
|
2772
|
-
return onSuccess(self.effect_instruction_i0)
|
|
2773
|
-
}
|
|
2774
|
-
})
|
|
2775
|
-
|
|
2776
|
-
/** @internal */
|
|
2777
|
-
export const exitMatchEffect = dual<
|
|
2778
|
-
<E, A2, E2, R, A, A3, E3, R2>(
|
|
2779
|
-
options: {
|
|
2780
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>
|
|
2781
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>
|
|
2782
|
-
}
|
|
2783
|
-
) => (self: Exit.Exit<A, E>) => Effect.Effect<A2 | A3, E2 | E3, R | R2>,
|
|
2784
|
-
<A, E, A2, E2, R, A3, E3, R2>(
|
|
2785
|
-
self: Exit.Exit<A, E>,
|
|
2786
|
-
options: {
|
|
2787
|
-
readonly onFailure: (cause: Cause.Cause<E>) => Effect.Effect<A2, E2, R>
|
|
2788
|
-
readonly onSuccess: (a: A) => Effect.Effect<A3, E3, R2>
|
|
2789
|
-
}
|
|
2790
|
-
) => Effect.Effect<A2 | A3, E2 | E3, R | R2>
|
|
2791
|
-
>(2, (self, { onFailure, onSuccess }) => {
|
|
2792
|
-
switch (self._tag) {
|
|
2793
|
-
case OpCodes.OP_FAILURE:
|
|
2794
|
-
return onFailure(self.effect_instruction_i0)
|
|
2795
|
-
case OpCodes.OP_SUCCESS:
|
|
2796
|
-
return onSuccess(self.effect_instruction_i0)
|
|
2797
|
-
}
|
|
2798
|
-
})
|
|
2799
|
-
|
|
2800
|
-
/** @internal */
|
|
2801
|
-
export const exitSucceed = <A>(value: A): Exit.Exit<A> => {
|
|
2802
|
-
const effect = new EffectPrimitiveSuccess(OpCodes.OP_SUCCESS) as any
|
|
2803
|
-
effect.effect_instruction_i0 = value
|
|
2804
|
-
return effect
|
|
2805
|
-
}
|
|
2806
|
-
|
|
2807
|
-
/** @internal */
|
|
2808
|
-
export const exitVoid: Exit.Exit<void> = exitSucceed(void 0)
|
|
2809
|
-
|
|
2810
|
-
/** @internal */
|
|
2811
|
-
export const exitZip = dual<
|
|
2812
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<[A, A2], E | E2>,
|
|
2813
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<[A, A2], E | E2>
|
|
2814
|
-
>(2, (self, that) =>
|
|
2815
|
-
exitZipWith(self, that, {
|
|
2816
|
-
onSuccess: (a, a2) => [a, a2],
|
|
2817
|
-
onFailure: internalCause.sequential
|
|
2818
|
-
}))
|
|
2819
|
-
|
|
2820
|
-
/** @internal */
|
|
2821
|
-
export const exitZipLeft = dual<
|
|
2822
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A, E | E2>,
|
|
2823
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A, E | E2>
|
|
2824
|
-
>(2, (self, that) =>
|
|
2825
|
-
exitZipWith(self, that, {
|
|
2826
|
-
onSuccess: (a, _) => a,
|
|
2827
|
-
onFailure: internalCause.sequential
|
|
2828
|
-
}))
|
|
2829
|
-
|
|
2830
|
-
/** @internal */
|
|
2831
|
-
export const exitZipRight = dual<
|
|
2832
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,
|
|
2833
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>
|
|
2834
|
-
>(2, (self, that) =>
|
|
2835
|
-
exitZipWith(self, that, {
|
|
2836
|
-
onSuccess: (_, a2) => a2,
|
|
2837
|
-
onFailure: internalCause.sequential
|
|
2838
|
-
}))
|
|
2839
|
-
|
|
2840
|
-
/** @internal */
|
|
2841
|
-
export const exitZipPar = dual<
|
|
2842
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<[A, A2], E | E2>,
|
|
2843
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<[A, A2], E | E2>
|
|
2844
|
-
>(2, (self, that) =>
|
|
2845
|
-
exitZipWith(self, that, {
|
|
2846
|
-
onSuccess: (a, a2) => [a, a2],
|
|
2847
|
-
onFailure: internalCause.parallel
|
|
2848
|
-
}))
|
|
2849
|
-
|
|
2850
|
-
/** @internal */
|
|
2851
|
-
export const exitZipParLeft = dual<
|
|
2852
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A, E | E2>,
|
|
2853
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A, E | E2>
|
|
2854
|
-
>(2, (self, that) =>
|
|
2855
|
-
exitZipWith(self, that, {
|
|
2856
|
-
onSuccess: (a, _) => a,
|
|
2857
|
-
onFailure: internalCause.parallel
|
|
2858
|
-
}))
|
|
2859
|
-
|
|
2860
|
-
/** @internal */
|
|
2861
|
-
export const exitZipParRight = dual<
|
|
2862
|
-
<A2, E2>(that: Exit.Exit<A2, E2>) => <A, E>(self: Exit.Exit<A, E>) => Exit.Exit<A2, E | E2>,
|
|
2863
|
-
<A, E, A2, E2>(self: Exit.Exit<A, E>, that: Exit.Exit<A2, E2>) => Exit.Exit<A2, E | E2>
|
|
2864
|
-
>(2, (self, that) =>
|
|
2865
|
-
exitZipWith(self, that, {
|
|
2866
|
-
onSuccess: (_, a2) => a2,
|
|
2867
|
-
onFailure: internalCause.parallel
|
|
2868
|
-
}))
|
|
2869
|
-
|
|
2870
|
-
/** @internal */
|
|
2871
|
-
export const exitZipWith = dual<
|
|
2872
|
-
<B, E2, A, C, E>(
|
|
2873
|
-
that: Exit.Exit<B, E2>,
|
|
2874
|
-
options: {
|
|
2875
|
-
readonly onSuccess: (a: A, b: B) => C
|
|
2876
|
-
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>
|
|
2877
|
-
}
|
|
2878
|
-
) => (self: Exit.Exit<A, E>) => Exit.Exit<C, E | E2>,
|
|
2879
|
-
<A, E, B, E2, C>(
|
|
2880
|
-
self: Exit.Exit<A, E>,
|
|
2881
|
-
that: Exit.Exit<B, E2>,
|
|
2882
|
-
options: {
|
|
2883
|
-
readonly onSuccess: (a: A, b: B) => C
|
|
2884
|
-
readonly onFailure: (cause: Cause.Cause<E>, cause2: Cause.Cause<E2>) => Cause.Cause<E | E2>
|
|
2885
|
-
}
|
|
2886
|
-
) => Exit.Exit<C, E | E2>
|
|
2887
|
-
>(3, (
|
|
2888
|
-
self,
|
|
2889
|
-
that,
|
|
2890
|
-
{ onFailure, onSuccess }
|
|
2891
|
-
) => {
|
|
2892
|
-
switch (self._tag) {
|
|
2893
|
-
case OpCodes.OP_FAILURE: {
|
|
2894
|
-
switch (that._tag) {
|
|
2895
|
-
case OpCodes.OP_SUCCESS:
|
|
2896
|
-
return exitFailCause(self.effect_instruction_i0)
|
|
2897
|
-
case OpCodes.OP_FAILURE: {
|
|
2898
|
-
return exitFailCause(onFailure(self.effect_instruction_i0, that.effect_instruction_i0))
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
}
|
|
2902
|
-
case OpCodes.OP_SUCCESS: {
|
|
2903
|
-
switch (that._tag) {
|
|
2904
|
-
case OpCodes.OP_SUCCESS:
|
|
2905
|
-
return exitSucceed(onSuccess(self.effect_instruction_i0, that.effect_instruction_i0))
|
|
2906
|
-
case OpCodes.OP_FAILURE:
|
|
2907
|
-
return exitFailCause(that.effect_instruction_i0)
|
|
2908
|
-
}
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
|
-
})
|
|
2912
|
-
|
|
2913
|
-
const exitCollectAllInternal = <A, E>(
|
|
2914
|
-
exits: Iterable<Exit.Exit<A, E>>,
|
|
2915
|
-
combineCauses: (causeA: Cause.Cause<E>, causeB: Cause.Cause<E>) => Cause.Cause<E>
|
|
2916
|
-
): Option.Option<Exit.Exit<Array<A>, E>> => {
|
|
2917
|
-
const list = Chunk.fromIterable(exits)
|
|
2918
|
-
if (!Chunk.isNonEmpty(list)) {
|
|
2919
|
-
return Option.none()
|
|
2920
|
-
}
|
|
2921
|
-
return pipe(
|
|
2922
|
-
Chunk.tailNonEmpty(list),
|
|
2923
|
-
Arr.reduce(
|
|
2924
|
-
pipe(Chunk.headNonEmpty(list), exitMap<A, Chunk.Chunk<A>>(Chunk.of)),
|
|
2925
|
-
(accumulator, current) =>
|
|
2926
|
-
pipe(
|
|
2927
|
-
accumulator,
|
|
2928
|
-
exitZipWith(current, {
|
|
2929
|
-
onSuccess: (list, value) => pipe(list, Chunk.prepend(value)),
|
|
2930
|
-
onFailure: combineCauses
|
|
2931
|
-
})
|
|
2932
|
-
)
|
|
2933
|
-
),
|
|
2934
|
-
exitMap(Chunk.reverse),
|
|
2935
|
-
exitMap((chunk) => Chunk.toReadonlyArray(chunk) as Array<A>),
|
|
2936
|
-
Option.some
|
|
2937
|
-
)
|
|
2938
|
-
}
|
|
2939
|
-
|
|
2940
|
-
// -----------------------------------------------------------------------------
|
|
2941
|
-
// Deferred
|
|
2942
|
-
// -----------------------------------------------------------------------------
|
|
2943
|
-
|
|
2944
|
-
/** @internal */
|
|
2945
|
-
export const deferredUnsafeMake = <A, E = never>(fiberId: FiberId.FiberId): Deferred.Deferred<A, E> => {
|
|
2946
|
-
const _deferred = {
|
|
2947
|
-
...CommitPrototype,
|
|
2948
|
-
[deferred.DeferredTypeId]: deferred.deferredVariance,
|
|
2949
|
-
state: MutableRef.make(deferred.pending<A, E>([])),
|
|
2950
|
-
commit() {
|
|
2951
|
-
return deferredAwait(this)
|
|
2952
|
-
},
|
|
2953
|
-
blockingOn: fiberId
|
|
2954
|
-
}
|
|
2955
|
-
return _deferred
|
|
2956
|
-
}
|
|
2957
|
-
|
|
2958
|
-
/* @internal */
|
|
2959
|
-
export const deferredMake = <A, E = never>(): Effect.Effect<Deferred.Deferred<A, E>> =>
|
|
2960
|
-
flatMap(fiberId, (id) => deferredMakeAs<A, E>(id))
|
|
2961
|
-
|
|
2962
|
-
/* @internal */
|
|
2963
|
-
export const deferredMakeAs = <A, E = never>(fiberId: FiberId.FiberId): Effect.Effect<Deferred.Deferred<A, E>> =>
|
|
2964
|
-
sync(() => deferredUnsafeMake<A, E>(fiberId))
|
|
2965
|
-
|
|
2966
|
-
/* @internal */
|
|
2967
|
-
export const deferredAwait = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<A, E> =>
|
|
2968
|
-
asyncInterrupt<A, E>((resume) => {
|
|
2969
|
-
const state = MutableRef.get(self.state)
|
|
2970
|
-
switch (state._tag) {
|
|
2971
|
-
case DeferredOpCodes.OP_STATE_DONE: {
|
|
2972
|
-
return resume(state.effect)
|
|
2973
|
-
}
|
|
2974
|
-
case DeferredOpCodes.OP_STATE_PENDING: {
|
|
2975
|
-
// we can push here as the internal state is mutable
|
|
2976
|
-
state.joiners.push(resume)
|
|
2977
|
-
return deferredInterruptJoiner(self, resume)
|
|
2978
|
-
}
|
|
2979
|
-
}
|
|
2980
|
-
}, self.blockingOn)
|
|
2981
|
-
|
|
2982
|
-
/* @internal */
|
|
2983
|
-
export const deferredComplete: {
|
|
2984
|
-
<A, E>(effect: Effect.Effect<A, E>): (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>
|
|
2985
|
-
<A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean>
|
|
2986
|
-
} = dual(
|
|
2987
|
-
2,
|
|
2988
|
-
<A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): Effect.Effect<boolean> =>
|
|
2989
|
-
intoDeferred(effect, self)
|
|
2990
|
-
)
|
|
2991
|
-
|
|
2992
|
-
/* @internal */
|
|
2993
|
-
export const deferredCompleteWith = dual<
|
|
2994
|
-
<A, E>(effect: Effect.Effect<A, E>) => (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
2995
|
-
<A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>) => Effect.Effect<boolean>
|
|
2996
|
-
>(2, (self, effect) =>
|
|
2997
|
-
sync(() => {
|
|
2998
|
-
const state = MutableRef.get(self.state)
|
|
2999
|
-
switch (state._tag) {
|
|
3000
|
-
case DeferredOpCodes.OP_STATE_DONE: {
|
|
3001
|
-
return false
|
|
3002
|
-
}
|
|
3003
|
-
case DeferredOpCodes.OP_STATE_PENDING: {
|
|
3004
|
-
MutableRef.set(self.state, deferred.done(effect))
|
|
3005
|
-
for (let i = 0, len = state.joiners.length; i < len; i++) {
|
|
3006
|
-
state.joiners[i](effect)
|
|
3007
|
-
}
|
|
3008
|
-
return true
|
|
3009
|
-
}
|
|
3010
|
-
}
|
|
3011
|
-
}))
|
|
3012
|
-
|
|
3013
|
-
/* @internal */
|
|
3014
|
-
export const deferredDone = dual<
|
|
3015
|
-
<A, E>(exit: Exit.Exit<A, E>) => (self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3016
|
-
<A, E>(self: Deferred.Deferred<A, E>, exit: Exit.Exit<A, E>) => Effect.Effect<boolean>
|
|
3017
|
-
>(2, (self, exit) => deferredCompleteWith(self, exit))
|
|
3018
|
-
|
|
3019
|
-
/* @internal */
|
|
3020
|
-
export const deferredFail = dual<
|
|
3021
|
-
<E>(error: E) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3022
|
-
<A, E>(self: Deferred.Deferred<A, E>, error: E) => Effect.Effect<boolean>
|
|
3023
|
-
>(2, (self, error) => deferredCompleteWith(self, fail(error)))
|
|
3024
|
-
|
|
3025
|
-
/* @internal */
|
|
3026
|
-
export const deferredFailSync = dual<
|
|
3027
|
-
<E>(evaluate: LazyArg<E>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3028
|
-
<A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<E>) => Effect.Effect<boolean>
|
|
3029
|
-
>(2, (self, evaluate) => deferredCompleteWith(self, failSync(evaluate)))
|
|
3030
|
-
|
|
3031
|
-
/* @internal */
|
|
3032
|
-
export const deferredFailCause = dual<
|
|
3033
|
-
<E>(cause: Cause.Cause<E>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3034
|
-
<A, E>(self: Deferred.Deferred<A, E>, cause: Cause.Cause<E>) => Effect.Effect<boolean>
|
|
3035
|
-
>(2, (self, cause) => deferredCompleteWith(self, failCause(cause)))
|
|
3036
|
-
|
|
3037
|
-
/* @internal */
|
|
3038
|
-
export const deferredFailCauseSync = dual<
|
|
3039
|
-
<E>(evaluate: LazyArg<Cause.Cause<E>>) => <A>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3040
|
-
<A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<Cause.Cause<E>>) => Effect.Effect<boolean>
|
|
3041
|
-
>(2, (self, evaluate) => deferredCompleteWith(self, failCauseSync(evaluate)))
|
|
3042
|
-
|
|
3043
|
-
/* @internal */
|
|
3044
|
-
export const deferredDie = dual<
|
|
3045
|
-
(defect: unknown) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3046
|
-
<A, E>(self: Deferred.Deferred<A, E>, defect: unknown) => Effect.Effect<boolean>
|
|
3047
|
-
>(2, (self, defect) => deferredCompleteWith(self, die(defect)))
|
|
3048
|
-
|
|
3049
|
-
/* @internal */
|
|
3050
|
-
export const deferredDieSync = dual<
|
|
3051
|
-
(evaluate: LazyArg<unknown>) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3052
|
-
<A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<unknown>) => Effect.Effect<boolean>
|
|
3053
|
-
>(2, (self, evaluate) => deferredCompleteWith(self, dieSync(evaluate)))
|
|
3054
|
-
|
|
3055
|
-
/* @internal */
|
|
3056
|
-
export const deferredInterrupt = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<boolean> =>
|
|
3057
|
-
flatMap(fiberId, (fiberId) => deferredCompleteWith(self, interruptWith(fiberId)))
|
|
3058
|
-
|
|
3059
|
-
/* @internal */
|
|
3060
|
-
export const deferredInterruptWith = dual<
|
|
3061
|
-
(fiberId: FiberId.FiberId) => <A, E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3062
|
-
<A, E>(self: Deferred.Deferred<A, E>, fiberId: FiberId.FiberId) => Effect.Effect<boolean>
|
|
3063
|
-
>(2, (self, fiberId) => deferredCompleteWith(self, interruptWith(fiberId)))
|
|
3064
|
-
|
|
3065
|
-
/* @internal */
|
|
3066
|
-
export const deferredIsDone = <A, E>(self: Deferred.Deferred<A, E>): Effect.Effect<boolean> =>
|
|
3067
|
-
sync(() => MutableRef.get(self.state)._tag === DeferredOpCodes.OP_STATE_DONE)
|
|
3068
|
-
|
|
3069
|
-
/* @internal */
|
|
3070
|
-
export const deferredPoll = <A, E>(
|
|
3071
|
-
self: Deferred.Deferred<A, E>
|
|
3072
|
-
): Effect.Effect<Option.Option<Effect.Effect<A, E>>> =>
|
|
3073
|
-
sync(() => {
|
|
3074
|
-
const state = MutableRef.get(self.state)
|
|
3075
|
-
switch (state._tag) {
|
|
3076
|
-
case DeferredOpCodes.OP_STATE_DONE: {
|
|
3077
|
-
return Option.some(state.effect)
|
|
3078
|
-
}
|
|
3079
|
-
case DeferredOpCodes.OP_STATE_PENDING: {
|
|
3080
|
-
return Option.none()
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
})
|
|
3084
|
-
|
|
3085
|
-
/* @internal */
|
|
3086
|
-
export const deferredSucceed = dual<
|
|
3087
|
-
<A>(value: A) => <E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3088
|
-
<A, E>(self: Deferred.Deferred<A, E>, value: A) => Effect.Effect<boolean>
|
|
3089
|
-
>(2, (self, value) => deferredCompleteWith(self, succeed(value)))
|
|
3090
|
-
|
|
3091
|
-
/* @internal */
|
|
3092
|
-
export const deferredSync = dual<
|
|
3093
|
-
<A>(evaluate: LazyArg<A>) => <E>(self: Deferred.Deferred<A, E>) => Effect.Effect<boolean>,
|
|
3094
|
-
<A, E>(self: Deferred.Deferred<A, E>, evaluate: LazyArg<A>) => Effect.Effect<boolean>
|
|
3095
|
-
>(2, (self, evaluate) => deferredCompleteWith(self, sync(evaluate)))
|
|
3096
|
-
|
|
3097
|
-
/** @internal */
|
|
3098
|
-
export const deferredUnsafeDone = <A, E>(self: Deferred.Deferred<A, E>, effect: Effect.Effect<A, E>): void => {
|
|
3099
|
-
const state = MutableRef.get(self.state)
|
|
3100
|
-
if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {
|
|
3101
|
-
MutableRef.set(self.state, deferred.done(effect))
|
|
3102
|
-
for (let i = 0, len = state.joiners.length; i < len; i++) {
|
|
3103
|
-
state.joiners[i](effect)
|
|
3104
|
-
}
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
|
|
3108
|
-
const deferredInterruptJoiner = <A, E>(
|
|
3109
|
-
self: Deferred.Deferred<A, E>,
|
|
3110
|
-
joiner: (effect: Effect.Effect<A, E>) => void
|
|
3111
|
-
): Effect.Effect<void> =>
|
|
3112
|
-
sync(() => {
|
|
3113
|
-
const state = MutableRef.get(self.state)
|
|
3114
|
-
if (state._tag === DeferredOpCodes.OP_STATE_PENDING) {
|
|
3115
|
-
const index = state.joiners.indexOf(joiner)
|
|
3116
|
-
if (index >= 0) {
|
|
3117
|
-
// we can splice here as the internal state is mutable
|
|
3118
|
-
state.joiners.splice(index, 1)
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
})
|
|
3122
|
-
|
|
3123
|
-
// -----------------------------------------------------------------------------
|
|
3124
|
-
// Context
|
|
3125
|
-
// -----------------------------------------------------------------------------
|
|
3126
|
-
|
|
3127
|
-
const constContext = withFiberRuntime((fiber) => exitSucceed(fiber.currentContext))
|
|
3128
|
-
|
|
3129
|
-
/* @internal */
|
|
3130
|
-
export const context = <R>(): Effect.Effect<Context.Context<R>, never, R> => constContext as any
|
|
3131
|
-
|
|
3132
|
-
/* @internal */
|
|
3133
|
-
export const contextWith = <R0, A>(
|
|
3134
|
-
f: (context: Context.Context<R0>) => A
|
|
3135
|
-
): Effect.Effect<A, never, R0> => map(context<R0>(), f)
|
|
3136
|
-
|
|
3137
|
-
/* @internal */
|
|
3138
|
-
export const contextWithEffect = <R2, A, E, R>(
|
|
3139
|
-
f: (context: Context.Context<R2>) => Effect.Effect<A, E, R>
|
|
3140
|
-
): Effect.Effect<A, E, R | R2> => flatMap(context<R2>(), f)
|
|
3141
|
-
|
|
3142
|
-
/* @internal */
|
|
3143
|
-
export const provideContext = dual<
|
|
3144
|
-
<R>(context: Context.Context<R>) => <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E>,
|
|
3145
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, context: Context.Context<R>) => Effect.Effect<A, E>
|
|
3146
|
-
>(2, <A, E, R>(self: Effect.Effect<A, E, R>, context: Context.Context<R>) =>
|
|
3147
|
-
fiberRefLocally(
|
|
3148
|
-
currentContext,
|
|
3149
|
-
context
|
|
3150
|
-
)(self as Effect.Effect<A, E>))
|
|
3151
|
-
|
|
3152
|
-
/* @internal */
|
|
3153
|
-
export const provideSomeContext = dual<
|
|
3154
|
-
<R>(context: Context.Context<R>) => <A, E, R1>(self: Effect.Effect<A, E, R1>) => Effect.Effect<A, E, Exclude<R1, R>>,
|
|
3155
|
-
<A, E, R1, R>(self: Effect.Effect<A, E, R1>, context: Context.Context<R>) => Effect.Effect<A, E, Exclude<R1, R>>
|
|
3156
|
-
>(2, <A, E, R1, R>(self: Effect.Effect<A, E, R1>, context: Context.Context<R>) =>
|
|
3157
|
-
fiberRefLocallyWith(
|
|
3158
|
-
currentContext,
|
|
3159
|
-
(parent) => Context.merge(parent, context)
|
|
3160
|
-
)(self as Effect.Effect<A, E>))
|
|
3161
|
-
|
|
3162
|
-
/* @internal */
|
|
3163
|
-
export const mapInputContext = dual<
|
|
3164
|
-
<R2, R>(
|
|
3165
|
-
f: (context: Context.Context<R2>) => Context.Context<R>
|
|
3166
|
-
) => <A, E>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R2>,
|
|
3167
|
-
<A, E, R, R2>(
|
|
3168
|
-
self: Effect.Effect<A, E, R>,
|
|
3169
|
-
f: (context: Context.Context<R2>) => Context.Context<R>
|
|
3170
|
-
) => Effect.Effect<A, E, R2>
|
|
3171
|
-
>(2, <A, E, R, R2>(
|
|
3172
|
-
self: Effect.Effect<A, E, R>,
|
|
3173
|
-
f: (context: Context.Context<R2>) => Context.Context<R>
|
|
3174
|
-
) => contextWithEffect((context: Context.Context<R2>) => provideContext(self, f(context))))
|
|
3175
|
-
|
|
3176
|
-
// -----------------------------------------------------------------------------
|
|
3177
|
-
// Filtering
|
|
3178
|
-
// -----------------------------------------------------------------------------
|
|
3179
|
-
|
|
3180
|
-
/** @internal */
|
|
3181
|
-
export const filterEffectOrElse: {
|
|
3182
|
-
<A, E2, R2, A2, E3, R3>(
|
|
3183
|
-
options: {
|
|
3184
|
-
readonly predicate: (a: NoInfer<A>) => Effect.Effect<boolean, E2, R2>
|
|
3185
|
-
readonly orElse: (a: NoInfer<A>) => Effect.Effect<A2, E3, R3>
|
|
3186
|
-
}
|
|
3187
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2 | E3, R | R2 | R3>
|
|
3188
|
-
<A, E, R, E2, R2, A2, E3, R3>(
|
|
3189
|
-
self: Effect.Effect<A, E, R>,
|
|
3190
|
-
options: {
|
|
3191
|
-
readonly predicate: (a: A) => Effect.Effect<boolean, E2, R2>
|
|
3192
|
-
readonly orElse: (a: A) => Effect.Effect<A2, E3, R3>
|
|
3193
|
-
}
|
|
3194
|
-
): Effect.Effect<A | A2, E | E2 | E3, R | R2 | R3>
|
|
3195
|
-
} = dual(2, <A, E, R, E2, R2, A2, E3, R3>(
|
|
3196
|
-
self: Effect.Effect<A, E, R>,
|
|
3197
|
-
options: {
|
|
3198
|
-
readonly predicate: (a: A) => Effect.Effect<boolean, E2, R2>
|
|
3199
|
-
readonly orElse: (a: A) => Effect.Effect<A2, E3, R3>
|
|
3200
|
-
}
|
|
3201
|
-
): Effect.Effect<A | A2, E | E2 | E3, R | R2 | R3> =>
|
|
3202
|
-
flatMap(
|
|
3203
|
-
self,
|
|
3204
|
-
(a) =>
|
|
3205
|
-
flatMap(
|
|
3206
|
-
options.predicate(a),
|
|
3207
|
-
(pass): Effect.Effect<A | A2, E3, R3> => pass ? succeed(a) : options.orElse(a)
|
|
3208
|
-
)
|
|
3209
|
-
))
|
|
3210
|
-
|
|
3211
|
-
/** @internal */
|
|
3212
|
-
export const filterEffectOrFail: {
|
|
3213
|
-
<A, E2, R2, E3>(
|
|
3214
|
-
options: {
|
|
3215
|
-
readonly predicate: (a: NoInfer<A>) => Effect.Effect<boolean, E2, R2>
|
|
3216
|
-
readonly orFailWith: (a: NoInfer<A>) => E3
|
|
3217
|
-
}
|
|
3218
|
-
): <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E2 | E3, R | R2>
|
|
3219
|
-
<A, E, R, E2, R2, E3>(
|
|
3220
|
-
self: Effect.Effect<A, E, R>,
|
|
3221
|
-
options: {
|
|
3222
|
-
readonly predicate: (a: A) => Effect.Effect<boolean, E2, R2>
|
|
3223
|
-
readonly orFailWith: (a: A) => E3
|
|
3224
|
-
}
|
|
3225
|
-
): Effect.Effect<A, E | E2 | E3, R | R2>
|
|
3226
|
-
} = dual(2, <A, E, R, E2, R2, E3>(
|
|
3227
|
-
self: Effect.Effect<A, E, R>,
|
|
3228
|
-
options: {
|
|
3229
|
-
readonly predicate: (a: A) => Effect.Effect<boolean, E2, R2>
|
|
3230
|
-
readonly orFailWith: (a: A) => E3
|
|
3231
|
-
}
|
|
3232
|
-
): Effect.Effect<A, E | E2 | E3, R | R2> =>
|
|
3233
|
-
filterEffectOrElse(self, {
|
|
3234
|
-
predicate: options.predicate,
|
|
3235
|
-
orElse: (a) => fail(options.orFailWith(a))
|
|
3236
|
-
}))
|
|
3237
|
-
|
|
3238
|
-
// -----------------------------------------------------------------------------
|
|
3239
|
-
// Tracing
|
|
3240
|
-
// -----------------------------------------------------------------------------
|
|
3241
|
-
|
|
3242
|
-
/** @internal */
|
|
3243
|
-
export const currentSpanFromFiber = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Option.Option<Tracer.Span> => {
|
|
3244
|
-
const span = fiber.currentSpan
|
|
3245
|
-
return span !== undefined && span._tag === "Span" ? Option.some(span) : Option.none()
|
|
3246
|
-
}
|
|
3247
|
-
|
|
3248
|
-
const NoopSpanProto: Omit<Tracer.Span, "parent" | "name" | "context"> = {
|
|
3249
|
-
_tag: "Span",
|
|
3250
|
-
spanId: "noop",
|
|
3251
|
-
traceId: "noop",
|
|
3252
|
-
sampled: false,
|
|
3253
|
-
status: {
|
|
3254
|
-
_tag: "Ended",
|
|
3255
|
-
startTime: BigInt(0),
|
|
3256
|
-
endTime: BigInt(0),
|
|
3257
|
-
exit: exitVoid
|
|
3258
|
-
},
|
|
3259
|
-
attributes: new Map(),
|
|
3260
|
-
links: [],
|
|
3261
|
-
kind: "internal",
|
|
3262
|
-
attribute() {},
|
|
3263
|
-
event() {},
|
|
3264
|
-
end() {},
|
|
3265
|
-
addLinks() {}
|
|
3266
|
-
}
|
|
3267
|
-
|
|
3268
|
-
/** @internal */
|
|
3269
|
-
export const noopSpan = (options: {
|
|
3270
|
-
readonly name: string
|
|
3271
|
-
readonly parent: Option.Option<Tracer.AnySpan>
|
|
3272
|
-
readonly context: Context.Context<never>
|
|
3273
|
-
}): Tracer.Span => Object.assign(Object.create(NoopSpanProto), options)
|