@clayroach/effect 3.19.14-source-capture.7 → 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
|
@@ -1,905 +0,0 @@
|
|
|
1
|
-
import type * as Cause from "../../Cause.js"
|
|
2
|
-
import type * as Deferred from "../../Deferred.js"
|
|
3
|
-
import * as Duration from "../../Duration.js"
|
|
4
|
-
import type * as Effect from "../../Effect.js"
|
|
5
|
-
import * as Effectable from "../../Effectable.js"
|
|
6
|
-
import * as Equal from "../../Equal.js"
|
|
7
|
-
import type { Equivalence } from "../../Equivalence.js"
|
|
8
|
-
import * as Exit from "../../Exit.js"
|
|
9
|
-
import type * as Fiber from "../../Fiber.js"
|
|
10
|
-
import * as FiberId from "../../FiberId.js"
|
|
11
|
-
import type * as FiberRefsPatch from "../../FiberRefsPatch.js"
|
|
12
|
-
import type { LazyArg } from "../../Function.js"
|
|
13
|
-
import { dual, pipe } from "../../Function.js"
|
|
14
|
-
import * as Hash from "../../Hash.js"
|
|
15
|
-
import * as MutableHashMap from "../../MutableHashMap.js"
|
|
16
|
-
import * as Option from "../../Option.js"
|
|
17
|
-
import { pipeArguments } from "../../Pipeable.js"
|
|
18
|
-
import * as Predicate from "../../Predicate.js"
|
|
19
|
-
import * as Readable from "../../Readable.js"
|
|
20
|
-
import type * as Ref from "../../Ref.js"
|
|
21
|
-
import { currentScheduler } from "../../Scheduler.js"
|
|
22
|
-
import type * as Scope from "../../Scope.js"
|
|
23
|
-
import type * as Supervisor from "../../Supervisor.js"
|
|
24
|
-
import type * as Synchronized from "../../SynchronizedRef.js"
|
|
25
|
-
import type * as Types from "../../Types.js"
|
|
26
|
-
import * as internalCause from "../cause.js"
|
|
27
|
-
import * as effect from "../core-effect.js"
|
|
28
|
-
import * as core from "../core.js"
|
|
29
|
-
import * as internalFiber from "../fiber.js"
|
|
30
|
-
import * as fiberRuntime from "../fiberRuntime.js"
|
|
31
|
-
import { globalScope } from "../fiberScope.js"
|
|
32
|
-
import * as internalRef from "../ref.js"
|
|
33
|
-
import * as supervisor from "../supervisor.js"
|
|
34
|
-
|
|
35
|
-
/** @internal */
|
|
36
|
-
class Semaphore {
|
|
37
|
-
public waiters = new Set<() => void>()
|
|
38
|
-
public taken = 0
|
|
39
|
-
|
|
40
|
-
constructor(public permits: number) {}
|
|
41
|
-
|
|
42
|
-
get free() {
|
|
43
|
-
return this.permits - this.taken
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
readonly take = (n: number): Effect.Effect<number> =>
|
|
47
|
-
core.asyncInterrupt<number>((resume) => {
|
|
48
|
-
if (this.free < n) {
|
|
49
|
-
const observer = () => {
|
|
50
|
-
if (this.free < n) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
this.waiters.delete(observer)
|
|
54
|
-
this.taken += n
|
|
55
|
-
resume(core.succeed(n))
|
|
56
|
-
}
|
|
57
|
-
this.waiters.add(observer)
|
|
58
|
-
return core.sync(() => {
|
|
59
|
-
this.waiters.delete(observer)
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
this.taken += n
|
|
63
|
-
return resume(core.succeed(n))
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
updateTakenUnsafe(fiber: Fiber.RuntimeFiber<any, any>, f: (n: number) => number): Effect.Effect<number> {
|
|
67
|
-
this.taken = f(this.taken)
|
|
68
|
-
if (this.waiters.size > 0) {
|
|
69
|
-
fiber.getFiberRef(currentScheduler).scheduleTask(() => {
|
|
70
|
-
const iter = this.waiters.values()
|
|
71
|
-
let item = iter.next()
|
|
72
|
-
while (item.done === false && this.free > 0) {
|
|
73
|
-
item.value()
|
|
74
|
-
item = iter.next()
|
|
75
|
-
}
|
|
76
|
-
}, fiber.getFiberRef(core.currentSchedulingPriority))
|
|
77
|
-
}
|
|
78
|
-
return core.succeed(this.free)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
updateTaken(f: (n: number) => number): Effect.Effect<number> {
|
|
82
|
-
return core.withFiberRuntime((fiber) => this.updateTakenUnsafe(fiber, f))
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
readonly resize = (permits: number) =>
|
|
86
|
-
core.asVoid(
|
|
87
|
-
core.withFiberRuntime((fiber) => {
|
|
88
|
-
this.permits = permits
|
|
89
|
-
if (this.free < 0) {
|
|
90
|
-
return core.void
|
|
91
|
-
}
|
|
92
|
-
return this.updateTakenUnsafe(fiber, (taken) => taken)
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
readonly release = (n: number): Effect.Effect<number> => this.updateTaken((taken) => taken - n)
|
|
97
|
-
|
|
98
|
-
readonly releaseAll: Effect.Effect<number> = this.updateTaken((_) => 0)
|
|
99
|
-
|
|
100
|
-
readonly withPermits = (n: number) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
101
|
-
core.uninterruptibleMask((restore) =>
|
|
102
|
-
core.flatMap(
|
|
103
|
-
restore(this.take(n)),
|
|
104
|
-
(permits) => fiberRuntime.ensuring(restore(self), this.release(permits))
|
|
105
|
-
)
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
readonly withPermitsIfAvailable = (n: number) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
|
109
|
-
core.uninterruptibleMask((restore) =>
|
|
110
|
-
core.suspend(() => {
|
|
111
|
-
if (this.free < n) {
|
|
112
|
-
return effect.succeedNone
|
|
113
|
-
}
|
|
114
|
-
this.taken += n
|
|
115
|
-
return fiberRuntime.ensuring(restore(effect.asSome(self)), this.release(n))
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @internal */
|
|
121
|
-
export const unsafeMakeSemaphore = (permits: number): Effect.Semaphore => new Semaphore(permits)
|
|
122
|
-
|
|
123
|
-
/** @internal */
|
|
124
|
-
export const makeSemaphore = (permits: number) => core.sync(() => unsafeMakeSemaphore(permits))
|
|
125
|
-
|
|
126
|
-
class Latch extends Effectable.Class<void> implements Effect.Latch {
|
|
127
|
-
waiters: Array<(_: Effect.Effect<void>) => void> = []
|
|
128
|
-
scheduled = false
|
|
129
|
-
constructor(private isOpen: boolean) {
|
|
130
|
-
super()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
commit() {
|
|
134
|
-
return this.await
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private unsafeSchedule(fiber: Fiber.RuntimeFiber<void>) {
|
|
138
|
-
if (this.scheduled || this.waiters.length === 0) {
|
|
139
|
-
return core.void
|
|
140
|
-
}
|
|
141
|
-
this.scheduled = true
|
|
142
|
-
fiber.currentScheduler.scheduleTask(this.flushWaiters, fiber.getFiberRef(core.currentSchedulingPriority))
|
|
143
|
-
return core.void
|
|
144
|
-
}
|
|
145
|
-
private flushWaiters = () => {
|
|
146
|
-
this.scheduled = false
|
|
147
|
-
const waiters = this.waiters
|
|
148
|
-
this.waiters = []
|
|
149
|
-
for (let i = 0; i < waiters.length; i++) {
|
|
150
|
-
waiters[i](core.exitVoid)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
open = core.withFiberRuntime<void>((fiber) => {
|
|
155
|
-
if (this.isOpen) {
|
|
156
|
-
return core.void
|
|
157
|
-
}
|
|
158
|
-
this.isOpen = true
|
|
159
|
-
return this.unsafeSchedule(fiber)
|
|
160
|
-
})
|
|
161
|
-
unsafeOpen() {
|
|
162
|
-
if (this.isOpen) return
|
|
163
|
-
this.isOpen = true
|
|
164
|
-
this.flushWaiters()
|
|
165
|
-
}
|
|
166
|
-
release = core.withFiberRuntime<void>((fiber) => {
|
|
167
|
-
if (this.isOpen) {
|
|
168
|
-
return core.void
|
|
169
|
-
}
|
|
170
|
-
return this.unsafeSchedule(fiber)
|
|
171
|
-
})
|
|
172
|
-
await = core.asyncInterrupt<void>((resume) => {
|
|
173
|
-
if (this.isOpen) {
|
|
174
|
-
return resume(core.void)
|
|
175
|
-
}
|
|
176
|
-
this.waiters.push(resume)
|
|
177
|
-
return core.sync(() => {
|
|
178
|
-
const index = this.waiters.indexOf(resume)
|
|
179
|
-
if (index !== -1) {
|
|
180
|
-
this.waiters.splice(index, 1)
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
unsafeClose() {
|
|
185
|
-
this.isOpen = false
|
|
186
|
-
}
|
|
187
|
-
close = core.sync(() => {
|
|
188
|
-
this.isOpen = false
|
|
189
|
-
})
|
|
190
|
-
whenOpen = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> => {
|
|
191
|
-
return core.zipRight(this.await, self)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** @internal */
|
|
196
|
-
export const unsafeMakeLatch = (open?: boolean | undefined): Effect.Latch => new Latch(open ?? false)
|
|
197
|
-
|
|
198
|
-
/** @internal */
|
|
199
|
-
export const makeLatch = (open?: boolean | undefined) => core.sync(() => unsafeMakeLatch(open))
|
|
200
|
-
|
|
201
|
-
/** @internal */
|
|
202
|
-
export const awaitAllChildren = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
|
|
203
|
-
ensuringChildren(self, fiberRuntime.fiberAwaitAll)
|
|
204
|
-
|
|
205
|
-
/** @internal */
|
|
206
|
-
export const cached: {
|
|
207
|
-
(
|
|
208
|
-
timeToLive: Duration.DurationInput
|
|
209
|
-
): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Effect.Effect<A, E>, never, R>
|
|
210
|
-
<A, E, R>(
|
|
211
|
-
self: Effect.Effect<A, E, R>,
|
|
212
|
-
timeToLive: Duration.DurationInput
|
|
213
|
-
): Effect.Effect<Effect.Effect<A, E>, never, R>
|
|
214
|
-
} = dual(
|
|
215
|
-
2,
|
|
216
|
-
<A, E, R>(
|
|
217
|
-
self: Effect.Effect<A, E, R>,
|
|
218
|
-
timeToLive: Duration.DurationInput
|
|
219
|
-
): Effect.Effect<Effect.Effect<A, E>, never, R> =>
|
|
220
|
-
core.map(cachedInvalidateWithTTL(self, timeToLive), (tuple) => tuple[0])
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
/** @internal */
|
|
224
|
-
export const cachedInvalidateWithTTL: {
|
|
225
|
-
(timeToLive: Duration.DurationInput): <A, E, R>(
|
|
226
|
-
self: Effect.Effect<A, E, R>
|
|
227
|
-
) => Effect.Effect<[Effect.Effect<A, E>, Effect.Effect<void>], never, R>
|
|
228
|
-
<A, E, R>(
|
|
229
|
-
self: Effect.Effect<A, E, R>,
|
|
230
|
-
timeToLive: Duration.DurationInput
|
|
231
|
-
): Effect.Effect<[Effect.Effect<A, E>, Effect.Effect<void>], never, R>
|
|
232
|
-
} = dual(
|
|
233
|
-
2,
|
|
234
|
-
<A, E, R>(
|
|
235
|
-
self: Effect.Effect<A, E, R>,
|
|
236
|
-
timeToLive: Duration.DurationInput
|
|
237
|
-
): Effect.Effect<[Effect.Effect<A, E>, Effect.Effect<void>], never, R> => {
|
|
238
|
-
const duration = Duration.decode(timeToLive)
|
|
239
|
-
return core.flatMap(
|
|
240
|
-
core.context<R>(),
|
|
241
|
-
(env) =>
|
|
242
|
-
core.map(
|
|
243
|
-
makeSynchronized<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>(Option.none()),
|
|
244
|
-
(cache) =>
|
|
245
|
-
[
|
|
246
|
-
core.provideContext(getCachedValue(self, duration, cache), env),
|
|
247
|
-
invalidateCache(cache)
|
|
248
|
-
] as [Effect.Effect<A, E>, Effect.Effect<void>]
|
|
249
|
-
)
|
|
250
|
-
)
|
|
251
|
-
}
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
/** @internal */
|
|
255
|
-
const computeCachedValue = <A, E, R>(
|
|
256
|
-
self: Effect.Effect<A, E, R>,
|
|
257
|
-
timeToLive: Duration.DurationInput,
|
|
258
|
-
start: number
|
|
259
|
-
): Effect.Effect<Option.Option<[number, Deferred.Deferred<A, E>]>, never, R> => {
|
|
260
|
-
const timeToLiveMillis = Duration.toMillis(Duration.decode(timeToLive))
|
|
261
|
-
return pipe(
|
|
262
|
-
core.deferredMake<A, E>(),
|
|
263
|
-
core.tap((deferred) => core.intoDeferred(self, deferred)),
|
|
264
|
-
core.map((deferred) => Option.some([start + timeToLiveMillis, deferred]))
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** @internal */
|
|
269
|
-
const getCachedValue = <A, E, R>(
|
|
270
|
-
self: Effect.Effect<A, E, R>,
|
|
271
|
-
timeToLive: Duration.DurationInput,
|
|
272
|
-
cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
|
|
273
|
-
): Effect.Effect<A, E, R> =>
|
|
274
|
-
core.uninterruptibleMask((restore) =>
|
|
275
|
-
pipe(
|
|
276
|
-
effect.clockWith((clock) => clock.currentTimeMillis),
|
|
277
|
-
core.flatMap((time) =>
|
|
278
|
-
updateSomeAndGetEffectSynchronized(cache, (option) => {
|
|
279
|
-
switch (option._tag) {
|
|
280
|
-
case "None": {
|
|
281
|
-
return Option.some(computeCachedValue(self, timeToLive, time))
|
|
282
|
-
}
|
|
283
|
-
case "Some": {
|
|
284
|
-
const [end] = option.value
|
|
285
|
-
return end - time <= 0
|
|
286
|
-
? Option.some(computeCachedValue(self, timeToLive, time))
|
|
287
|
-
: Option.none()
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
})
|
|
291
|
-
),
|
|
292
|
-
core.flatMap((option) =>
|
|
293
|
-
Option.isNone(option) ?
|
|
294
|
-
core.dieMessage(
|
|
295
|
-
"BUG: Effect.cachedInvalidate - please report an issue at https://github.com/Effect-TS/effect/issues"
|
|
296
|
-
) :
|
|
297
|
-
restore(core.deferredAwait(option.value[1]))
|
|
298
|
-
)
|
|
299
|
-
)
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
/** @internal */
|
|
303
|
-
const invalidateCache = <A, E>(
|
|
304
|
-
cache: Synchronized.SynchronizedRef<Option.Option<readonly [number, Deferred.Deferred<A, E>]>>
|
|
305
|
-
): Effect.Effect<void> => internalRef.set(cache, Option.none())
|
|
306
|
-
|
|
307
|
-
/** @internal */
|
|
308
|
-
export const ensuringChild = dual<
|
|
309
|
-
<X, R2>(
|
|
310
|
-
f: (fiber: Fiber.Fiber<ReadonlyArray<unknown>, any>) => Effect.Effect<X, never, R2>
|
|
311
|
-
) => <A, E, R>(
|
|
312
|
-
self: Effect.Effect<A, E, R>
|
|
313
|
-
) => Effect.Effect<A, E, R | R2>,
|
|
314
|
-
<A, E, R, X, R2>(
|
|
315
|
-
self: Effect.Effect<A, E, R>,
|
|
316
|
-
f: (fiber: Fiber.Fiber<ReadonlyArray<unknown>, any>) => Effect.Effect<X, never, R2>
|
|
317
|
-
) => Effect.Effect<A, E, R | R2>
|
|
318
|
-
>(2, (self, f) => ensuringChildren(self, (children) => f(fiberRuntime.fiberAll(children))))
|
|
319
|
-
|
|
320
|
-
/** @internal */
|
|
321
|
-
export const ensuringChildren = dual<
|
|
322
|
-
<X, R2>(
|
|
323
|
-
children: (fibers: ReadonlyArray<Fiber.RuntimeFiber<any, any>>) => Effect.Effect<X, never, R2>
|
|
324
|
-
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R | R2>,
|
|
325
|
-
<A, E, R, X, R2>(
|
|
326
|
-
self: Effect.Effect<A, E, R>,
|
|
327
|
-
children: (fibers: ReadonlyArray<Fiber.RuntimeFiber<any, any>>) => Effect.Effect<X, never, R2>
|
|
328
|
-
) => Effect.Effect<A, E, R | R2>
|
|
329
|
-
>(2, (self, children) =>
|
|
330
|
-
core.flatMap(supervisor.track, (supervisor) =>
|
|
331
|
-
pipe(
|
|
332
|
-
supervised(self, supervisor),
|
|
333
|
-
fiberRuntime.ensuring(core.flatMap(supervisor.value, children))
|
|
334
|
-
)))
|
|
335
|
-
|
|
336
|
-
/** @internal */
|
|
337
|
-
export const forkAll: {
|
|
338
|
-
(
|
|
339
|
-
options?: {
|
|
340
|
-
readonly discard?: false | undefined
|
|
341
|
-
}
|
|
342
|
-
): <Eff extends Effect.Effect<any, any, any>>(
|
|
343
|
-
effects: Iterable<Eff>
|
|
344
|
-
) => Effect.Effect<
|
|
345
|
-
Fiber.Fiber<Array<Effect.Effect.Success<Eff>>, Effect.Effect.Error<Eff>>,
|
|
346
|
-
never,
|
|
347
|
-
Effect.Effect.Context<Eff>
|
|
348
|
-
>
|
|
349
|
-
(options: {
|
|
350
|
-
readonly discard: true
|
|
351
|
-
}): <Eff extends Effect.Effect<any, any, any>>(
|
|
352
|
-
effects: Iterable<Eff>
|
|
353
|
-
) => Effect.Effect<void, never, Effect.Effect.Context<Eff>>
|
|
354
|
-
<Eff extends Effect.Effect<any, any, any>>(
|
|
355
|
-
effects: Iterable<Eff>,
|
|
356
|
-
options?: {
|
|
357
|
-
readonly discard?: false | undefined
|
|
358
|
-
}
|
|
359
|
-
): Effect.Effect<
|
|
360
|
-
Fiber.Fiber<Array<Effect.Effect.Success<Eff>>, Effect.Effect.Error<Eff>>,
|
|
361
|
-
never,
|
|
362
|
-
Effect.Effect.Context<Eff>
|
|
363
|
-
>
|
|
364
|
-
<Eff extends Effect.Effect<any, any, any>>(effects: Iterable<Eff>, options: {
|
|
365
|
-
readonly discard: true
|
|
366
|
-
}): Effect.Effect<void, never, Effect.Effect.Context<Eff>>
|
|
367
|
-
} = dual((args) => Predicate.isIterable(args[0]), <A, E, R>(effects: Iterable<Effect.Effect<A, E, R>>, options: {
|
|
368
|
-
readonly discard: true
|
|
369
|
-
}): Effect.Effect<void, never, R> => {
|
|
370
|
-
const rawStack = new Error().stack ?? ""
|
|
371
|
-
const effectsArray = Array.from(effects)
|
|
372
|
-
const count = effectsArray.length
|
|
373
|
-
const result: Effect.Effect<void | Fiber.Fiber<Array<A>, E>, never, R> = options?.discard ?
|
|
374
|
-
core.forEachSequentialDiscard(effectsArray, fiberRuntime.fork) :
|
|
375
|
-
core.map(core.forEachSequential(effectsArray, fiberRuntime.fork), fiberRuntime.fiberAll)
|
|
376
|
-
;(result as any).trace = core.makeOperationMeta("forkAll", rawStack, count)
|
|
377
|
-
return result
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
/** @internal */
|
|
381
|
-
export const forkIn = dual<
|
|
382
|
-
(scope: Scope.Scope) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>,
|
|
383
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, scope: Scope.Scope) => Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R>
|
|
384
|
-
>(
|
|
385
|
-
2,
|
|
386
|
-
<A, E, R>(self: Effect.Effect<A, E, R>, scope: Scope.Scope): Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R> => {
|
|
387
|
-
const rawStack = new Error().stack ?? ""
|
|
388
|
-
const result: Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R> = core.withFiberRuntime((parent, parentStatus) => {
|
|
389
|
-
const scopeImpl = scope as fiberRuntime.ScopeImpl
|
|
390
|
-
const fiber = fiberRuntime.unsafeFork(self, parent, parentStatus.runtimeFlags, globalScope)
|
|
391
|
-
if (scopeImpl.state._tag === "Open") {
|
|
392
|
-
const finalizer = () =>
|
|
393
|
-
core.fiberIdWith((fiberId) =>
|
|
394
|
-
Equal.equals(fiberId, fiber.id()) ?
|
|
395
|
-
core.void :
|
|
396
|
-
core.asVoid(core.interruptFiber(fiber))
|
|
397
|
-
)
|
|
398
|
-
const key = {}
|
|
399
|
-
scopeImpl.state.finalizers.set(key, finalizer)
|
|
400
|
-
fiber.addObserver(() => {
|
|
401
|
-
if (scopeImpl.state._tag === "Closed") return
|
|
402
|
-
scopeImpl.state.finalizers.delete(key)
|
|
403
|
-
})
|
|
404
|
-
} else {
|
|
405
|
-
fiber.unsafeInterruptAsFork(parent.id())
|
|
406
|
-
}
|
|
407
|
-
return core.succeed(fiber)
|
|
408
|
-
})
|
|
409
|
-
;(result as any).trace = core.makeOperationMeta("forkIn", rawStack, 1)
|
|
410
|
-
return result
|
|
411
|
-
}
|
|
412
|
-
)
|
|
413
|
-
|
|
414
|
-
/** @internal */
|
|
415
|
-
export const forkScoped = <A, E, R>(
|
|
416
|
-
self: Effect.Effect<A, E, R>
|
|
417
|
-
): Effect.Effect<Fiber.RuntimeFiber<A, E>, never, R | Scope.Scope> =>
|
|
418
|
-
fiberRuntime.scopeWith((scope) => forkIn(self, scope))
|
|
419
|
-
|
|
420
|
-
/** @internal */
|
|
421
|
-
export const fromFiber = <A, E>(fiber: Fiber.Fiber<A, E>): Effect.Effect<A, E> => internalFiber.join(fiber)
|
|
422
|
-
|
|
423
|
-
/** @internal */
|
|
424
|
-
export const fromFiberEffect = <A, E, R>(fiber: Effect.Effect<Fiber.Fiber<A, E>, E, R>): Effect.Effect<A, E, R> =>
|
|
425
|
-
core.suspend(() => core.flatMap(fiber, internalFiber.join))
|
|
426
|
-
|
|
427
|
-
const memoKeySymbol = Symbol.for("effect/Effect/memoizeFunction.key")
|
|
428
|
-
|
|
429
|
-
class Key<in out A> implements Equal.Equal {
|
|
430
|
-
[memoKeySymbol] = memoKeySymbol
|
|
431
|
-
constructor(readonly a: A, readonly eq?: Equivalence<A>) {}
|
|
432
|
-
[Equal.symbol](that: Equal.Equal) {
|
|
433
|
-
if (Predicate.hasProperty(that, memoKeySymbol)) {
|
|
434
|
-
if (this.eq) {
|
|
435
|
-
return this.eq(this.a, (that as unknown as Key<A>).a)
|
|
436
|
-
} else {
|
|
437
|
-
return Equal.equals(this.a, (that as unknown as Key<A>).a)
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return false
|
|
441
|
-
}
|
|
442
|
-
[Hash.symbol]() {
|
|
443
|
-
return this.eq ? 0 : Hash.cached(this, Hash.hash(this.a))
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** @internal */
|
|
448
|
-
export const cachedFunction = <A, B, E, R>(
|
|
449
|
-
f: (a: A) => Effect.Effect<B, E, R>,
|
|
450
|
-
eq?: Equivalence<A>
|
|
451
|
-
): Effect.Effect<(a: A) => Effect.Effect<B, E, R>> => {
|
|
452
|
-
return pipe(
|
|
453
|
-
core.sync(() => MutableHashMap.empty<Key<A>, Deferred.Deferred<readonly [FiberRefsPatch.FiberRefsPatch, B], E>>()),
|
|
454
|
-
core.flatMap(makeSynchronized),
|
|
455
|
-
core.map((ref) => (a: A) =>
|
|
456
|
-
pipe(
|
|
457
|
-
ref.modifyEffect((map) => {
|
|
458
|
-
const result = pipe(map, MutableHashMap.get(new Key(a, eq)))
|
|
459
|
-
if (Option.isNone(result)) {
|
|
460
|
-
return pipe(
|
|
461
|
-
core.deferredMake<readonly [FiberRefsPatch.FiberRefsPatch, B], E>(),
|
|
462
|
-
core.tap((deferred) =>
|
|
463
|
-
pipe(
|
|
464
|
-
effect.diffFiberRefs(f(a)),
|
|
465
|
-
core.intoDeferred(deferred),
|
|
466
|
-
fiberRuntime.fork
|
|
467
|
-
)
|
|
468
|
-
),
|
|
469
|
-
core.map((deferred) => [deferred, pipe(map, MutableHashMap.set(new Key(a, eq), deferred))] as const)
|
|
470
|
-
)
|
|
471
|
-
}
|
|
472
|
-
return core.succeed([result.value, map] as const)
|
|
473
|
-
}),
|
|
474
|
-
core.flatMap(core.deferredAwait),
|
|
475
|
-
core.flatMap(([patch, b]) => pipe(effect.patchFiberRefs(patch), core.as(b)))
|
|
476
|
-
)
|
|
477
|
-
)
|
|
478
|
-
)
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/** @internal */
|
|
482
|
-
export const raceFirst = dual<
|
|
483
|
-
<A2, E2, R2>(
|
|
484
|
-
that: Effect.Effect<A2, E2, R2>
|
|
485
|
-
) => <A, E, R>(
|
|
486
|
-
self: Effect.Effect<A, E, R>
|
|
487
|
-
) => Effect.Effect<A2 | A, E2 | E, R | R2>,
|
|
488
|
-
<A, E, R, A2, E2, R2>(
|
|
489
|
-
self: Effect.Effect<A, E, R>,
|
|
490
|
-
that: Effect.Effect<A2, E2, R2>
|
|
491
|
-
) => Effect.Effect<A2 | A, E2 | E, R | R2>
|
|
492
|
-
>(2, <A, E, R, A2, E2, R2>(
|
|
493
|
-
self: Effect.Effect<A, E, R>,
|
|
494
|
-
that: Effect.Effect<A2, E2, R2>
|
|
495
|
-
) =>
|
|
496
|
-
pipe(
|
|
497
|
-
core.exit(self),
|
|
498
|
-
fiberRuntime.race(core.exit(that)),
|
|
499
|
-
(effect: Effect.Effect<Exit.Exit<A | A2, E | E2>, never, R | R2>) => core.flatten(effect)
|
|
500
|
-
))
|
|
501
|
-
|
|
502
|
-
/** @internal */
|
|
503
|
-
export const supervised = dual<
|
|
504
|
-
<X>(supervisor: Supervisor.Supervisor<X>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
|
|
505
|
-
<A, E, R, X>(self: Effect.Effect<A, E, R>, supervisor: Supervisor.Supervisor<X>) => Effect.Effect<A, E, R>
|
|
506
|
-
>(2, (self, supervisor) => {
|
|
507
|
-
const supervise = core.fiberRefLocallyWith(fiberRuntime.currentSupervisor, (s) => s.zip(supervisor))
|
|
508
|
-
return supervise(self)
|
|
509
|
-
})
|
|
510
|
-
|
|
511
|
-
/** @internal */
|
|
512
|
-
export const timeout = dual<
|
|
513
|
-
(
|
|
514
|
-
duration: Duration.DurationInput
|
|
515
|
-
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | Cause.TimeoutException, R>,
|
|
516
|
-
<A, E, R>(
|
|
517
|
-
self: Effect.Effect<A, E, R>,
|
|
518
|
-
duration: Duration.DurationInput
|
|
519
|
-
) => Effect.Effect<A, E | Cause.TimeoutException, R>
|
|
520
|
-
>(2, (self, duration) =>
|
|
521
|
-
timeoutFail(self, {
|
|
522
|
-
onTimeout: () => core.timeoutExceptionFromDuration(duration),
|
|
523
|
-
duration
|
|
524
|
-
}))
|
|
525
|
-
|
|
526
|
-
/** @internal */
|
|
527
|
-
export const timeoutFail = dual<
|
|
528
|
-
<E1>(
|
|
529
|
-
options: {
|
|
530
|
-
readonly onTimeout: LazyArg<E1>
|
|
531
|
-
readonly duration: Duration.DurationInput
|
|
532
|
-
}
|
|
533
|
-
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E1, R>,
|
|
534
|
-
<A, E, R, E1>(
|
|
535
|
-
self: Effect.Effect<A, E, R>,
|
|
536
|
-
options: {
|
|
537
|
-
readonly onTimeout: LazyArg<E1>
|
|
538
|
-
readonly duration: Duration.DurationInput
|
|
539
|
-
}
|
|
540
|
-
) => Effect.Effect<A, E | E1, R>
|
|
541
|
-
>(2, (self, { duration, onTimeout }) =>
|
|
542
|
-
core.flatten(timeoutTo(self, {
|
|
543
|
-
onTimeout: () => core.failSync(onTimeout),
|
|
544
|
-
onSuccess: core.succeed,
|
|
545
|
-
duration
|
|
546
|
-
})))
|
|
547
|
-
|
|
548
|
-
/** @internal */
|
|
549
|
-
export const timeoutFailCause = dual<
|
|
550
|
-
<E1>(
|
|
551
|
-
options: {
|
|
552
|
-
readonly onTimeout: LazyArg<Cause.Cause<E1>>
|
|
553
|
-
readonly duration: Duration.DurationInput
|
|
554
|
-
}
|
|
555
|
-
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E | E1, R>,
|
|
556
|
-
<A, E, R, E1>(
|
|
557
|
-
self: Effect.Effect<A, E, R>,
|
|
558
|
-
options: {
|
|
559
|
-
readonly onTimeout: LazyArg<Cause.Cause<E1>>
|
|
560
|
-
readonly duration: Duration.DurationInput
|
|
561
|
-
}
|
|
562
|
-
) => Effect.Effect<A, E | E1, R>
|
|
563
|
-
>(2, (self, { duration, onTimeout }) =>
|
|
564
|
-
core.flatten(timeoutTo(self, {
|
|
565
|
-
onTimeout: () => core.failCauseSync(onTimeout),
|
|
566
|
-
onSuccess: core.succeed,
|
|
567
|
-
duration
|
|
568
|
-
})))
|
|
569
|
-
|
|
570
|
-
/** @internal */
|
|
571
|
-
export const timeoutOption = dual<
|
|
572
|
-
(
|
|
573
|
-
duration: Duration.DurationInput
|
|
574
|
-
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>,
|
|
575
|
-
<A, E, R>(
|
|
576
|
-
self: Effect.Effect<A, E, R>,
|
|
577
|
-
duration: Duration.DurationInput
|
|
578
|
-
) => Effect.Effect<Option.Option<A>, E, R>
|
|
579
|
-
>(2, (self, duration) =>
|
|
580
|
-
timeoutTo(self, {
|
|
581
|
-
duration,
|
|
582
|
-
onSuccess: Option.some,
|
|
583
|
-
onTimeout: Option.none
|
|
584
|
-
}))
|
|
585
|
-
|
|
586
|
-
/** @internal */
|
|
587
|
-
export const timeoutTo = dual<
|
|
588
|
-
<A, B, B1>(
|
|
589
|
-
options: {
|
|
590
|
-
readonly onTimeout: LazyArg<B1>
|
|
591
|
-
readonly onSuccess: (a: A) => B
|
|
592
|
-
readonly duration: Duration.DurationInput
|
|
593
|
-
}
|
|
594
|
-
) => <E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<B | B1, E, R>,
|
|
595
|
-
<A, E, R, B1, B>(
|
|
596
|
-
self: Effect.Effect<A, E, R>,
|
|
597
|
-
options: {
|
|
598
|
-
readonly onTimeout: LazyArg<B1>
|
|
599
|
-
readonly onSuccess: (a: A) => B
|
|
600
|
-
readonly duration: Duration.DurationInput
|
|
601
|
-
}
|
|
602
|
-
) => Effect.Effect<B | B1, E, R>
|
|
603
|
-
>(
|
|
604
|
-
2,
|
|
605
|
-
(self, { duration, onSuccess, onTimeout }) =>
|
|
606
|
-
core.fiberIdWith((parentFiberId) =>
|
|
607
|
-
core.uninterruptibleMask((restore) =>
|
|
608
|
-
fiberRuntime.raceFibersWith(
|
|
609
|
-
restore(self),
|
|
610
|
-
core.interruptible(effect.sleep(duration)),
|
|
611
|
-
{
|
|
612
|
-
onSelfWin: (winner, loser) =>
|
|
613
|
-
core.flatMap(
|
|
614
|
-
winner.await,
|
|
615
|
-
(exit) => {
|
|
616
|
-
if (exit._tag === "Success") {
|
|
617
|
-
return core.flatMap(
|
|
618
|
-
winner.inheritAll,
|
|
619
|
-
() =>
|
|
620
|
-
core.as(
|
|
621
|
-
core.interruptAsFiber(loser, parentFiberId),
|
|
622
|
-
onSuccess(exit.value)
|
|
623
|
-
)
|
|
624
|
-
)
|
|
625
|
-
} else {
|
|
626
|
-
return core.flatMap(
|
|
627
|
-
core.interruptAsFiber(loser, parentFiberId),
|
|
628
|
-
() => core.exitFailCause(exit.cause)
|
|
629
|
-
)
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
),
|
|
633
|
-
onOtherWin: (winner, loser) =>
|
|
634
|
-
core.flatMap(
|
|
635
|
-
winner.await,
|
|
636
|
-
(exit) => {
|
|
637
|
-
if (exit._tag === "Success") {
|
|
638
|
-
return core.flatMap(
|
|
639
|
-
winner.inheritAll,
|
|
640
|
-
() =>
|
|
641
|
-
core.as(
|
|
642
|
-
core.interruptAsFiber(loser, parentFiberId),
|
|
643
|
-
onTimeout()
|
|
644
|
-
)
|
|
645
|
-
)
|
|
646
|
-
} else {
|
|
647
|
-
return core.flatMap(
|
|
648
|
-
core.interruptAsFiber(loser, parentFiberId),
|
|
649
|
-
() => core.exitFailCause(exit.cause)
|
|
650
|
-
)
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
),
|
|
654
|
-
otherScope: globalScope
|
|
655
|
-
}
|
|
656
|
-
)
|
|
657
|
-
)
|
|
658
|
-
)
|
|
659
|
-
)
|
|
660
|
-
|
|
661
|
-
// circular with Synchronized
|
|
662
|
-
|
|
663
|
-
/** @internal */
|
|
664
|
-
const SynchronizedSymbolKey = "effect/Ref/SynchronizedRef"
|
|
665
|
-
|
|
666
|
-
/** @internal */
|
|
667
|
-
export const SynchronizedTypeId: Synchronized.SynchronizedRefTypeId = Symbol.for(
|
|
668
|
-
SynchronizedSymbolKey
|
|
669
|
-
) as Synchronized.SynchronizedRefTypeId
|
|
670
|
-
|
|
671
|
-
/** @internal */
|
|
672
|
-
export const synchronizedVariance = {
|
|
673
|
-
/* c8 ignore next */
|
|
674
|
-
_A: (_: any) => _
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
/** @internal */
|
|
678
|
-
class SynchronizedImpl<in out A> extends Effectable.Class<A> implements Synchronized.SynchronizedRef<A> {
|
|
679
|
-
readonly [SynchronizedTypeId] = synchronizedVariance
|
|
680
|
-
readonly [internalRef.RefTypeId] = internalRef.refVariance
|
|
681
|
-
readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
|
|
682
|
-
constructor(
|
|
683
|
-
readonly ref: Ref.Ref<A>,
|
|
684
|
-
readonly withLock: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
|
|
685
|
-
) {
|
|
686
|
-
super()
|
|
687
|
-
this.get = internalRef.get(this.ref)
|
|
688
|
-
}
|
|
689
|
-
readonly get: Effect.Effect<A>
|
|
690
|
-
commit() {
|
|
691
|
-
return this.get
|
|
692
|
-
}
|
|
693
|
-
modify<B>(f: (a: A) => readonly [B, A]): Effect.Effect<B> {
|
|
694
|
-
return this.modifyEffect((a) => core.succeed(f(a)))
|
|
695
|
-
}
|
|
696
|
-
modifyEffect<B, E, R>(f: (a: A) => Effect.Effect<readonly [B, A], E, R>): Effect.Effect<B, E, R> {
|
|
697
|
-
return this.withLock(
|
|
698
|
-
pipe(
|
|
699
|
-
core.flatMap(internalRef.get(this.ref), f),
|
|
700
|
-
core.flatMap(([b, a]) => core.as(internalRef.set(this.ref, a), b))
|
|
701
|
-
)
|
|
702
|
-
)
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
/** @internal */
|
|
707
|
-
export const makeSynchronized = <A>(value: A): Effect.Effect<Synchronized.SynchronizedRef<A>> =>
|
|
708
|
-
core.sync(() => unsafeMakeSynchronized(value))
|
|
709
|
-
|
|
710
|
-
/** @internal */
|
|
711
|
-
export const unsafeMakeSynchronized = <A>(value: A): Synchronized.SynchronizedRef<A> => {
|
|
712
|
-
const ref = internalRef.unsafeMake(value)
|
|
713
|
-
const sem = unsafeMakeSemaphore(1)
|
|
714
|
-
return new SynchronizedImpl(ref, sem.withPermits(1))
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/** @internal */
|
|
718
|
-
export const updateSomeAndGetEffectSynchronized = dual<
|
|
719
|
-
<A, R, E>(
|
|
720
|
-
pf: (a: A) => Option.Option<Effect.Effect<A, E, R>>
|
|
721
|
-
) => (self: Synchronized.SynchronizedRef<A>) => Effect.Effect<A, E, R>,
|
|
722
|
-
<A, R, E>(
|
|
723
|
-
self: Synchronized.SynchronizedRef<A>,
|
|
724
|
-
pf: (a: A) => Option.Option<Effect.Effect<A, E, R>>
|
|
725
|
-
) => Effect.Effect<A, E, R>
|
|
726
|
-
>(2, (self, pf) =>
|
|
727
|
-
self.modifyEffect((value) => {
|
|
728
|
-
const result = pf(value)
|
|
729
|
-
switch (result._tag) {
|
|
730
|
-
case "None": {
|
|
731
|
-
return core.succeed([value, value] as const)
|
|
732
|
-
}
|
|
733
|
-
case "Some": {
|
|
734
|
-
return core.map(result.value, (a) => [a, a] as const)
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}))
|
|
738
|
-
|
|
739
|
-
// circular with Fiber
|
|
740
|
-
|
|
741
|
-
/** @internal */
|
|
742
|
-
export const zipFiber = dual<
|
|
743
|
-
<A2, E2>(that: Fiber.Fiber<A2, E2>) => <A, E>(self: Fiber.Fiber<A, E>) => Fiber.Fiber<[A, A2], E | E2>,
|
|
744
|
-
<A, E, A2, E2>(self: Fiber.Fiber<A, E>, that: Fiber.Fiber<A2, E2>) => Fiber.Fiber<[A, A2], E | E2>
|
|
745
|
-
>(2, (self, that) => zipWithFiber(self, that, (a, b) => [a, b]))
|
|
746
|
-
|
|
747
|
-
/** @internal */
|
|
748
|
-
export const zipLeftFiber = dual<
|
|
749
|
-
<A2, E2>(that: Fiber.Fiber<A2, E2>) => <A, E>(self: Fiber.Fiber<A, E>) => Fiber.Fiber<A, E | E2>,
|
|
750
|
-
<A, E, A2, E2>(self: Fiber.Fiber<A, E>, that: Fiber.Fiber<A2, E2>) => Fiber.Fiber<A, E | E2>
|
|
751
|
-
>(2, (self, that) => zipWithFiber(self, that, (a, _) => a))
|
|
752
|
-
|
|
753
|
-
/** @internal */
|
|
754
|
-
export const zipRightFiber = dual<
|
|
755
|
-
<A2, E2>(that: Fiber.Fiber<A2, E2>) => <A, E>(self: Fiber.Fiber<A, E>) => Fiber.Fiber<A2, E | E2>,
|
|
756
|
-
<A, E, A2, E2>(self: Fiber.Fiber<A, E>, that: Fiber.Fiber<A2, E2>) => Fiber.Fiber<A2, E | E2>
|
|
757
|
-
>(2, (self, that) => zipWithFiber(self, that, (_, b) => b))
|
|
758
|
-
|
|
759
|
-
/** @internal */
|
|
760
|
-
export const zipWithFiber = dual<
|
|
761
|
-
<B, E2, A, C>(
|
|
762
|
-
that: Fiber.Fiber<B, E2>,
|
|
763
|
-
f: (a: A, b: B) => C
|
|
764
|
-
) => <E>(self: Fiber.Fiber<A, E>) => Fiber.Fiber<C, E | E2>,
|
|
765
|
-
<A, E, B, E2, C>(
|
|
766
|
-
self: Fiber.Fiber<A, E>,
|
|
767
|
-
that: Fiber.Fiber<B, E2>,
|
|
768
|
-
f: (a: A, b: B) => C
|
|
769
|
-
) => Fiber.Fiber<C, E | E2>
|
|
770
|
-
>(3, (self, that, f) => ({
|
|
771
|
-
...Effectable.CommitPrototype,
|
|
772
|
-
commit() {
|
|
773
|
-
return internalFiber.join(this)
|
|
774
|
-
},
|
|
775
|
-
[internalFiber.FiberTypeId]: internalFiber.fiberVariance,
|
|
776
|
-
id: () => pipe(self.id(), FiberId.getOrElse(that.id())),
|
|
777
|
-
await: pipe(
|
|
778
|
-
self.await,
|
|
779
|
-
core.flatten,
|
|
780
|
-
fiberRuntime.zipWithOptions(core.flatten(that.await), f, { concurrent: true }),
|
|
781
|
-
core.exit
|
|
782
|
-
),
|
|
783
|
-
children: self.children,
|
|
784
|
-
inheritAll: core.zipRight(
|
|
785
|
-
that.inheritAll,
|
|
786
|
-
self.inheritAll
|
|
787
|
-
),
|
|
788
|
-
poll: core.zipWith(
|
|
789
|
-
self.poll,
|
|
790
|
-
that.poll,
|
|
791
|
-
(optionA, optionB) =>
|
|
792
|
-
pipe(
|
|
793
|
-
optionA,
|
|
794
|
-
Option.flatMap((exitA) =>
|
|
795
|
-
pipe(
|
|
796
|
-
optionB,
|
|
797
|
-
Option.map((exitB) =>
|
|
798
|
-
Exit.zipWith(exitA, exitB, {
|
|
799
|
-
onSuccess: f,
|
|
800
|
-
onFailure: internalCause.parallel
|
|
801
|
-
})
|
|
802
|
-
)
|
|
803
|
-
)
|
|
804
|
-
)
|
|
805
|
-
)
|
|
806
|
-
),
|
|
807
|
-
interruptAsFork: (id) =>
|
|
808
|
-
core.zipRight(
|
|
809
|
-
self.interruptAsFork(id),
|
|
810
|
-
that.interruptAsFork(id)
|
|
811
|
-
),
|
|
812
|
-
pipe() {
|
|
813
|
-
return pipeArguments(this, arguments)
|
|
814
|
-
}
|
|
815
|
-
}))
|
|
816
|
-
|
|
817
|
-
/* @internal */
|
|
818
|
-
export const bindAll: {
|
|
819
|
-
<
|
|
820
|
-
A extends object,
|
|
821
|
-
X extends Record<string, Effect.Effect<any, any, any>>,
|
|
822
|
-
O extends Types.NoExcessProperties<{
|
|
823
|
-
readonly concurrency?: Types.Concurrency | undefined
|
|
824
|
-
readonly batching?: boolean | "inherit" | undefined
|
|
825
|
-
readonly mode?: "default" | "validate" | "either" | undefined
|
|
826
|
-
readonly concurrentFinalizers?: boolean | undefined
|
|
827
|
-
}, O>
|
|
828
|
-
>(
|
|
829
|
-
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
|
|
830
|
-
options?: undefined | O
|
|
831
|
-
): <E1, R1>(
|
|
832
|
-
self: Effect.Effect<A, E1, R1>
|
|
833
|
-
) => [Effect.All.ReturnObject<X, false, Effect.All.ExtractMode<O>>] extends
|
|
834
|
-
[Effect.Effect<infer Success, infer Error, infer Context>] ? Effect.Effect<
|
|
835
|
-
{
|
|
836
|
-
[K in keyof A | keyof Success]: K extends keyof A ? A[K]
|
|
837
|
-
: K extends keyof Success ? Success[K]
|
|
838
|
-
: never
|
|
839
|
-
},
|
|
840
|
-
| E1
|
|
841
|
-
| Error,
|
|
842
|
-
R1 | Context
|
|
843
|
-
>
|
|
844
|
-
: never
|
|
845
|
-
|
|
846
|
-
<
|
|
847
|
-
A extends object,
|
|
848
|
-
X extends Record<string, Effect.Effect<any, any, any>>,
|
|
849
|
-
O extends Types.NoExcessProperties<{
|
|
850
|
-
readonly concurrency?: Types.Concurrency | undefined
|
|
851
|
-
readonly batching?: boolean | "inherit" | undefined
|
|
852
|
-
readonly mode?: "default" | "validate" | "either" | undefined
|
|
853
|
-
readonly concurrentFinalizers?: boolean | undefined
|
|
854
|
-
}, O>,
|
|
855
|
-
E1,
|
|
856
|
-
R1
|
|
857
|
-
>(
|
|
858
|
-
self: Effect.Effect<A, E1, R1>,
|
|
859
|
-
f: (a: A) => [Extract<keyof X, keyof A>] extends [never] ? X : `Duplicate keys`,
|
|
860
|
-
options?: undefined | {
|
|
861
|
-
readonly concurrency?: Types.Concurrency | undefined
|
|
862
|
-
readonly batching?: boolean | "inherit" | undefined
|
|
863
|
-
readonly mode?: "default" | "validate" | "either" | undefined
|
|
864
|
-
readonly concurrentFinalizers?: boolean | undefined
|
|
865
|
-
}
|
|
866
|
-
): [Effect.All.ReturnObject<X, false, Effect.All.ExtractMode<O>>] extends
|
|
867
|
-
[Effect.Effect<infer Success, infer Error, infer Context>] ? Effect.Effect<
|
|
868
|
-
{
|
|
869
|
-
[K in keyof A | keyof Success]: K extends keyof A ? A[K]
|
|
870
|
-
: K extends keyof Success ? Success[K]
|
|
871
|
-
: never
|
|
872
|
-
},
|
|
873
|
-
| E1
|
|
874
|
-
| Error,
|
|
875
|
-
R1 | Context
|
|
876
|
-
>
|
|
877
|
-
: never
|
|
878
|
-
} = dual((args) => core.isEffect(args[0]), <
|
|
879
|
-
A extends object,
|
|
880
|
-
X extends Record<string, Effect.Effect<any, any, any>>,
|
|
881
|
-
O extends Types.NoExcessProperties<{
|
|
882
|
-
readonly concurrency?: Types.Concurrency | undefined
|
|
883
|
-
readonly batching?: boolean | "inherit" | undefined
|
|
884
|
-
readonly mode?: "default" | "validate" | "either" | undefined
|
|
885
|
-
readonly concurrentFinalizers?: boolean | undefined
|
|
886
|
-
}, O>,
|
|
887
|
-
E1,
|
|
888
|
-
R1
|
|
889
|
-
>(
|
|
890
|
-
self: Effect.Effect<A, E1, R1>,
|
|
891
|
-
f: (a: A) => X,
|
|
892
|
-
options?: undefined | O
|
|
893
|
-
) =>
|
|
894
|
-
core.flatMap(
|
|
895
|
-
self,
|
|
896
|
-
(a) =>
|
|
897
|
-
(fiberRuntime.all(f(a), options) as Effect.All.ReturnObject<
|
|
898
|
-
X,
|
|
899
|
-
Effect.All.IsDiscard<O>,
|
|
900
|
-
Effect.All.ExtractMode<O>
|
|
901
|
-
>)
|
|
902
|
-
.pipe(
|
|
903
|
-
core.map((record) => Object.assign({}, a, record))
|
|
904
|
-
)
|
|
905
|
-
))
|