effect 2.0.0-next.44 → 2.0.0-next.46
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/Bigint/dist/effect-Bigint.cjs.dev.js +125 -1
- package/Bigint/dist/effect-Bigint.cjs.mjs +6 -1
- package/Bigint/dist/effect-Bigint.cjs.prod.js +125 -1
- package/Bigint/dist/effect-Bigint.esm.js +111 -2
- package/Boolean/dist/effect-Boolean.cjs.dev.js +1 -1
- package/Boolean/dist/effect-Boolean.cjs.prod.js +1 -1
- package/Boolean/dist/effect-Boolean.esm.js +1 -1
- package/Brand/dist/effect-Brand.cjs.dev.js +3 -3
- package/Brand/dist/effect-Brand.cjs.prod.js +3 -3
- package/Cache/dist/effect-Cache.cjs.dev.js +32 -32
- package/Cache/dist/effect-Cache.cjs.prod.js +32 -32
- package/Cause/dist/effect-Cause.cjs.dev.js +17 -17
- package/Cause/dist/effect-Cause.cjs.mjs +1 -1
- package/Cause/dist/effect-Cause.cjs.prod.js +17 -17
- package/Cause/dist/effect-Cause.esm.js +4 -4
- package/Channel/dist/effect-Channel.cjs.dev.js +50 -50
- package/Channel/dist/effect-Channel.cjs.mjs +3 -3
- package/Channel/dist/effect-Channel.cjs.prod.js +50 -50
- package/Channel/dist/effect-Channel.esm.js +8 -8
- package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.dev.js +36 -36
- package/ChannelSingleProducerAsyncInput/dist/effect-ChannelSingleProducerAsyncInput.cjs.prod.js +36 -36
- package/Chunk/dist/effect-Chunk.cjs.dev.js +3 -3
- package/Chunk/dist/effect-Chunk.cjs.prod.js +3 -3
- package/Clock/dist/effect-Clock.cjs.dev.js +16 -16
- package/Clock/dist/effect-Clock.cjs.prod.js +16 -16
- package/Config/dist/effect-Config.cjs.dev.js +11 -11
- package/Config/dist/effect-Config.cjs.prod.js +11 -11
- package/ConfigError/dist/effect-ConfigError.cjs.dev.js +4 -4
- package/ConfigError/dist/effect-ConfigError.cjs.prod.js +4 -4
- package/ConfigProvider/dist/effect-ConfigProvider.cjs.dev.js +17 -17
- package/ConfigProvider/dist/effect-ConfigProvider.cjs.prod.js +17 -17
- package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.dev.js +5 -5
- package/ConfigProviderPathPatch/dist/effect-ConfigProviderPathPatch.cjs.prod.js +5 -5
- package/ConfigSecret/dist/effect-ConfigSecret.cjs.dev.js +4 -4
- package/ConfigSecret/dist/effect-ConfigSecret.cjs.prod.js +4 -4
- package/Console/dist/effect-Console.cjs.dev.js +35 -35
- package/Console/dist/effect-Console.cjs.prod.js +35 -35
- package/Context/dist/effect-Context.cjs.dev.js +3 -8
- package/Context/dist/effect-Context.cjs.prod.js +3 -8
- package/Data/dist/effect-Data.cjs.dev.js +141 -54
- package/Data/dist/effect-Data.cjs.mjs +2 -0
- package/Data/dist/effect-Data.cjs.prod.js +141 -54
- package/Data/dist/effect-Data.esm.js +51 -3
- package/DefaultServices/dist/effect-DefaultServices.cjs.dev.js +16 -16
- package/DefaultServices/dist/effect-DefaultServices.cjs.prod.js +16 -16
- package/Deferred/dist/effect-Deferred.cjs.dev.js +8 -8
- package/Deferred/dist/effect-Deferred.cjs.prod.js +8 -8
- package/Differ/dist/effect-Differ.cjs.dev.js +11 -11
- package/Differ/dist/effect-Differ.cjs.prod.js +11 -11
- package/Duration/dist/effect-Duration.cjs.dev.js +3 -3
- package/Duration/dist/effect-Duration.cjs.prod.js +3 -3
- package/Effect/dist/effect-Effect.cjs.dev.js +44 -44
- package/Effect/dist/effect-Effect.cjs.prod.js +44 -44
- package/Effectable/dist/effect-Effectable.cjs.dev.js +24 -14
- package/Effectable/dist/effect-Effectable.cjs.mjs +5 -4
- package/Effectable/dist/effect-Effectable.cjs.prod.js +24 -14
- package/Effectable/dist/effect-Effectable.esm.js +15 -5
- package/Either/dist/effect-Either.cjs.dev.js +3 -3
- package/Either/dist/effect-Either.cjs.prod.js +3 -3
- package/Encoding/dist/effect-Encoding.cjs.dev.js +3 -3
- package/Encoding/dist/effect-Encoding.cjs.prod.js +3 -3
- package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.dev.js +2 -2
- package/ExecutionStrategy/dist/effect-ExecutionStrategy.cjs.prod.js +2 -2
- package/Exit/dist/effect-Exit.cjs.dev.js +8 -8
- package/Exit/dist/effect-Exit.cjs.prod.js +8 -8
- package/Fiber/dist/effect-Fiber.cjs.dev.js +29 -29
- package/Fiber/dist/effect-Fiber.cjs.prod.js +29 -29
- package/FiberId/dist/effect-FiberId.cjs.dev.js +5 -5
- package/FiberId/dist/effect-FiberId.cjs.prod.js +5 -5
- package/FiberRef/dist/effect-FiberRef.cjs.dev.js +29 -29
- package/FiberRef/dist/effect-FiberRef.cjs.prod.js +29 -29
- package/FiberRefs/dist/effect-FiberRefs.cjs.dev.js +9 -9
- package/FiberRefs/dist/effect-FiberRefs.cjs.prod.js +9 -9
- package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.dev.js +10 -10
- package/FiberRefsPatch/dist/effect-FiberRefsPatch.cjs.prod.js +10 -10
- package/GroupBy/dist/effect-GroupBy.cjs.dev.js +42 -42
- package/GroupBy/dist/effect-GroupBy.cjs.prod.js +42 -42
- package/HashMap/dist/effect-HashMap.cjs.dev.js +20 -20
- package/HashMap/dist/effect-HashMap.cjs.prod.js +20 -20
- package/HashSet/dist/effect-HashSet.cjs.dev.js +20 -20
- package/HashSet/dist/effect-HashSet.cjs.prod.js +20 -20
- package/KeyedPool/dist/effect-KeyedPool.cjs.dev.js +33 -33
- package/KeyedPool/dist/effect-KeyedPool.cjs.prod.js +33 -33
- package/Layer/dist/effect-Layer.cjs.dev.js +32 -32
- package/Layer/dist/effect-Layer.cjs.prod.js +32 -32
- package/List/dist/effect-List.cjs.dev.js +3 -3
- package/List/dist/effect-List.cjs.prod.js +3 -3
- package/LogLevel/dist/effect-LogLevel.cjs.dev.js +8 -8
- package/LogLevel/dist/effect-LogLevel.cjs.prod.js +8 -8
- package/Logger/dist/effect-Logger.cjs.dev.js +33 -33
- package/Logger/dist/effect-Logger.cjs.prod.js +33 -33
- package/Metric/dist/effect-Metric.cjs.dev.js +27 -27
- package/Metric/dist/effect-Metric.cjs.prod.js +27 -27
- package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.dev.js +4 -4
- package/MetricBoundaries/dist/effect-MetricBoundaries.cjs.prod.js +4 -4
- package/MetricHook/dist/effect-MetricHook.cjs.dev.js +6 -6
- package/MetricHook/dist/effect-MetricHook.cjs.prod.js +6 -6
- package/MetricKey/dist/effect-MetricKey.cjs.dev.js +6 -6
- package/MetricKey/dist/effect-MetricKey.cjs.prod.js +6 -6
- package/MetricKeyType/dist/effect-MetricKeyType.cjs.dev.js +4 -4
- package/MetricKeyType/dist/effect-MetricKeyType.cjs.prod.js +4 -4
- package/MetricPolling/dist/effect-MetricPolling.cjs.dev.js +30 -30
- package/MetricPolling/dist/effect-MetricPolling.cjs.prod.js +30 -30
- package/MetricRegistry/dist/effect-MetricRegistry.cjs.dev.js +8 -8
- package/MetricRegistry/dist/effect-MetricRegistry.cjs.prod.js +8 -8
- package/MetricState/dist/effect-MetricState.cjs.dev.js +1 -1
- package/MetricState/dist/effect-MetricState.cjs.prod.js +1 -1
- package/MutableHashMap/dist/effect-MutableHashMap.cjs.dev.js +4 -4
- package/MutableHashMap/dist/effect-MutableHashMap.cjs.prod.js +4 -4
- package/MutableHashSet/dist/effect-MutableHashSet.cjs.dev.js +4 -4
- package/MutableHashSet/dist/effect-MutableHashSet.cjs.prod.js +4 -4
- package/MutableQueue/dist/effect-MutableQueue.cjs.dev.js +3 -3
- package/MutableQueue/dist/effect-MutableQueue.cjs.prod.js +3 -3
- package/Number/dist/effect-Number.cjs.dev.js +1 -1
- package/Number/dist/effect-Number.cjs.prod.js +1 -1
- package/Number/dist/effect-Number.esm.js +1 -1
- package/Option/dist/effect-Option.cjs.dev.js +9 -9
- package/Option/dist/effect-Option.cjs.prod.js +9 -9
- package/Pool/dist/effect-Pool.cjs.dev.js +31 -31
- package/Pool/dist/effect-Pool.cjs.prod.js +31 -31
- package/PubSub/dist/effect-PubSub.cjs.d.mts +2 -0
- package/PubSub/dist/effect-PubSub.cjs.d.mts.map +1 -0
- package/PubSub/dist/effect-PubSub.cjs.d.ts +2 -0
- package/PubSub/dist/effect-PubSub.cjs.d.ts.map +1 -0
- package/{Hub/dist/effect-Hub.cjs.dev.js → PubSub/dist/effect-PubSub.cjs.dev.js} +163 -163
- package/PubSub/dist/effect-PubSub.cjs.js +7 -0
- package/{Hub/dist/effect-Hub.cjs.mjs → PubSub/dist/effect-PubSub.cjs.mjs} +1 -1
- package/{Hub/dist/effect-Hub.cjs.prod.js → PubSub/dist/effect-PubSub.cjs.prod.js} +163 -163
- package/{Hub/dist/effect-Hub.esm.js → PubSub/dist/effect-PubSub.esm.js} +15 -15
- package/PubSub/package.json +4 -0
- package/Queue/dist/effect-Queue.cjs.dev.js +28 -28
- package/Queue/dist/effect-Queue.cjs.prod.js +28 -28
- package/README.md +5 -5
- package/Random/dist/effect-Random.cjs.dev.js +16 -16
- package/Random/dist/effect-Random.cjs.prod.js +16 -16
- package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.dev.js +3 -3
- package/ReadonlyArray/dist/effect-ReadonlyArray.cjs.prod.js +3 -3
- package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.dev.js +3 -3
- package/ReadonlyRecord/dist/effect-ReadonlyRecord.cjs.prod.js +3 -3
- package/RedBlackTree/dist/effect-RedBlackTree.cjs.dev.js +4 -4
- package/RedBlackTree/dist/effect-RedBlackTree.cjs.prod.js +4 -4
- package/Ref/dist/effect-Ref.cjs.dev.js +9 -9
- package/Ref/dist/effect-Ref.cjs.prod.js +9 -9
- package/Reloadable/dist/effect-Reloadable.cjs.dev.js +44 -44
- package/Reloadable/dist/effect-Reloadable.cjs.prod.js +44 -44
- package/Request/dist/effect-Request.cjs.dev.js +29 -29
- package/Request/dist/effect-Request.cjs.prod.js +29 -29
- package/RequestBlock/dist/effect-RequestBlock.cjs.dev.js +36 -36
- package/RequestBlock/dist/effect-RequestBlock.cjs.prod.js +36 -36
- package/RequestResolver/dist/effect-RequestResolver.cjs.dev.js +38 -38
- package/RequestResolver/dist/effect-RequestResolver.cjs.prod.js +38 -38
- package/Resource/dist/effect-Resource.cjs.dev.js +34 -34
- package/Resource/dist/effect-Resource.cjs.prod.js +34 -34
- package/Runtime/dist/effect-Runtime.cjs.dev.js +34 -34
- package/Runtime/dist/effect-Runtime.cjs.prod.js +34 -34
- package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.dev.js +33 -33
- package/RuntimeFlags/dist/effect-RuntimeFlags.cjs.prod.js +33 -33
- package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.dev.js +6 -6
- package/RuntimeFlagsPatch/dist/effect-RuntimeFlagsPatch.cjs.prod.js +6 -6
- package/STM/dist/effect-STM.cjs.dev.js +48 -48
- package/STM/dist/effect-STM.cjs.prod.js +48 -48
- package/Schedule/dist/effect-Schedule.cjs.dev.js +19 -19
- package/Schedule/dist/effect-Schedule.cjs.prod.js +19 -19
- package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.dev.js +3 -3
- package/ScheduleDecision/dist/effect-ScheduleDecision.cjs.prod.js +3 -3
- package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.dev.js +3 -3
- package/ScheduleInterval/dist/effect-ScheduleInterval.cjs.prod.js +3 -3
- package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.dev.js +3 -3
- package/ScheduleIntervals/dist/effect-ScheduleIntervals.cjs.prod.js +3 -3
- package/Scheduler/dist/effect-Scheduler.cjs.dev.js +8 -8
- package/Scheduler/dist/effect-Scheduler.cjs.prod.js +8 -8
- package/Scope/dist/effect-Scope.cjs.dev.js +27 -27
- package/Scope/dist/effect-Scope.cjs.prod.js +27 -27
- package/ScopedCache/dist/effect-ScopedCache.cjs.dev.js +78 -61
- package/ScopedCache/dist/effect-ScopedCache.cjs.prod.js +78 -61
- package/ScopedRef/dist/effect-ScopedRef.cjs.dev.js +34 -34
- package/ScopedRef/dist/effect-ScopedRef.cjs.prod.js +34 -34
- package/Sink/dist/effect-Sink.cjs.dev.js +43 -43
- package/Sink/dist/effect-Sink.cjs.mjs +1 -1
- package/Sink/dist/effect-Sink.cjs.prod.js +43 -43
- package/Sink/dist/effect-Sink.esm.js +5 -5
- package/SortedMap/dist/effect-SortedMap.cjs.dev.js +3 -3
- package/SortedMap/dist/effect-SortedMap.cjs.prod.js +3 -3
- package/SortedSet/dist/effect-SortedSet.cjs.dev.js +3 -3
- package/SortedSet/dist/effect-SortedSet.cjs.prod.js +3 -3
- package/Stream/dist/effect-Stream.cjs.dev.js +60 -60
- package/Stream/dist/effect-Stream.cjs.mjs +5 -5
- package/Stream/dist/effect-Stream.cjs.prod.js +60 -60
- package/Stream/dist/effect-Stream.esm.js +15 -15
- package/Streamable/dist/effect-Streamable.cjs.d.mts +2 -0
- package/Streamable/dist/effect-Streamable.cjs.d.mts.map +1 -0
- package/Streamable/dist/effect-Streamable.cjs.d.ts +2 -0
- package/Streamable/dist/effect-Streamable.cjs.d.ts.map +1 -0
- package/Streamable/dist/effect-Streamable.cjs.dev.js +152 -0
- package/Streamable/dist/effect-Streamable.cjs.js +7 -0
- package/Streamable/dist/effect-Streamable.cjs.mjs +3 -0
- package/Streamable/dist/effect-Streamable.cjs.prod.js +152 -0
- package/Streamable/dist/effect-Streamable.esm.js +42 -0
- package/Streamable/package.json +4 -0
- package/String/dist/effect-String.cjs.dev.js +4 -4
- package/String/dist/effect-String.cjs.prod.js +4 -4
- package/String/dist/effect-String.esm.js +1 -1
- package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.dev.js +48 -48
- package/SubscriptionRef/dist/effect-SubscriptionRef.cjs.prod.js +48 -48
- package/Supervisor/dist/effect-Supervisor.cjs.dev.js +34 -34
- package/Supervisor/dist/effect-Supervisor.cjs.prod.js +34 -34
- package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.dev.js +30 -30
- package/SynchronizedRef/dist/effect-SynchronizedRef.cjs.prod.js +30 -30
- package/TArray/dist/effect-TArray.cjs.dev.js +46 -46
- package/TArray/dist/effect-TArray.cjs.prod.js +46 -46
- package/TDeferred/dist/effect-TDeferred.cjs.dev.js +45 -45
- package/TDeferred/dist/effect-TDeferred.cjs.prod.js +45 -45
- package/TMap/dist/effect-TMap.cjs.dev.js +47 -47
- package/TMap/dist/effect-TMap.cjs.prod.js +47 -47
- package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.dev.js +44 -44
- package/TPriorityQueue/dist/effect-TPriorityQueue.cjs.prod.js +44 -44
- package/TPubSub/dist/effect-TPubSub.cjs.d.mts +2 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.mts.map +1 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.ts +2 -0
- package/TPubSub/dist/effect-TPubSub.cjs.d.ts.map +1 -0
- package/{THub/dist/effect-THub.cjs.dev.js → TPubSub/dist/effect-TPubSub.cjs.dev.js} +101 -101
- package/TPubSub/dist/effect-TPubSub.cjs.js +7 -0
- package/{THub/dist/effect-THub.cjs.mjs → TPubSub/dist/effect-TPubSub.cjs.mjs} +2 -2
- package/{THub/dist/effect-THub.cjs.prod.js → TPubSub/dist/effect-TPubSub.cjs.prod.js} +101 -101
- package/TPubSub/dist/effect-TPubSub.esm.js +157 -0
- package/TPubSub/package.json +4 -0
- package/TQueue/dist/effect-TQueue.cjs.dev.js +46 -46
- package/TQueue/dist/effect-TQueue.cjs.prod.js +46 -46
- package/TRandom/dist/effect-TRandom.cjs.dev.js +50 -50
- package/TRandom/dist/effect-TRandom.cjs.prod.js +50 -50
- package/TReentrantLock/dist/effect-TReentrantLock.cjs.dev.js +46 -46
- package/TReentrantLock/dist/effect-TReentrantLock.cjs.prod.js +46 -46
- package/TRef/dist/effect-TRef.cjs.dev.js +44 -44
- package/TRef/dist/effect-TRef.cjs.prod.js +44 -44
- package/TSemaphore/dist/effect-TSemaphore.cjs.dev.js +45 -45
- package/TSemaphore/dist/effect-TSemaphore.cjs.prod.js +45 -45
- package/TSet/dist/effect-TSet.cjs.dev.js +47 -47
- package/TSet/dist/effect-TSet.cjs.prod.js +47 -47
- package/Take/dist/effect-Take.cjs.dev.js +36 -36
- package/Take/dist/effect-Take.cjs.prod.js +36 -36
- package/TestAnnotation/dist/effect-TestAnnotation.cjs.dev.js +8 -8
- package/TestAnnotation/dist/effect-TestAnnotation.cjs.prod.js +8 -8
- package/TestAnnotations/dist/effect-TestAnnotations.cjs.dev.js +25 -25
- package/TestAnnotations/dist/effect-TestAnnotations.cjs.prod.js +25 -25
- package/TestClock/dist/effect-TestClock.cjs.dev.js +46 -46
- package/TestClock/dist/effect-TestClock.cjs.prod.js +46 -46
- package/TestConfig/dist/effect-TestConfig.cjs.dev.js +3 -8
- package/TestConfig/dist/effect-TestConfig.cjs.prod.js +3 -8
- package/TestContext/dist/effect-TestContext.cjs.dev.js +37 -37
- package/TestContext/dist/effect-TestContext.cjs.prod.js +37 -37
- package/TestLive/dist/effect-TestLive.cjs.dev.js +17 -17
- package/TestLive/dist/effect-TestLive.cjs.prod.js +17 -17
- package/TestServices/dist/effect-TestServices.cjs.dev.js +42 -42
- package/TestServices/dist/effect-TestServices.cjs.prod.js +42 -42
- package/TestSized/dist/effect-TestSized.cjs.dev.js +11 -11
- package/TestSized/dist/effect-TestSized.cjs.prod.js +11 -11
- package/Tracer/dist/effect-Tracer.cjs.dev.js +16 -16
- package/Tracer/dist/effect-Tracer.cjs.prod.js +16 -16
- package/dist/{Context-01a123ac.cjs.prod.js → Context-9fe5eb16.cjs.prod.js} +5 -5
- package/dist/{Context-593661f6.cjs.dev.js → Context-da73ddfa.cjs.dev.js} +5 -5
- package/dist/{Effectable-2f022879.cjs.dev.js → Effectable-7314aed8.cjs.dev.js} +63 -10
- package/dist/{Effectable-cd8f3a96.cjs.prod.js → Effectable-c4c14a2b.cjs.prod.js} +63 -10
- package/dist/{Either-7a881c7a.cjs.prod.js → Either-d43f082c.cjs.prod.js} +6 -79
- package/dist/{Either-12bbe00c.cjs.dev.js → Either-fa0ef1d9.cjs.dev.js} +6 -79
- package/dist/{ExecutionStrategy-14d3053a.cjs.prod.js → ExecutionStrategy-4808fe5d.cjs.prod.js} +2 -2
- package/dist/{ExecutionStrategy-70f1a920.cjs.dev.js → ExecutionStrategy-7d9d457b.cjs.dev.js} +2 -2
- package/dist/{HashSet-0b4ff1e4.cjs.dev.js → HashSet-5963ad6b.cjs.dev.js} +32 -32
- package/dist/{HashSet-6257b66d.cjs.prod.js → HashSet-ac02a3e1.cjs.prod.js} +32 -32
- package/dist/Option-463b42e6.cjs.dev.js +81 -0
- package/dist/Option-935e5d7c.cjs.prod.js +81 -0
- package/dist/{Ref-a3a4e50d.cjs.prod.js → Ref-4014b526.cjs.prod.js} +1 -1
- package/dist/{Ref-74b592a4.cjs.dev.js → Ref-acdee7ef.cjs.dev.js} +1 -1
- package/dist/{cache-75fbef45.cjs.prod.js → cache-5c7d77e4.cjs.prod.js} +17 -17
- package/dist/{cache-e1ea3923.cjs.dev.js → cache-7eed9d33.cjs.dev.js} +17 -17
- package/dist/{circular-6f16b226.cjs.prod.js → circular-1f481ffb.cjs.prod.js} +33 -33
- package/dist/{circular-f406f9a4.cjs.prod.js → circular-9e10a5a7.cjs.prod.js} +6 -6
- package/dist/{circular-58ff5e9c.cjs.dev.js → circular-c2dbce1a.cjs.dev.js} +33 -33
- package/dist/{circular-30564534.cjs.dev.js → circular-c8b65bdb.cjs.dev.js} +6 -6
- package/dist/{config-80900693.cjs.dev.js → config-3b7935a3.cjs.dev.js} +3 -3
- package/dist/{config-d0ddc159.cjs.prod.js → config-5ba54da1.cjs.prod.js} +3 -3
- package/dist/{configProvider-93617d6d.cjs.prod.js → configProvider-b6b20998.cjs.prod.js} +29 -29
- package/dist/{configProvider-ce43fdbf.cjs.dev.js → configProvider-f34a82f1.cjs.dev.js} +29 -29
- package/dist/{core-0b0539de.cjs.prod.js → core-07202cc0.cjs.prod.js} +711 -726
- package/dist/{core-60ca562a.cjs.prod.js → core-7411d1e1.cjs.prod.js} +3 -3
- package/dist/{core-b4d7b4f5.cjs.dev.js → core-b7401357.cjs.dev.js} +711 -726
- package/dist/{core-13f8a866.cjs.dev.js → core-c5747f88.cjs.dev.js} +3 -3
- package/dist/{core-effect-892f3686.cjs.dev.js → core-effect-1c564d42.cjs.dev.js} +77 -75
- package/dist/{core-effect-c65770cd.cjs.prod.js → core-effect-9201ea63.cjs.prod.js} +77 -75
- package/dist/{dataSource-3ba9e4d3.cjs.dev.js → dataSource-b5eda714.cjs.dev.js} +2 -2
- package/dist/{dataSource-7df3a5f6.cjs.prod.js → dataSource-b83bc277.cjs.prod.js} +2 -2
- package/dist/declarations/src/Bigint.d.ts +92 -1
- package/dist/declarations/src/Bigint.d.ts.map +1 -1
- package/dist/declarations/src/Boolean.d.ts +1 -1
- package/dist/declarations/src/Cause.d.ts +6 -6
- package/dist/declarations/src/Cause.d.ts.map +1 -1
- package/dist/declarations/src/Channel.d.ts +7 -7
- package/dist/declarations/src/Channel.d.ts.map +1 -1
- package/dist/declarations/src/Data.d.ts +30 -0
- package/dist/declarations/src/Data.d.ts.map +1 -1
- package/dist/declarations/src/Effect.d.ts +4 -2
- package/dist/declarations/src/Effect.d.ts.map +1 -1
- package/dist/declarations/src/Effectable.d.ts +14 -4
- package/dist/declarations/src/Effectable.d.ts.map +1 -1
- package/dist/declarations/src/Metric.d.ts +31 -7
- package/dist/declarations/src/Metric.d.ts.map +1 -1
- package/dist/declarations/src/MetricHook.d.ts +7 -4
- package/dist/declarations/src/MetricHook.d.ts.map +1 -1
- package/dist/declarations/src/MetricKey.d.ts +24 -4
- package/dist/declarations/src/MetricKey.d.ts.map +1 -1
- package/dist/declarations/src/MetricKeyType.d.ts +9 -6
- package/dist/declarations/src/MetricKeyType.d.ts.map +1 -1
- package/dist/declarations/src/MetricRegistry.d.ts +2 -2
- package/dist/declarations/src/MetricRegistry.d.ts.map +1 -1
- package/dist/declarations/src/MetricState.d.ts +15 -9
- package/dist/declarations/src/MetricState.d.ts.map +1 -1
- package/dist/declarations/src/Number.d.ts +1 -1
- package/dist/declarations/src/{Hub.d.ts → PubSub.d.ts} +38 -38
- package/dist/declarations/src/PubSub.d.ts.map +1 -0
- package/dist/declarations/src/Sink.d.ts +4 -4
- package/dist/declarations/src/Sink.d.ts.map +1 -1
- package/dist/declarations/src/Stream.d.ts +24 -24
- package/dist/declarations/src/Stream.d.ts.map +1 -1
- package/dist/declarations/src/Streamable.d.ts +27 -0
- package/dist/declarations/src/Streamable.d.ts.map +1 -0
- package/dist/declarations/src/String.d.ts +1 -1
- package/dist/declarations/src/SubscriptionRef.d.ts.map +1 -1
- package/dist/declarations/src/TPubSub.d.ts +146 -0
- package/dist/declarations/src/TPubSub.d.ts.map +1 -0
- package/dist/declarations/src/index.d.ts +15 -15
- package/dist/declarations/src/index.d.ts.map +1 -1
- package/dist/{defaultServices-5530ff0e.cjs.dev.js → defaultServices-755d5b46.cjs.dev.js} +6 -6
- package/dist/{defaultServices-086b8ac9.cjs.prod.js → defaultServices-9d7ce86f.cjs.prod.js} +6 -6
- package/dist/effect.cjs.dev.js +9 -9
- package/dist/effect.cjs.mjs +3 -3
- package/dist/effect.cjs.prod.js +9 -9
- package/dist/effect.esm.js +6 -6
- package/dist/{fiber-1bfb4c1d.cjs.dev.js → fiber-5156eff2.cjs.dev.js} +12 -12
- package/dist/{fiber-2eb0a4c1.cjs.prod.js → fiber-9519d109.cjs.prod.js} +12 -12
- package/dist/{fiberRefs-be6b6a70.cjs.prod.js → fiberRefs-558c17e6.cjs.prod.js} +1 -1
- package/dist/{fiberRefs-be4fae6a.cjs.dev.js → fiberRefs-98b71233.cjs.dev.js} +1 -1
- package/dist/{fiberRuntime-2d31e120.cjs.prod.js → fiberRuntime-31ae011f.cjs.prod.js} +99 -100
- package/dist/{fiberRuntime-c7280769.cjs.dev.js → fiberRuntime-d3872282.cjs.dev.js} +99 -100
- package/dist/{groupBy-0702739b.cjs.prod.js → groupBy-724f64ef.cjs.prod.js} +4 -4
- package/dist/{groupBy-7f852bf3.cjs.dev.js → groupBy-862cc2da.cjs.dev.js} +4 -4
- package/dist/{hook-e72b20fd.cjs.dev.js → hook-8cefc909.cjs.dev.js} +8 -4
- package/dist/{hook-470b717e.cjs.prod.js → hook-98ce30e4.cjs.prod.js} +8 -4
- package/dist/{key-f0a1408a.cjs.dev.js → key-198b6670.cjs.dev.js} +3 -3
- package/dist/{key-378a6a2c.cjs.prod.js → key-eb8a12b2.cjs.prod.js} +3 -3
- package/dist/{keyType-cf67c69c.cjs.prod.js → keyType-0c5e6178.cjs.prod.js} +9 -2
- package/dist/{keyType-55f27f07.cjs.dev.js → keyType-7c164b82.cjs.dev.js} +9 -2
- package/dist/{layer-b42e8022.cjs.dev.js → layer-29574350.cjs.dev.js} +33 -33
- package/dist/{layer-d103b49b.cjs.prod.js → layer-51ff4846.cjs.prod.js} +33 -33
- package/dist/{patch-a1b2802f.cjs.dev.js → patch-0220a642.cjs.dev.js} +1 -1
- package/dist/{patch-c4d6c61e.cjs.prod.js → patch-7c559bb2.cjs.prod.js} +1 -1
- package/dist/{pathPatch-15c8d723.cjs.prod.js → pathPatch-b56a4da2.cjs.prod.js} +1 -1
- package/dist/{pathPatch-d9d41297.cjs.dev.js → pathPatch-fab016f1.cjs.dev.js} +1 -1
- package/dist/{pool-ef44ba82.cjs.dev.js → pool-3211287f.cjs.dev.js} +31 -31
- package/dist/{pool-e414eb88.cjs.prod.js → pool-f77d7705.cjs.prod.js} +31 -31
- package/dist/{query-1d0157db.cjs.prod.js → query-a52b25f0.cjs.prod.js} +11 -11
- package/dist/{query-54337864.cjs.dev.js → query-c36decd5.cjs.dev.js} +11 -11
- package/dist/{queue-27ac9d98.cjs.prod.js → queue-315ea45d.cjs.prod.js} +22 -22
- package/dist/{queue-533d70d4.cjs.dev.js → queue-7a223c44.cjs.dev.js} +22 -22
- package/dist/{registry-1099de3f.cjs.dev.js → registry-62ff192e.cjs.dev.js} +4 -4
- package/dist/{registry-013ecdde.cjs.prod.js → registry-d5258dff.cjs.prod.js} +4 -4
- package/dist/{runtime-ea174155.cjs.prod.js → runtime-005f8a9b.cjs.prod.js} +7 -7
- package/dist/{runtime-afad6a9b.cjs.dev.js → runtime-57c8ddf8.cjs.dev.js} +7 -7
- package/dist/{schedule-1d92198c.cjs.prod.js → schedule-8cdf6bf1.cjs.prod.js} +40 -40
- package/dist/{schedule-e0f55cab.cjs.dev.js → schedule-e7a9f93f.cjs.dev.js} +40 -40
- package/dist/scopedRef-789d7fef.cjs.prod.js +55 -0
- package/dist/scopedRef-eb19c7a6.cjs.dev.js +55 -0
- package/dist/{singleProducerAsyncInput-4105a342.cjs.dev.js → singleProducerAsyncInput-9ff8389b.cjs.dev.js} +1 -1
- package/dist/{singleProducerAsyncInput-21463e16.cjs.prod.js → singleProducerAsyncInput-f9b258b1.cjs.prod.js} +1 -1
- package/dist/{sink-9129504b.cjs.prod.js → sink-572d8981.cjs.prod.js} +17 -17
- package/dist/{sink-ee393b63.cjs.dev.js → sink-8d3427e7.cjs.dev.js} +17 -17
- package/dist/{state-dd1bd066.cjs.prod.js → state-0bdf02b7.cjs.prod.js} +2 -6
- package/dist/{state-8fbec044.cjs.dev.js → state-931050c4.cjs.dev.js} +2 -6
- package/dist/{stm-537da66b.cjs.dev.js → stm-8aca0022.cjs.dev.js} +3 -3
- package/dist/{stm-5043c3cb.cjs.prod.js → stm-f250b596.cjs.prod.js} +3 -3
- package/dist/{stream-c7eda5bc.cjs.dev.js → stream-34d80d2c.cjs.dev.js} +31 -28
- package/dist/{stream-13637643.cjs.prod.js → stream-ea4f4d44.cjs.prod.js} +31 -28
- package/dist/{synchronizedRef-37e32854.cjs.dev.js → synchronizedRef-a12fd967.cjs.dev.js} +6 -6
- package/dist/{synchronizedRef-b4cde4de.cjs.prod.js → synchronizedRef-ed8aa6ac.cjs.prod.js} +6 -6
- package/dist/{tArray-df1bae1c.cjs.dev.js → tArray-17f078f2.cjs.dev.js} +3 -3
- package/dist/{tArray-d5476a2d.cjs.prod.js → tArray-d184e22f.cjs.prod.js} +3 -3
- package/dist/{tMap-a3e14c05.cjs.dev.js → tMap-1a5aa78b.cjs.dev.js} +4 -4
- package/dist/{tMap-20ef43ea.cjs.prod.js → tMap-e219f30e.cjs.prod.js} +4 -4
- package/dist/{tQueue-bd3cf539.cjs.dev.js → tQueue-0a4fc773.cjs.dev.js} +3 -3
- package/dist/{tQueue-c02c22bd.cjs.prod.js → tQueue-47129ad0.cjs.prod.js} +3 -3
- package/dist/{tRef-49e44dde.cjs.prod.js → tRef-ab4c5713.cjs.prod.js} +1 -1
- package/dist/{tRef-75dd04b3.cjs.dev.js → tRef-b860ef05.cjs.dev.js} +1 -1
- package/internal/Context.esm.js +4 -4
- package/internal/Data.esm.js +4 -1
- package/internal/Differ/ChunkPatch.esm.js +1 -1
- package/internal/Differ/ContextPatch.esm.js +1 -1
- package/internal/Differ/HashMapPatch.esm.js +1 -1
- package/internal/Differ/HashSetPatch.esm.js +1 -1
- package/internal/Differ/OrPatch.esm.js +1 -1
- package/internal/Effectable.esm.js +9 -9
- package/internal/Either.esm.js +3 -3
- package/internal/Option.esm.js +3 -3
- package/internal/cache.esm.js +1 -1
- package/internal/cause.esm.js +6 -21
- package/internal/channel.esm.js +5 -5
- package/internal/core-effect.esm.js +6 -4
- package/internal/fiberRuntime.esm.js +3 -3
- package/internal/layer.esm.js +1 -1
- package/internal/metric/hook.esm.js +7 -3
- package/internal/metric/key.esm.js +2 -2
- package/internal/metric/keyType.esm.js +9 -2
- package/internal/metric/registry.esm.js +2 -2
- package/internal/metric/state.esm.js +2 -6
- package/internal/metric.esm.js +3 -3
- package/internal/{hub.esm.js → pubsub.esm.js} +108 -108
- package/internal/request.esm.js +1 -1
- package/internal/sink.esm.js +8 -8
- package/internal/stm/{tHub.esm.js → tPubSub.esm.js} +30 -30
- package/internal/stream.esm.js +23 -20
- package/internal/subscriptionRef.esm.js +8 -8
- package/package.json +66 -211
- package/src/.index.ts +30 -0
- package/src/Bigint.ts +497 -0
- package/src/Boolean.ts +261 -0
- package/src/Brand.ts +336 -0
- package/src/Cache.ts +250 -0
- package/src/Cause.ts +813 -0
- package/src/Channel.ts +2244 -0
- package/src/ChannelChildExecutorDecision.ts +138 -0
- package/src/ChannelMergeDecision.ts +94 -0
- package/src/ChannelMergeState.ts +166 -0
- package/src/ChannelMergeStrategy.ts +107 -0
- package/src/ChannelSingleProducerAsyncInput.ts +68 -0
- package/src/ChannelUpstreamPullRequest.ts +110 -0
- package/src/ChannelUpstreamPullStrategy.ts +120 -0
- package/src/Chunk.ts +1314 -0
- package/src/Clock.ts +111 -0
- package/src/Config.ts +447 -0
- package/src/ConfigError.ts +267 -0
- package/src/ConfigProvider.ts +296 -0
- package/src/ConfigProviderPathPatch.ts +100 -0
- package/src/ConfigSecret.ts +76 -0
- package/src/Console.ts +222 -0
- package/src/Context.ts +365 -0
- package/src/Data.ts +367 -0
- package/src/DefaultServices.ts +34 -0
- package/src/Deferred.ts +283 -0
- package/src/Differ.ts +406 -0
- package/src/Duration.ts +558 -0
- package/src/Effect.ts +5177 -0
- package/src/Effectable.ts +107 -0
- package/src/Either.ts +593 -0
- package/src/Encoding.ts +130 -0
- package/src/Equal.ts +64 -0
- package/src/Equivalence.ts +235 -0
- package/src/ExecutionStrategy.ts +111 -0
- package/src/Exit.ts +464 -0
- package/src/Fiber.ts +650 -0
- package/src/FiberId.ts +187 -0
- package/src/FiberRef.ts +399 -0
- package/src/FiberRefs.ts +160 -0
- package/src/FiberRefsPatch.ts +105 -0
- package/src/FiberStatus.ts +108 -0
- package/src/Function.ts +834 -0
- package/src/GlobalValue.ts +20 -0
- package/src/GroupBy.ts +102 -0
- package/src/HKT.ts +44 -0
- package/src/Hash.ts +162 -0
- package/src/HashMap.ts +373 -0
- package/src/HashSet.ts +300 -0
- package/src/Inspectable.ts +45 -0
- package/src/KeyedPool.ts +160 -0
- package/src/Layer.ts +866 -0
- package/src/List.ts +942 -0
- package/src/LogLevel.ts +266 -0
- package/src/LogSpan.ts +25 -0
- package/src/Logger.ts +321 -0
- package/src/Metric.ts +657 -0
- package/src/MetricBoundaries.ts +70 -0
- package/src/MetricHook.ts +139 -0
- package/src/MetricKey.ts +227 -0
- package/src/MetricKeyType.ts +257 -0
- package/src/MetricLabel.ts +47 -0
- package/src/MetricPair.ts +70 -0
- package/src/MetricPolling.ts +136 -0
- package/src/MetricRegistry.ts +47 -0
- package/src/MetricState.ts +256 -0
- package/src/MutableHashMap.ts +187 -0
- package/src/MutableHashSet.ts +118 -0
- package/src/MutableList.ts +289 -0
- package/src/MutableQueue.ts +227 -0
- package/src/MutableRef.ts +204 -0
- package/src/NonEmptyIterable.ts +30 -0
- package/src/Number.ts +406 -0
- package/src/Option.ts +1307 -0
- package/src/Order.ts +328 -0
- package/src/Ordering.ts +112 -0
- package/src/Pipeable.ts +318 -0
- package/src/Pool.ts +148 -0
- package/src/Predicate.ts +704 -0
- package/src/PubSub.ts +175 -0
- package/src/Queue.ts +575 -0
- package/src/Random.ts +115 -0
- package/src/ReadonlyArray.ts +2017 -0
- package/src/ReadonlyRecord.ts +641 -0
- package/src/RedBlackTree.ts +415 -0
- package/src/Ref.ts +159 -0
- package/src/Reloadable.ts +136 -0
- package/src/Request.ts +285 -0
- package/src/RequestBlock.ts +157 -0
- package/src/RequestResolver.ts +305 -0
- package/src/Resource.ts +97 -0
- package/src/Runtime.ts +216 -0
- package/src/RuntimeFlags.ts +336 -0
- package/src/RuntimeFlagsPatch.ts +183 -0
- package/src/STM.ts +2076 -0
- package/src/Schedule.ts +1396 -0
- package/src/ScheduleDecision.ts +62 -0
- package/src/ScheduleInterval.ts +151 -0
- package/src/ScheduleIntervals.ts +122 -0
- package/src/Scheduler.ts +359 -0
- package/src/Scope.ts +171 -0
- package/src/ScopedCache.ts +148 -0
- package/src/ScopedRef.ts +95 -0
- package/src/Sink.ts +1431 -0
- package/src/SortedMap.ts +229 -0
- package/src/SortedSet.ts +385 -0
- package/src/Stream.ts +4540 -0
- package/src/StreamEmit.ts +83 -0
- package/src/StreamHaltStrategy.ts +111 -0
- package/src/Streamable.ts +42 -0
- package/src/String.ts +682 -0
- package/src/Struct.ts +151 -0
- package/src/SubscriptionRef.ts +273 -0
- package/src/Supervisor.ts +239 -0
- package/src/Symbol.ts +28 -0
- package/src/SynchronizedRef.ts +249 -0
- package/src/TArray.ts +494 -0
- package/src/TDeferred.ts +99 -0
- package/src/TMap.ts +510 -0
- package/src/TPriorityQueue.ts +223 -0
- package/src/TPubSub.ts +187 -0
- package/src/TQueue.ts +431 -0
- package/src/TRandom.ts +129 -0
- package/src/TReentrantLock.ts +224 -0
- package/src/TRef.ts +176 -0
- package/src/TSemaphore.ts +129 -0
- package/src/TSet.ts +349 -0
- package/src/Take.ts +257 -0
- package/src/TestAnnotation.ts +166 -0
- package/src/TestAnnotationMap.ts +124 -0
- package/src/TestAnnotations.ts +113 -0
- package/src/TestClock.ts +552 -0
- package/src/TestConfig.ts +49 -0
- package/src/TestContext.ts +35 -0
- package/src/TestLive.ts +55 -0
- package/src/TestServices.ts +392 -0
- package/src/TestSized.ts +55 -0
- package/src/Tracer.ts +119 -0
- package/src/Tuple.ts +204 -0
- package/src/Types.ts +123 -0
- package/src/Unify.ts +118 -0
- package/src/Utils.ts +699 -0
- package/src/index.ts +840 -0
- package/src/internal/Common.ts +56 -0
- package/src/internal/Context.ts +252 -0
- package/src/internal/Data.ts +55 -0
- package/src/internal/Differ/ChunkPatch.ts +209 -0
- package/src/internal/Differ/ContextPatch.ts +229 -0
- package/src/internal/Differ/HashMapPatch.ts +217 -0
- package/src/internal/Differ/HashSetPatch.ts +174 -0
- package/src/internal/Differ/OrPatch.ts +296 -0
- package/src/internal/Differ.ts +184 -0
- package/src/internal/Effectable.ts +92 -0
- package/src/internal/Either.ts +107 -0
- package/src/internal/Encoding/Base64.ts +282 -0
- package/src/internal/Encoding/Base64Url.ts +28 -0
- package/src/internal/Encoding/Common.ts +24 -0
- package/src/internal/Encoding/Hex.ts +315 -0
- package/src/internal/HashMap/array.ts +49 -0
- package/src/internal/HashMap/bitwise.ts +32 -0
- package/src/internal/HashMap/config.ts +14 -0
- package/src/internal/HashMap/keySet.ts +8 -0
- package/src/internal/HashMap/node.ts +390 -0
- package/src/internal/HashMap.ts +533 -0
- package/src/internal/HashSet.ts +319 -0
- package/src/internal/Iterable.ts +54 -0
- package/src/internal/Option.ts +79 -0
- package/src/internal/ReadonlyArray.ts +8 -0
- package/src/internal/RedBlackTree/iterator.ts +207 -0
- package/src/internal/RedBlackTree/node.ts +48 -0
- package/src/internal/RedBlackTree.ts +1195 -0
- package/src/internal/Stack.ts +4 -0
- package/src/internal/blockedRequests.ts +512 -0
- package/src/internal/cache.ts +714 -0
- package/src/internal/cause.ts +1205 -0
- package/src/internal/channel/channelExecutor.ts +1193 -0
- package/src/internal/channel/channelState.ts +132 -0
- package/src/internal/channel/childExecutorDecision.ts +95 -0
- package/src/internal/channel/continuation.ts +171 -0
- package/src/internal/channel/mergeDecision.ts +115 -0
- package/src/internal/channel/mergeState.ts +120 -0
- package/src/internal/channel/mergeStrategy.ts +72 -0
- package/src/internal/channel/singleProducerAsyncInput.ts +261 -0
- package/src/internal/channel/subexecutor.ts +229 -0
- package/src/internal/channel/upstreamPullRequest.ts +83 -0
- package/src/internal/channel/upstreamPullStrategy.ts +86 -0
- package/src/internal/channel.ts +2516 -0
- package/src/internal/clock.ts +97 -0
- package/src/internal/completedRequestMap.ts +9 -0
- package/src/internal/concurrency.ts +83 -0
- package/src/internal/config.ts +598 -0
- package/src/internal/configError.ts +291 -0
- package/src/internal/configProvider/pathPatch.ts +97 -0
- package/src/internal/configProvider.ts +692 -0
- package/src/internal/configSecret.ts +71 -0
- package/src/internal/console.ts +136 -0
- package/src/internal/core-effect.ts +2146 -0
- package/src/internal/core-stream.ts +999 -0
- package/src/internal/core.ts +2765 -0
- package/src/internal/dataSource.ts +258 -0
- package/src/internal/defaultServices/console.ts +97 -0
- package/src/internal/defaultServices.ts +140 -0
- package/src/internal/deferred.ts +44 -0
- package/src/internal/effect/circular.ts +664 -0
- package/src/internal/executionStrategy.ts +72 -0
- package/src/internal/fiber.ts +350 -0
- package/src/internal/fiberId.ts +270 -0
- package/src/internal/fiberMessage.ts +85 -0
- package/src/internal/fiberRefs/patch.ts +144 -0
- package/src/internal/fiberRefs.ts +239 -0
- package/src/internal/fiberRuntime.ts +3477 -0
- package/src/internal/fiberScope.ts +72 -0
- package/src/internal/fiberStatus.ts +118 -0
- package/src/internal/groupBy.ts +516 -0
- package/src/internal/keyedPool.ts +240 -0
- package/src/internal/layer/circular.ts +203 -0
- package/src/internal/layer.ts +1230 -0
- package/src/internal/logSpan.ts +15 -0
- package/src/internal/logger-circular.ts +24 -0
- package/src/internal/logger.ts +307 -0
- package/src/internal/metric/boundaries.ts +72 -0
- package/src/internal/metric/hook.ts +459 -0
- package/src/internal/metric/key.ts +173 -0
- package/src/internal/metric/keyType.ts +263 -0
- package/src/internal/metric/label.ts +44 -0
- package/src/internal/metric/pair.ts +48 -0
- package/src/internal/metric/polling.ts +143 -0
- package/src/internal/metric/registry.ts +188 -0
- package/src/internal/metric/state.ts +286 -0
- package/src/internal/metric.ts +522 -0
- package/src/internal/opCodes/cause.ts +35 -0
- package/src/internal/opCodes/channel.ts +83 -0
- package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
- package/src/internal/opCodes/channelMergeDecision.ts +11 -0
- package/src/internal/opCodes/channelMergeState.ts +17 -0
- package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
- package/src/internal/opCodes/channelState.ts +23 -0
- package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
- package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
- package/src/internal/opCodes/config.ts +65 -0
- package/src/internal/opCodes/configError.ts +35 -0
- package/src/internal/opCodes/continuation.ts +11 -0
- package/src/internal/opCodes/deferred.ts +11 -0
- package/src/internal/opCodes/effect.ts +83 -0
- package/src/internal/opCodes/layer.ts +53 -0
- package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
- package/src/internal/pool.ts +499 -0
- package/src/internal/pubsub.ts +1557 -0
- package/src/internal/query.ts +199 -0
- package/src/internal/queue.ts +729 -0
- package/src/internal/random.ts +88 -0
- package/src/internal/ref.ts +164 -0
- package/src/internal/reloadable.ts +164 -0
- package/src/internal/request.ts +137 -0
- package/src/internal/resource.ts +64 -0
- package/src/internal/ringBuffer.ts +68 -0
- package/src/internal/runtime.ts +348 -0
- package/src/internal/runtimeFlags.ts +176 -0
- package/src/internal/runtimeFlagsPatch.ts +103 -0
- package/src/internal/schedule/decision.ts +47 -0
- package/src/internal/schedule/interval.ts +101 -0
- package/src/internal/schedule/intervals.ts +179 -0
- package/src/internal/schedule.ts +2096 -0
- package/src/internal/scopedCache.ts +634 -0
- package/src/internal/scopedRef.ts +133 -0
- package/src/internal/singleShotGen.ts +35 -0
- package/src/internal/sink.ts +2118 -0
- package/src/internal/stm/core.ts +804 -0
- package/src/internal/stm/opCodes/stm.ts +71 -0
- package/src/internal/stm/opCodes/stmState.ts +17 -0
- package/src/internal/stm/opCodes/strategy.ts +17 -0
- package/src/internal/stm/opCodes/tExit.ts +29 -0
- package/src/internal/stm/opCodes/tryCommit.ts +11 -0
- package/src/internal/stm/stm/entry.ts +59 -0
- package/src/internal/stm/stm/journal.ts +123 -0
- package/src/internal/stm/stm/opCodes/stm.ts +71 -0
- package/src/internal/stm/stm/opCodes/stmState.ts +17 -0
- package/src/internal/stm/stm/opCodes/strategy.ts +17 -0
- package/src/internal/stm/stm/opCodes/tExit.ts +29 -0
- package/src/internal/stm/stm/opCodes/tryCommit.ts +11 -0
- package/src/internal/stm/stm/stmState.ts +130 -0
- package/src/internal/stm/stm/tExit.ts +180 -0
- package/src/internal/stm/stm/tryCommit.ts +34 -0
- package/src/internal/stm/stm/txnId.ts +14 -0
- package/src/internal/stm/stm/versioned.ts +4 -0
- package/src/internal/stm/stm.ts +1491 -0
- package/src/internal/stm/tArray.ts +550 -0
- package/src/internal/stm/tDeferred.ts +79 -0
- package/src/internal/stm/tMap.ts +824 -0
- package/src/internal/stm/tPriorityQueue.ts +259 -0
- package/src/internal/stm/tPubSub.ts +542 -0
- package/src/internal/stm/tQueue.ts +400 -0
- package/src/internal/stm/tRandom.ts +140 -0
- package/src/internal/stm/tReentrantLock.ts +352 -0
- package/src/internal/stm/tRef.ts +190 -0
- package/src/internal/stm/tSemaphore.ts +113 -0
- package/src/internal/stm/tSet.ts +237 -0
- package/src/internal/stream/debounceState.ts +57 -0
- package/src/internal/stream/emit.ts +46 -0
- package/src/internal/stream/haltStrategy.ts +85 -0
- package/src/internal/stream/handoff.ts +185 -0
- package/src/internal/stream/handoffSignal.ts +59 -0
- package/src/internal/stream/pull.ts +35 -0
- package/src/internal/stream/sinkEndReason.ts +30 -0
- package/src/internal/stream/zipAllState.ts +88 -0
- package/src/internal/stream/zipChunksState.ts +56 -0
- package/src/internal/stream.ts +8089 -0
- package/src/internal/string-utils.ts +107 -0
- package/src/internal/subscriptionRef.ts +133 -0
- package/src/internal/supervisor/patch.ts +190 -0
- package/src/internal/supervisor.ts +301 -0
- package/src/internal/synchronizedRef.ts +115 -0
- package/src/internal/take.ts +198 -0
- package/src/internal/testing/sleep.ts +27 -0
- package/src/internal/testing/suspendedWarningData.ts +85 -0
- package/src/internal/testing/warningData.ts +94 -0
- package/src/internal/timeout.ts +23 -0
- package/src/internal/tracer.ts +74 -0
- package/Error/dist/effect-Error.cjs.d.mts +0 -2
- package/Error/dist/effect-Error.cjs.d.mts.map +0 -1
- package/Error/dist/effect-Error.cjs.d.ts +0 -2
- package/Error/dist/effect-Error.cjs.d.ts.map +0 -1
- package/Error/dist/effect-Error.cjs.dev.js +0 -140
- package/Error/dist/effect-Error.cjs.js +0 -7
- package/Error/dist/effect-Error.cjs.mjs +0 -4
- package/Error/dist/effect-Error.cjs.prod.js +0 -140
- package/Error/dist/effect-Error.esm.js +0 -47
- package/Error/package.json +0 -4
- package/Hub/dist/effect-Hub.cjs.d.mts +0 -2
- package/Hub/dist/effect-Hub.cjs.d.mts.map +0 -1
- package/Hub/dist/effect-Hub.cjs.d.ts +0 -2
- package/Hub/dist/effect-Hub.cjs.d.ts.map +0 -1
- package/Hub/dist/effect-Hub.cjs.js +0 -7
- package/Hub/package.json +0 -4
- package/THub/dist/effect-THub.cjs.d.mts +0 -2
- package/THub/dist/effect-THub.cjs.d.mts.map +0 -1
- package/THub/dist/effect-THub.cjs.d.ts +0 -2
- package/THub/dist/effect-THub.cjs.d.ts.map +0 -1
- package/THub/dist/effect-THub.cjs.js +0 -7
- package/THub/dist/effect-THub.esm.js +0 -157
- package/THub/package.json +0 -4
- package/dist/declarations/src/Error.d.ts +0 -37
- package/dist/declarations/src/Error.d.ts.map +0 -1
- package/dist/declarations/src/Hub.d.ts.map +0 -1
- package/dist/declarations/src/THub.d.ts +0 -146
- package/dist/declarations/src/THub.d.ts.map +0 -1
- package/dist/scopedRef-1c2c9acf.cjs.prod.js +0 -55
- package/dist/scopedRef-ab4c58b0.cjs.dev.js +0 -55
- /package/dist/{FiberId-e594f6e8.cjs.prod.js → FiberId-1d7ac632.cjs.prod.js} +0 -0
- /package/dist/{FiberId-557db880.cjs.dev.js → FiberId-d88ddce6.cjs.dev.js} +0 -0
- /package/dist/{RuntimeFlagsPatch-ea268c50.cjs.dev.js → RuntimeFlagsPatch-69102b03.cjs.dev.js} +0 -0
- /package/dist/{RuntimeFlagsPatch-e2769b87.cjs.prod.js → RuntimeFlagsPatch-866fa259.cjs.prod.js} +0 -0
- /package/dist/{boundaries-20cfad9d.cjs.prod.js → boundaries-9af538e3.cjs.prod.js} +0 -0
- /package/dist/{boundaries-3810d885.cjs.dev.js → boundaries-f212e414.cjs.dev.js} +0 -0
- /package/dist/{configError-33e55472.cjs.prod.js → configError-b43723af.cjs.prod.js} +0 -0
- /package/dist/{configError-240e9b61.cjs.dev.js → configError-d5efe9c0.cjs.dev.js} +0 -0
- /package/dist/{configSecret-e34c1b14.cjs.dev.js → configSecret-3e8ae336.cjs.dev.js} +0 -0
- /package/dist/{configSecret-d1caca55.cjs.prod.js → configSecret-e2faa181.cjs.prod.js} +0 -0
- /package/dist/{take-2af6e92a.cjs.prod.js → take-85daaf79.cjs.prod.js} +0 -0
- /package/dist/{take-df9480a8.cjs.dev.js → take-f9ef9e2e.cjs.dev.js} +0 -0
|
@@ -0,0 +1,3477 @@
|
|
|
1
|
+
import * as Boolean from "../Boolean"
|
|
2
|
+
import type * as Cause from "../Cause"
|
|
3
|
+
import * as Chunk from "../Chunk"
|
|
4
|
+
import type * as Clock from "../Clock"
|
|
5
|
+
import type { ConfigProvider } from "../ConfigProvider"
|
|
6
|
+
import * as Context from "../Context"
|
|
7
|
+
import * as Deferred from "../Deferred"
|
|
8
|
+
import type * as Effect from "../Effect"
|
|
9
|
+
import type * as Either from "../Either"
|
|
10
|
+
import * as ExecutionStrategy from "../ExecutionStrategy"
|
|
11
|
+
import type * as Exit from "../Exit"
|
|
12
|
+
import type * as Fiber from "../Fiber"
|
|
13
|
+
import * as FiberId from "../FiberId"
|
|
14
|
+
import type * as FiberRef from "../FiberRef"
|
|
15
|
+
import * as FiberRefs from "../FiberRefs"
|
|
16
|
+
import * as FiberRefsPatch from "../FiberRefsPatch"
|
|
17
|
+
import * as FiberStatus from "../FiberStatus"
|
|
18
|
+
import type { LazyArg } from "../Function"
|
|
19
|
+
import { dual, identity, pipe } from "../Function"
|
|
20
|
+
import * as HashSet from "../HashSet"
|
|
21
|
+
import * as _RequestBlock from "../internal/blockedRequests"
|
|
22
|
+
import * as internalCause from "../internal/cause"
|
|
23
|
+
import * as clock from "../internal/clock"
|
|
24
|
+
import { currentRequestMap } from "../internal/completedRequestMap"
|
|
25
|
+
import * as concurrency from "../internal/concurrency"
|
|
26
|
+
import { configProviderTag } from "../internal/configProvider"
|
|
27
|
+
import * as core from "../internal/core"
|
|
28
|
+
import * as internalEffect from "../internal/core-effect"
|
|
29
|
+
import * as defaultServices from "../internal/defaultServices"
|
|
30
|
+
import { consoleTag } from "../internal/defaultServices/console"
|
|
31
|
+
import * as executionStrategy from "../internal/executionStrategy"
|
|
32
|
+
import * as internalFiber from "../internal/fiber"
|
|
33
|
+
import * as FiberMessage from "../internal/fiberMessage"
|
|
34
|
+
import * as fiberRefs from "../internal/fiberRefs"
|
|
35
|
+
import * as fiberScope from "../internal/fiberScope"
|
|
36
|
+
import * as internalLogger from "../internal/logger"
|
|
37
|
+
import * as metric from "../internal/metric"
|
|
38
|
+
import * as metricBoundaries from "../internal/metric/boundaries"
|
|
39
|
+
import * as metricLabel from "../internal/metric/label"
|
|
40
|
+
import * as OpCodes from "../internal/opCodes/effect"
|
|
41
|
+
import { complete } from "../internal/request"
|
|
42
|
+
import * as _runtimeFlags from "../internal/runtimeFlags"
|
|
43
|
+
import { OpSupervision } from "../internal/runtimeFlags"
|
|
44
|
+
import * as supervisor from "../internal/supervisor"
|
|
45
|
+
import * as SupervisorPatch from "../internal/supervisor/patch"
|
|
46
|
+
import * as tracer from "../internal/tracer"
|
|
47
|
+
import * as List from "../List"
|
|
48
|
+
import type { Logger } from "../Logger"
|
|
49
|
+
import * as LogLevel from "../LogLevel"
|
|
50
|
+
import type * as MetricLabel from "../MetricLabel"
|
|
51
|
+
import * as MRef from "../MutableRef"
|
|
52
|
+
import * as Option from "../Option"
|
|
53
|
+
import { pipeArguments } from "../Pipeable"
|
|
54
|
+
import * as Predicate from "../Predicate"
|
|
55
|
+
import * as RA from "../ReadonlyArray"
|
|
56
|
+
import * as Ref from "../Ref"
|
|
57
|
+
import type { Entry, Request } from "../Request"
|
|
58
|
+
import type * as RequestBlock from "../RequestBlock"
|
|
59
|
+
import type * as RuntimeFlags from "../RuntimeFlags"
|
|
60
|
+
import * as RuntimeFlagsPatch from "../RuntimeFlagsPatch"
|
|
61
|
+
import { currentScheduler, type Scheduler } from "../Scheduler"
|
|
62
|
+
import type * as Scope from "../Scope"
|
|
63
|
+
import type * as Supervisor from "../Supervisor"
|
|
64
|
+
import type * as Tracer from "../Tracer"
|
|
65
|
+
import type { Concurrency } from "../Types"
|
|
66
|
+
|
|
67
|
+
/** @internal */
|
|
68
|
+
export const fiberStarted = metric.counter("effect_fiber_started")
|
|
69
|
+
/** @internal */
|
|
70
|
+
export const fiberActive = metric.counter("effect_fiber_active")
|
|
71
|
+
/** @internal */
|
|
72
|
+
export const fiberSuccesses = metric.counter("effect_fiber_successes")
|
|
73
|
+
/** @internal */
|
|
74
|
+
export const fiberFailures = metric.counter("effect_fiber_failures")
|
|
75
|
+
/** @internal */
|
|
76
|
+
export const fiberLifetimes = metric.tagged(
|
|
77
|
+
metric.histogram(
|
|
78
|
+
"effect_fiber_lifetimes",
|
|
79
|
+
metricBoundaries.exponential({
|
|
80
|
+
start: 1.0,
|
|
81
|
+
factor: 1.3,
|
|
82
|
+
count: 100
|
|
83
|
+
})
|
|
84
|
+
),
|
|
85
|
+
"time_unit",
|
|
86
|
+
"milliseconds"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
/** @internal */
|
|
90
|
+
type EvaluationSignal =
|
|
91
|
+
| EvaluationSignalContinue
|
|
92
|
+
| EvaluationSignalDone
|
|
93
|
+
| EvaluationSignalYieldNow
|
|
94
|
+
|
|
95
|
+
/** @internal */
|
|
96
|
+
const EvaluationSignalContinue = "Continue" as const
|
|
97
|
+
|
|
98
|
+
/** @internal */
|
|
99
|
+
type EvaluationSignalContinue = typeof EvaluationSignalContinue
|
|
100
|
+
|
|
101
|
+
/** @internal */
|
|
102
|
+
const EvaluationSignalDone = "Done" as const
|
|
103
|
+
|
|
104
|
+
/** @internal */
|
|
105
|
+
type EvaluationSignalDone = typeof EvaluationSignalDone
|
|
106
|
+
|
|
107
|
+
/** @internal */
|
|
108
|
+
const EvaluationSignalYieldNow = "Yield" as const
|
|
109
|
+
|
|
110
|
+
/** @internal */
|
|
111
|
+
type EvaluationSignalYieldNow = typeof EvaluationSignalYieldNow
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
export const runtimeFiberVariance = {
|
|
115
|
+
_E: (_: never) => _,
|
|
116
|
+
_A: (_: never) => _
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const absurd = (_: never): never => {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`BUG: FiberRuntime - ${JSON.stringify(_)} - please report an issue at https://github.com/Effect-TS/io/issues`
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const contOpSuccess = {
|
|
126
|
+
[OpCodes.OP_ON_SUCCESS]: (
|
|
127
|
+
_: FiberRuntime<any, any>,
|
|
128
|
+
cont: core.OnSuccess,
|
|
129
|
+
value: unknown
|
|
130
|
+
) => {
|
|
131
|
+
return cont.i1(value)
|
|
132
|
+
},
|
|
133
|
+
["OnStep"]: (
|
|
134
|
+
_: FiberRuntime<any, any>,
|
|
135
|
+
cont: core.OnStep,
|
|
136
|
+
value: unknown
|
|
137
|
+
) => {
|
|
138
|
+
return cont.i1(core.exitSucceed(value))
|
|
139
|
+
},
|
|
140
|
+
[OpCodes.OP_ON_SUCCESS_AND_FAILURE]: (
|
|
141
|
+
_: FiberRuntime<any, any>,
|
|
142
|
+
cont: core.OnSuccessAndFailure,
|
|
143
|
+
value: unknown
|
|
144
|
+
) => {
|
|
145
|
+
return cont.i2(value)
|
|
146
|
+
},
|
|
147
|
+
[OpCodes.OP_REVERT_FLAGS]: (
|
|
148
|
+
self: FiberRuntime<any, any>,
|
|
149
|
+
cont: core.RevertFlags,
|
|
150
|
+
value: unknown
|
|
151
|
+
) => {
|
|
152
|
+
self.patchRuntimeFlags(self._runtimeFlags, cont.patch)
|
|
153
|
+
if (_runtimeFlags.interruptible(self._runtimeFlags) && self.isInterrupted()) {
|
|
154
|
+
return core.exitFailCause(self.getInterruptedCause())
|
|
155
|
+
} else {
|
|
156
|
+
return core.exitSucceed(value)
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[OpCodes.OP_WHILE]: (
|
|
160
|
+
self: FiberRuntime<any, any>,
|
|
161
|
+
cont: core.While,
|
|
162
|
+
value: unknown
|
|
163
|
+
) => {
|
|
164
|
+
cont.i2(value)
|
|
165
|
+
if (cont.i0()) {
|
|
166
|
+
self.pushStack(cont)
|
|
167
|
+
return cont.i1()
|
|
168
|
+
} else {
|
|
169
|
+
return core.unit
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const drainQueueWhileRunningTable = {
|
|
175
|
+
[FiberMessage.OP_INTERRUPT_SIGNAL]: (
|
|
176
|
+
self: FiberRuntime<any, any>,
|
|
177
|
+
runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
178
|
+
cur: Effect.Effect<any, any, any>,
|
|
179
|
+
message: FiberMessage.FiberMessage & { _tag: FiberMessage.OP_INTERRUPT_SIGNAL }
|
|
180
|
+
) => {
|
|
181
|
+
self.processNewInterruptSignal(message.cause)
|
|
182
|
+
return _runtimeFlags.interruptible(runtimeFlags) ? core.exitFailCause(message.cause) : cur
|
|
183
|
+
},
|
|
184
|
+
[FiberMessage.OP_RESUME]: (
|
|
185
|
+
_self: FiberRuntime<any, any>,
|
|
186
|
+
_runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
187
|
+
_cur: Effect.Effect<any, any, any>,
|
|
188
|
+
_message: FiberMessage.FiberMessage
|
|
189
|
+
) => {
|
|
190
|
+
throw new Error("It is illegal to have multiple concurrent run loops in a single fiber")
|
|
191
|
+
},
|
|
192
|
+
[FiberMessage.OP_STATEFUL]: (
|
|
193
|
+
self: FiberRuntime<any, any>,
|
|
194
|
+
runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
195
|
+
cur: Effect.Effect<any, any, any>,
|
|
196
|
+
message: FiberMessage.FiberMessage & { _tag: FiberMessage.OP_STATEFUL }
|
|
197
|
+
) => {
|
|
198
|
+
message.onFiber(self, FiberStatus.running(runtimeFlags))
|
|
199
|
+
return cur
|
|
200
|
+
},
|
|
201
|
+
[FiberMessage.OP_YIELD_NOW]: (
|
|
202
|
+
_self: FiberRuntime<any, any>,
|
|
203
|
+
_runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
204
|
+
cur: Effect.Effect<any, any, any>,
|
|
205
|
+
_message: FiberMessage.FiberMessage & { _tag: FiberMessage.OP_YIELD_NOW }
|
|
206
|
+
) => {
|
|
207
|
+
return core.flatMap(core.yieldNow(), () => cur)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Executes all requests, submitting requests to each data source in parallel.
|
|
213
|
+
*/
|
|
214
|
+
const runBlockedRequests = <R>(self: RequestBlock.RequestBlock<R>) =>
|
|
215
|
+
core.forEachSequentialDiscard(
|
|
216
|
+
_RequestBlock.flatten(self),
|
|
217
|
+
(requestsByRequestResolver) =>
|
|
218
|
+
forEachParUnboundedDiscard(
|
|
219
|
+
_RequestBlock.sequentialCollectionToChunk(requestsByRequestResolver),
|
|
220
|
+
([dataSource, sequential]) => {
|
|
221
|
+
const map = new Map<Request<any, any>, Entry<any>>()
|
|
222
|
+
for (const block of sequential) {
|
|
223
|
+
for (const entry of block) {
|
|
224
|
+
map.set(entry.request as Request<any, any>, entry)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return core.fiberRefLocally(
|
|
228
|
+
invokeWithInterrupt(dataSource.runAll(sequential), sequential.flat()),
|
|
229
|
+
currentRequestMap,
|
|
230
|
+
map
|
|
231
|
+
)
|
|
232
|
+
},
|
|
233
|
+
false
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
/** @internal */
|
|
238
|
+
export class FiberRuntime<E, A> implements Fiber.RuntimeFiber<E, A> {
|
|
239
|
+
readonly [internalFiber.FiberTypeId] = internalFiber.fiberVariance
|
|
240
|
+
|
|
241
|
+
readonly [internalFiber.RuntimeFiberTypeId] = runtimeFiberVariance
|
|
242
|
+
|
|
243
|
+
pipe() {
|
|
244
|
+
return pipeArguments(this, arguments)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private _fiberRefs: FiberRefs.FiberRefs
|
|
248
|
+
private _fiberId: FiberId.Runtime
|
|
249
|
+
public _runtimeFlags: RuntimeFlags.RuntimeFlags
|
|
250
|
+
|
|
251
|
+
private _queue = new Array<FiberMessage.FiberMessage>()
|
|
252
|
+
private _children: Set<FiberRuntime<any, any>> | null = null
|
|
253
|
+
private _observers = new Array<(exit: Exit.Exit<E, A>) => void>()
|
|
254
|
+
private _running = false
|
|
255
|
+
private _stack: Array<core.Continuation> = []
|
|
256
|
+
private _asyncInterruptor: ((effect: Effect.Effect<any, any, any>) => any) | null = null
|
|
257
|
+
private _asyncBlockingOn: FiberId.FiberId | null = null
|
|
258
|
+
private _exitValue: Exit.Exit<E, A> | null = null
|
|
259
|
+
private _steps: Array<boolean> = [false]
|
|
260
|
+
public _supervisor: Supervisor.Supervisor<any>
|
|
261
|
+
public _scheduler: Scheduler
|
|
262
|
+
private _tracer: Tracer.Tracer
|
|
263
|
+
public currentOpCount: number = 0
|
|
264
|
+
private isYielding = false
|
|
265
|
+
|
|
266
|
+
constructor(
|
|
267
|
+
fiberId: FiberId.Runtime,
|
|
268
|
+
fiberRefs0: FiberRefs.FiberRefs,
|
|
269
|
+
runtimeFlags0: RuntimeFlags.RuntimeFlags
|
|
270
|
+
) {
|
|
271
|
+
this._runtimeFlags = runtimeFlags0
|
|
272
|
+
this._fiberId = fiberId
|
|
273
|
+
this._fiberRefs = fiberRefs0
|
|
274
|
+
this._supervisor = this.getFiberRef(currentSupervisor)
|
|
275
|
+
this._scheduler = this.getFiberRef(currentScheduler)
|
|
276
|
+
if (_runtimeFlags.runtimeMetrics(runtimeFlags0)) {
|
|
277
|
+
const tags = this.getFiberRef(core.currentMetricLabels)
|
|
278
|
+
fiberStarted.unsafeUpdate(1, tags)
|
|
279
|
+
fiberActive.unsafeUpdate(1, tags)
|
|
280
|
+
}
|
|
281
|
+
this._tracer = Context.get(this.getFiberRef(defaultServices.currentServices), tracer.tracerTag)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The identity of the fiber.
|
|
286
|
+
*/
|
|
287
|
+
id(): FiberId.Runtime {
|
|
288
|
+
return this._fiberId
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Begins execution of the effect associated with this fiber on in the
|
|
293
|
+
* background. This can be called to "kick off" execution of a fiber after
|
|
294
|
+
* it has been created.
|
|
295
|
+
*/
|
|
296
|
+
resume<E, A>(effect: Effect.Effect<any, E, A>): void {
|
|
297
|
+
this.tell(FiberMessage.resume(effect))
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The status of the fiber.
|
|
302
|
+
*/
|
|
303
|
+
status(): Effect.Effect<never, never, FiberStatus.FiberStatus> {
|
|
304
|
+
return this.ask((_, status) => status)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Gets the fiber runtime flags.
|
|
309
|
+
*/
|
|
310
|
+
runtimeFlags(): Effect.Effect<never, never, RuntimeFlags.RuntimeFlags> {
|
|
311
|
+
return this.ask((state, status) => {
|
|
312
|
+
if (FiberStatus.isDone(status)) {
|
|
313
|
+
return state._runtimeFlags
|
|
314
|
+
}
|
|
315
|
+
return status.runtimeFlags
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Returns the current `FiberScope` for the fiber.
|
|
321
|
+
*/
|
|
322
|
+
scope(): fiberScope.FiberScope {
|
|
323
|
+
return fiberScope.unsafeMake(this)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Retrieves the immediate children of the fiber.
|
|
328
|
+
*/
|
|
329
|
+
children(): Effect.Effect<never, never, Array<Fiber.RuntimeFiber<any, any>>> {
|
|
330
|
+
return this.ask((fiber) => Array.from(fiber.getChildren()))
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Gets the fiber's set of children.
|
|
335
|
+
*/
|
|
336
|
+
getChildren(): Set<FiberRuntime<any, any>> {
|
|
337
|
+
if (this._children === null) {
|
|
338
|
+
this._children = new Set()
|
|
339
|
+
}
|
|
340
|
+
return this._children
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Retrieves the interrupted cause of the fiber, which will be `Cause.empty`
|
|
345
|
+
* if the fiber has not been interrupted.
|
|
346
|
+
*
|
|
347
|
+
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked
|
|
348
|
+
* on this fiber, then values derived from the fiber's state (including the
|
|
349
|
+
* log annotations and log level) may not be up-to-date.
|
|
350
|
+
*/
|
|
351
|
+
getInterruptedCause() {
|
|
352
|
+
return this.getFiberRef(core.currentInterruptedCause)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Retrieves the whole set of fiber refs.
|
|
357
|
+
*/
|
|
358
|
+
fiberRefs(): Effect.Effect<never, never, FiberRefs.FiberRefs> {
|
|
359
|
+
return this.ask((fiber) => fiber.getFiberRefs())
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Returns an effect that will contain information computed from the fiber
|
|
364
|
+
* state and status while running on the fiber.
|
|
365
|
+
*
|
|
366
|
+
* This allows the outside world to interact safely with mutable fiber state
|
|
367
|
+
* without locks or immutable data.
|
|
368
|
+
*/
|
|
369
|
+
ask<Z>(
|
|
370
|
+
f: (runtime: FiberRuntime<any, any>, status: FiberStatus.FiberStatus) => Z
|
|
371
|
+
): Effect.Effect<never, never, Z> {
|
|
372
|
+
return core.suspend(() => {
|
|
373
|
+
const deferred = core.deferredUnsafeMake<never, Z>(this._fiberId)
|
|
374
|
+
this.tell(
|
|
375
|
+
FiberMessage.stateful((fiber, status) => {
|
|
376
|
+
core.deferredUnsafeDone(deferred, core.sync(() => f(fiber, status)))
|
|
377
|
+
})
|
|
378
|
+
)
|
|
379
|
+
return core.deferredAwait(deferred)
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Adds a message to be processed by the fiber on the fiber.
|
|
385
|
+
*/
|
|
386
|
+
tell(message: FiberMessage.FiberMessage): void {
|
|
387
|
+
this._queue.push(message)
|
|
388
|
+
if (!this._running) {
|
|
389
|
+
this._running = true
|
|
390
|
+
this.drainQueueLaterOnExecutor()
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
await(): Effect.Effect<never, never, Exit.Exit<E, A>> {
|
|
395
|
+
return core.async<never, never, Exit.Exit<E, A>>((resume) => {
|
|
396
|
+
const cb = (exit: Exit.Exit<E, A>) => resume(core.succeed(exit))
|
|
397
|
+
this.tell(
|
|
398
|
+
FiberMessage.stateful((fiber, _) => {
|
|
399
|
+
if (fiber._exitValue !== null) {
|
|
400
|
+
cb(this._exitValue!)
|
|
401
|
+
} else {
|
|
402
|
+
fiber.addObserver(cb)
|
|
403
|
+
}
|
|
404
|
+
})
|
|
405
|
+
)
|
|
406
|
+
return core.sync(() =>
|
|
407
|
+
this.tell(
|
|
408
|
+
FiberMessage.stateful((fiber, _) => {
|
|
409
|
+
fiber.removeObserver(cb)
|
|
410
|
+
})
|
|
411
|
+
)
|
|
412
|
+
)
|
|
413
|
+
}, this.id())
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
inheritAll(): Effect.Effect<never, never, void> {
|
|
417
|
+
return core.withFiberRuntime<never, never, void>((parentFiber, parentStatus) => {
|
|
418
|
+
const parentFiberId = parentFiber.id()
|
|
419
|
+
const parentFiberRefs = parentFiber.getFiberRefs()
|
|
420
|
+
const parentRuntimeFlags = parentStatus.runtimeFlags
|
|
421
|
+
const childFiberRefs = this.getFiberRefs()
|
|
422
|
+
const updatedFiberRefs = fiberRefs.joinAs(parentFiberRefs, parentFiberId, childFiberRefs)
|
|
423
|
+
|
|
424
|
+
parentFiber.setFiberRefs(updatedFiberRefs)
|
|
425
|
+
|
|
426
|
+
const updatedRuntimeFlags = parentFiber.getFiberRef(currentRuntimeFlags)
|
|
427
|
+
|
|
428
|
+
const patch = pipe(
|
|
429
|
+
_runtimeFlags.diff(parentRuntimeFlags, updatedRuntimeFlags),
|
|
430
|
+
// Do not inherit WindDown or Interruption!
|
|
431
|
+
RuntimeFlagsPatch.exclude(_runtimeFlags.Interruption),
|
|
432
|
+
RuntimeFlagsPatch.exclude(_runtimeFlags.WindDown)
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
return core.updateRuntimeFlags(patch)
|
|
436
|
+
})
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Tentatively observes the fiber, but returns immediately if it is not
|
|
441
|
+
* already done.
|
|
442
|
+
*/
|
|
443
|
+
poll(): Effect.Effect<never, never, Option.Option<Exit.Exit<E, A>>> {
|
|
444
|
+
return core.sync(() => Option.fromNullable(this._exitValue))
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Unsafely observes the fiber, but returns immediately if it is not
|
|
449
|
+
* already done.
|
|
450
|
+
*/
|
|
451
|
+
unsafePoll(): Exit.Exit<E, A> | null {
|
|
452
|
+
return this._exitValue
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* In the background, interrupts the fiber as if interrupted from the specified fiber.
|
|
457
|
+
*/
|
|
458
|
+
interruptAsFork(fiberId: FiberId.FiberId): Effect.Effect<never, never, void> {
|
|
459
|
+
return core.sync(() => this.tell(FiberMessage.interruptSignal(internalCause.interrupt(fiberId))))
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Adds an observer to the list of observers.
|
|
464
|
+
*
|
|
465
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
466
|
+
*/
|
|
467
|
+
addObserver(observer: (exit: Exit.Exit<E, A>) => void): void {
|
|
468
|
+
if (this._exitValue !== null) {
|
|
469
|
+
observer(this._exitValue!)
|
|
470
|
+
} else {
|
|
471
|
+
this._observers.push(observer)
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Removes the specified observer from the list of observers that will be
|
|
477
|
+
* notified when the fiber exits.
|
|
478
|
+
*
|
|
479
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
480
|
+
*/
|
|
481
|
+
removeObserver(observer: (exit: Exit.Exit<E, A>) => void): void {
|
|
482
|
+
this._observers = this._observers.filter((o) => o !== observer)
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Retrieves all fiber refs of the fiber.
|
|
486
|
+
*
|
|
487
|
+
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked
|
|
488
|
+
* on this fiber, then values derived from the fiber's state (including the
|
|
489
|
+
* log annotations and log level) may not be up-to-date.
|
|
490
|
+
*/
|
|
491
|
+
getFiberRefs(): FiberRefs.FiberRefs {
|
|
492
|
+
this.setFiberRef(currentRuntimeFlags, this._runtimeFlags)
|
|
493
|
+
return this._fiberRefs
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Deletes the specified fiber ref.
|
|
498
|
+
*
|
|
499
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
500
|
+
*/
|
|
501
|
+
unsafeDeleteFiberRef<X>(fiberRef: FiberRef.FiberRef<X>): void {
|
|
502
|
+
this._fiberRefs = fiberRefs.delete_(this._fiberRefs, fiberRef)
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Retrieves the state of the fiber ref, or else its initial value.
|
|
507
|
+
*
|
|
508
|
+
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked
|
|
509
|
+
* on this fiber, then values derived from the fiber's state (including the
|
|
510
|
+
* log annotations and log level) may not be up-to-date.
|
|
511
|
+
*/
|
|
512
|
+
getFiberRef<X>(fiberRef: FiberRef.FiberRef<X>): X {
|
|
513
|
+
if (this._fiberRefs.locals.has(fiberRef)) {
|
|
514
|
+
return this._fiberRefs.locals.get(fiberRef)![0][1] as X
|
|
515
|
+
}
|
|
516
|
+
return fiberRef.initial
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Sets the fiber ref to the specified value.
|
|
521
|
+
*
|
|
522
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
523
|
+
*/
|
|
524
|
+
setFiberRef<X>(fiberRef: FiberRef.FiberRef<X>, value: X): void {
|
|
525
|
+
this._fiberRefs = fiberRefs.updatedAs(this._fiberRefs, {
|
|
526
|
+
fiberId: this._fiberId,
|
|
527
|
+
fiberRef,
|
|
528
|
+
value
|
|
529
|
+
})
|
|
530
|
+
this.refreshRefCache()
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
refreshRefCache() {
|
|
534
|
+
this._tracer = Context.get(this.getFiberRef(defaultServices.currentServices), tracer.tracerTag)
|
|
535
|
+
this._supervisor = this.getFiberRef(currentSupervisor)
|
|
536
|
+
this._scheduler = this.getFiberRef(currentScheduler)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Wholesale replaces all fiber refs of this fiber.
|
|
541
|
+
*
|
|
542
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
543
|
+
*/
|
|
544
|
+
setFiberRefs(fiberRefs: FiberRefs.FiberRefs): void {
|
|
545
|
+
this._fiberRefs = fiberRefs
|
|
546
|
+
this.refreshRefCache()
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Adds a reference to the specified fiber inside the children set.
|
|
551
|
+
*
|
|
552
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
553
|
+
*/
|
|
554
|
+
addChild(child: FiberRuntime<any, any>) {
|
|
555
|
+
this.getChildren().add(child)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Removes a reference to the specified fiber inside the children set.
|
|
560
|
+
*
|
|
561
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
562
|
+
*/
|
|
563
|
+
removeChild(child: FiberRuntime<any, any>) {
|
|
564
|
+
this.getChildren().delete(child)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* On the current thread, executes all messages in the fiber's inbox. This
|
|
569
|
+
* method may return before all work is done, in the event the fiber executes
|
|
570
|
+
* an asynchronous operation.
|
|
571
|
+
*
|
|
572
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
573
|
+
*/
|
|
574
|
+
drainQueueOnCurrentThread() {
|
|
575
|
+
let recurse = true
|
|
576
|
+
while (recurse) {
|
|
577
|
+
let evaluationSignal: EvaluationSignal = EvaluationSignalContinue
|
|
578
|
+
const prev = (globalThis as any)[internalFiber.currentFiberURI]
|
|
579
|
+
;(globalThis as any)[internalFiber.currentFiberURI] = this
|
|
580
|
+
try {
|
|
581
|
+
while (evaluationSignal === EvaluationSignalContinue) {
|
|
582
|
+
evaluationSignal = this._queue.length === 0 ?
|
|
583
|
+
EvaluationSignalDone :
|
|
584
|
+
this.evaluateMessageWhileSuspended(this._queue.splice(0, 1)[0]!)
|
|
585
|
+
}
|
|
586
|
+
} finally {
|
|
587
|
+
this._running = false
|
|
588
|
+
;(globalThis as any)[internalFiber.currentFiberURI] = prev
|
|
589
|
+
}
|
|
590
|
+
// Maybe someone added something to the queue between us checking, and us
|
|
591
|
+
// giving up the drain. If so, we need to restart the draining, but only
|
|
592
|
+
// if we beat everyone else to the restart:
|
|
593
|
+
if (this._queue.length > 0 && !this._running) {
|
|
594
|
+
this._running = true
|
|
595
|
+
if (evaluationSignal === EvaluationSignalYieldNow) {
|
|
596
|
+
this.drainQueueLaterOnExecutor()
|
|
597
|
+
recurse = false
|
|
598
|
+
} else {
|
|
599
|
+
recurse = true
|
|
600
|
+
}
|
|
601
|
+
} else {
|
|
602
|
+
recurse = false
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Schedules the execution of all messages in the fiber's inbox.
|
|
609
|
+
*
|
|
610
|
+
* This method will return immediately after the scheduling
|
|
611
|
+
* operation is completed, but potentially before such messages have been
|
|
612
|
+
* executed.
|
|
613
|
+
*
|
|
614
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
615
|
+
*/
|
|
616
|
+
drainQueueLaterOnExecutor() {
|
|
617
|
+
this._scheduler.scheduleTask(
|
|
618
|
+
this.run,
|
|
619
|
+
this.getFiberRef(core.currentSchedulingPriority)
|
|
620
|
+
)
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Drains the fiber's message queue while the fiber is actively running,
|
|
625
|
+
* returning the next effect to execute, which may be the input effect if no
|
|
626
|
+
* additional effect needs to be executed.
|
|
627
|
+
*
|
|
628
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
629
|
+
*/
|
|
630
|
+
drainQueueWhileRunning(
|
|
631
|
+
runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
632
|
+
cur0: Effect.Effect<any, any, any>
|
|
633
|
+
) {
|
|
634
|
+
let cur = cur0
|
|
635
|
+
while (this._queue.length > 0) {
|
|
636
|
+
const message = this._queue.splice(0, 1)[0]
|
|
637
|
+
// @ts-expect-error
|
|
638
|
+
cur = drainQueueWhileRunningTable[message._tag](this, runtimeFlags, cur, message)
|
|
639
|
+
}
|
|
640
|
+
return cur
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Determines if the fiber is interrupted.
|
|
645
|
+
*
|
|
646
|
+
* **NOTE**: This method is safe to invoke on any fiber, but if not invoked
|
|
647
|
+
* on this fiber, then values derived from the fiber's state (including the
|
|
648
|
+
* log annotations and log level) may not be up-to-date.
|
|
649
|
+
*/
|
|
650
|
+
isInterrupted(): boolean {
|
|
651
|
+
return !internalCause.isEmpty(this.getFiberRef(core.currentInterruptedCause))
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Adds an interruptor to the set of interruptors that are interrupting this
|
|
656
|
+
* fiber.
|
|
657
|
+
*
|
|
658
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
659
|
+
*/
|
|
660
|
+
addInterruptedCause(cause: Cause.Cause<never>) {
|
|
661
|
+
const oldSC = this.getFiberRef(core.currentInterruptedCause)
|
|
662
|
+
this.setFiberRef(core.currentInterruptedCause, internalCause.sequential(oldSC, cause))
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Processes a new incoming interrupt signal.
|
|
667
|
+
*
|
|
668
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
669
|
+
*/
|
|
670
|
+
processNewInterruptSignal(cause: Cause.Cause<never>): void {
|
|
671
|
+
this.addInterruptedCause(cause)
|
|
672
|
+
this.sendInterruptSignalToAllChildren()
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* Interrupts all children of the current fiber, returning an effect that will
|
|
677
|
+
* await the exit of the children. This method will return null if the fiber
|
|
678
|
+
* has no children.
|
|
679
|
+
*
|
|
680
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
681
|
+
*/
|
|
682
|
+
sendInterruptSignalToAllChildren(): boolean {
|
|
683
|
+
if (this._children === null || this._children.size === 0) {
|
|
684
|
+
return false
|
|
685
|
+
}
|
|
686
|
+
let told = false
|
|
687
|
+
for (const child of this._children) {
|
|
688
|
+
child.tell(FiberMessage.interruptSignal(internalCause.interrupt(this.id())))
|
|
689
|
+
told = true
|
|
690
|
+
}
|
|
691
|
+
return told
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Interrupts all children of the current fiber, returning an effect that will
|
|
696
|
+
* await the exit of the children. This method will return null if the fiber
|
|
697
|
+
* has no children.
|
|
698
|
+
*
|
|
699
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
700
|
+
*/
|
|
701
|
+
interruptAllChildren() {
|
|
702
|
+
if (this.sendInterruptSignalToAllChildren()) {
|
|
703
|
+
const it = this._children!.values()
|
|
704
|
+
this._children = null
|
|
705
|
+
let isDone = false
|
|
706
|
+
const body = () => {
|
|
707
|
+
const next = it.next()
|
|
708
|
+
if (!next.done) {
|
|
709
|
+
return core.asUnit(next.value.await())
|
|
710
|
+
} else {
|
|
711
|
+
return core.sync(() => {
|
|
712
|
+
isDone = true
|
|
713
|
+
})
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
return core.whileLoop({
|
|
717
|
+
while: () => !isDone,
|
|
718
|
+
body,
|
|
719
|
+
step: () => {
|
|
720
|
+
//
|
|
721
|
+
}
|
|
722
|
+
})
|
|
723
|
+
}
|
|
724
|
+
return null
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
reportExitValue(exit: Exit.Exit<E, A>) {
|
|
728
|
+
if (_runtimeFlags.runtimeMetrics(this._runtimeFlags)) {
|
|
729
|
+
const tags = this.getFiberRef(core.currentMetricLabels)
|
|
730
|
+
fiberActive.unsafeUpdate(-1, tags)
|
|
731
|
+
switch (exit._tag) {
|
|
732
|
+
case OpCodes.OP_SUCCESS: {
|
|
733
|
+
fiberSuccesses.unsafeUpdate(1, tags)
|
|
734
|
+
break
|
|
735
|
+
}
|
|
736
|
+
case OpCodes.OP_FAILURE: {
|
|
737
|
+
fiberFailures.unsafeUpdate(1, tags)
|
|
738
|
+
break
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
if (exit._tag === "Failure") {
|
|
743
|
+
const level = this.getFiberRef(core.currentUnhandledErrorLogLevel)
|
|
744
|
+
if (!internalCause.isInterruptedOnly(exit.cause) && level._tag === "Some") {
|
|
745
|
+
this.log("Fiber terminated with a non handled error", exit.cause, level)
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
setExitValue(exit: Exit.Exit<E, A>) {
|
|
751
|
+
this._exitValue = exit
|
|
752
|
+
|
|
753
|
+
if (_runtimeFlags.runtimeMetrics(this._runtimeFlags)) {
|
|
754
|
+
const tags = this.getFiberRef(core.currentMetricLabels)
|
|
755
|
+
const startTimeMillis = this.id().startTimeMillis
|
|
756
|
+
const endTimeMillis = new Date().getTime()
|
|
757
|
+
fiberLifetimes.unsafeUpdate(endTimeMillis - startTimeMillis, tags)
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
this.reportExitValue(exit)
|
|
761
|
+
|
|
762
|
+
for (let i = this._observers.length - 1; i >= 0; i--) {
|
|
763
|
+
this._observers[i](exit)
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
getLoggers() {
|
|
768
|
+
return this.getFiberRef(currentLoggers)
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
log(
|
|
772
|
+
message: unknown,
|
|
773
|
+
cause: Cause.Cause<any>,
|
|
774
|
+
overrideLogLevel: Option.Option<LogLevel.LogLevel>
|
|
775
|
+
): void {
|
|
776
|
+
const logLevel = Option.isSome(overrideLogLevel) ?
|
|
777
|
+
overrideLogLevel.value :
|
|
778
|
+
this.getFiberRef(core.currentLogLevel)
|
|
779
|
+
const minimumLogLevel = this.getFiberRef(currentMinimumLogLevel)
|
|
780
|
+
if (LogLevel.greaterThan(minimumLogLevel, logLevel)) {
|
|
781
|
+
return
|
|
782
|
+
}
|
|
783
|
+
const spans = this.getFiberRef(core.currentLogSpan)
|
|
784
|
+
const annotations = this.getFiberRef(core.currentLogAnnotations)
|
|
785
|
+
const loggers = this.getLoggers()
|
|
786
|
+
const contextMap = this.getFiberRefs()
|
|
787
|
+
if (HashSet.size(loggers) > 0) {
|
|
788
|
+
const clockService = Context.get(this.getFiberRef(defaultServices.currentServices), clock.clockTag)
|
|
789
|
+
const date = new Date(clockService.unsafeCurrentTimeMillis())
|
|
790
|
+
for (const logger of loggers) {
|
|
791
|
+
logger.log({
|
|
792
|
+
fiberId: this.id(),
|
|
793
|
+
logLevel,
|
|
794
|
+
message,
|
|
795
|
+
cause,
|
|
796
|
+
context: contextMap,
|
|
797
|
+
spans,
|
|
798
|
+
annotations,
|
|
799
|
+
date
|
|
800
|
+
})
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Evaluates a single message on the current thread, while the fiber is
|
|
807
|
+
* suspended. This method should only be called while evaluation of the
|
|
808
|
+
* fiber's effect is suspended due to an asynchronous operation.
|
|
809
|
+
*
|
|
810
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
811
|
+
*/
|
|
812
|
+
evaluateMessageWhileSuspended(message: FiberMessage.FiberMessage): EvaluationSignal {
|
|
813
|
+
switch (message._tag) {
|
|
814
|
+
case FiberMessage.OP_YIELD_NOW: {
|
|
815
|
+
return EvaluationSignalYieldNow
|
|
816
|
+
}
|
|
817
|
+
case FiberMessage.OP_INTERRUPT_SIGNAL: {
|
|
818
|
+
this.processNewInterruptSignal(message.cause)
|
|
819
|
+
if (this._asyncInterruptor !== null) {
|
|
820
|
+
this._asyncInterruptor(core.exitFailCause(message.cause))
|
|
821
|
+
this._asyncInterruptor = null
|
|
822
|
+
}
|
|
823
|
+
return EvaluationSignalContinue
|
|
824
|
+
}
|
|
825
|
+
case FiberMessage.OP_RESUME: {
|
|
826
|
+
this._asyncInterruptor = null
|
|
827
|
+
this._asyncBlockingOn = null
|
|
828
|
+
this.evaluateEffect(message.effect)
|
|
829
|
+
return EvaluationSignalContinue
|
|
830
|
+
}
|
|
831
|
+
case FiberMessage.OP_STATEFUL: {
|
|
832
|
+
message.onFiber(
|
|
833
|
+
this,
|
|
834
|
+
this._exitValue !== null ?
|
|
835
|
+
FiberStatus.done :
|
|
836
|
+
FiberStatus.suspended(this._runtimeFlags, this._asyncBlockingOn!)
|
|
837
|
+
)
|
|
838
|
+
return EvaluationSignalContinue
|
|
839
|
+
}
|
|
840
|
+
default: {
|
|
841
|
+
return absurd(message)
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Evaluates an effect until completion, potentially asynchronously.
|
|
848
|
+
*
|
|
849
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
850
|
+
*/
|
|
851
|
+
evaluateEffect(effect0: Effect.Effect<any, any, any>) {
|
|
852
|
+
this._supervisor.onResume(this)
|
|
853
|
+
try {
|
|
854
|
+
let effect: Effect.Effect<any, any, any> | null =
|
|
855
|
+
_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted() ?
|
|
856
|
+
core.exitFailCause(this.getInterruptedCause()) :
|
|
857
|
+
effect0
|
|
858
|
+
while (effect !== null) {
|
|
859
|
+
try {
|
|
860
|
+
const eff: Effect.Effect<any, any, any> = effect
|
|
861
|
+
const exit = this.runLoop(eff)
|
|
862
|
+
this._runtimeFlags = pipe(this._runtimeFlags, _runtimeFlags.enable(_runtimeFlags.WindDown))
|
|
863
|
+
const interruption = this.interruptAllChildren()
|
|
864
|
+
if (interruption !== null) {
|
|
865
|
+
effect = core.flatMap(interruption, () => exit)
|
|
866
|
+
} else {
|
|
867
|
+
if (this._queue.length === 0) {
|
|
868
|
+
// No more messages to process, so we will allow the fiber to end life:
|
|
869
|
+
this.setExitValue(exit)
|
|
870
|
+
} else {
|
|
871
|
+
// There are messages, possibly added by the final op executed by
|
|
872
|
+
// the fiber. To be safe, we should execute those now before we
|
|
873
|
+
// allow the fiber to end life:
|
|
874
|
+
this.tell(FiberMessage.resume(exit))
|
|
875
|
+
}
|
|
876
|
+
effect = null
|
|
877
|
+
}
|
|
878
|
+
} catch (e) {
|
|
879
|
+
if (core.isEffect(e)) {
|
|
880
|
+
if ((e as core.Primitive)._op === OpCodes.OP_YIELD) {
|
|
881
|
+
if (_runtimeFlags.cooperativeYielding(this._runtimeFlags)) {
|
|
882
|
+
this.tell(FiberMessage.yieldNow())
|
|
883
|
+
this.tell(FiberMessage.resume(core.exitUnit))
|
|
884
|
+
effect = null
|
|
885
|
+
} else {
|
|
886
|
+
effect = core.exitUnit
|
|
887
|
+
}
|
|
888
|
+
} else if ((e as core.Primitive)._op === OpCodes.OP_ASYNC) {
|
|
889
|
+
// Terminate this evaluation, async resumption will continue evaluation:
|
|
890
|
+
effect = null
|
|
891
|
+
}
|
|
892
|
+
} else {
|
|
893
|
+
throw e
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
} finally {
|
|
898
|
+
this._supervisor.onSuspend(this)
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Begins execution of the effect associated with this fiber on the current
|
|
904
|
+
* thread. This can be called to "kick off" execution of a fiber after it has
|
|
905
|
+
* been created, in hopes that the effect can be executed synchronously.
|
|
906
|
+
*
|
|
907
|
+
* This is not the normal way of starting a fiber, but it is useful when the
|
|
908
|
+
* express goal of executing the fiber is to synchronously produce its exit.
|
|
909
|
+
*/
|
|
910
|
+
start<R>(effect: Effect.Effect<R, E, A>): void {
|
|
911
|
+
if (!this._running) {
|
|
912
|
+
this._running = true
|
|
913
|
+
const prev = (globalThis as any)[internalFiber.currentFiberURI]
|
|
914
|
+
;(globalThis as any)[internalFiber.currentFiberURI] = this
|
|
915
|
+
try {
|
|
916
|
+
this.evaluateEffect(effect)
|
|
917
|
+
} finally {
|
|
918
|
+
this._running = false
|
|
919
|
+
;(globalThis as any)[internalFiber.currentFiberURI] = prev
|
|
920
|
+
// Because we're special casing `start`, we have to be responsible
|
|
921
|
+
// for spinning up the fiber if there were new messages added to
|
|
922
|
+
// the queue between the completion of the effect and the transition
|
|
923
|
+
// to the not running state.
|
|
924
|
+
if (this._queue.length > 0) {
|
|
925
|
+
this.drainQueueLaterOnExecutor()
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
} else {
|
|
929
|
+
this.tell(FiberMessage.resume(effect))
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Begins execution of the effect associated with this fiber on in the
|
|
935
|
+
* background, and on the correct thread pool. This can be called to "kick
|
|
936
|
+
* off" execution of a fiber after it has been created, in hopes that the
|
|
937
|
+
* effect can be executed synchronously.
|
|
938
|
+
*/
|
|
939
|
+
startFork<R>(effect: Effect.Effect<R, E, A>): void {
|
|
940
|
+
this.tell(FiberMessage.resume(effect))
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Takes the current runtime flags, patches them to return the new runtime
|
|
945
|
+
* flags, and then makes any changes necessary to fiber state based on the
|
|
946
|
+
* specified patch.
|
|
947
|
+
*
|
|
948
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
949
|
+
*/
|
|
950
|
+
patchRuntimeFlags(oldRuntimeFlags: RuntimeFlags.RuntimeFlags, patch: RuntimeFlagsPatch.RuntimeFlagsPatch) {
|
|
951
|
+
const newRuntimeFlags = _runtimeFlags.patch(oldRuntimeFlags, patch)
|
|
952
|
+
;(globalThis as any)[internalFiber.currentFiberURI] = this
|
|
953
|
+
this._runtimeFlags = newRuntimeFlags
|
|
954
|
+
return newRuntimeFlags
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Initiates an asynchronous operation, by building a callback that will
|
|
959
|
+
* resume execution, and then feeding that callback to the registration
|
|
960
|
+
* function, handling error cases and repeated resumptions appropriately.
|
|
961
|
+
*
|
|
962
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
963
|
+
*/
|
|
964
|
+
initiateAsync(
|
|
965
|
+
runtimeFlags: RuntimeFlags.RuntimeFlags,
|
|
966
|
+
asyncRegister: (resume: (effect: Effect.Effect<any, any, any>) => void) => void
|
|
967
|
+
) {
|
|
968
|
+
let alreadyCalled = false
|
|
969
|
+
const callback = (effect: Effect.Effect<any, any, any>) => {
|
|
970
|
+
if (!alreadyCalled) {
|
|
971
|
+
alreadyCalled = true
|
|
972
|
+
this.tell(FiberMessage.resume(effect))
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
if (_runtimeFlags.interruptible(runtimeFlags)) {
|
|
976
|
+
this._asyncInterruptor = callback
|
|
977
|
+
}
|
|
978
|
+
try {
|
|
979
|
+
asyncRegister(callback)
|
|
980
|
+
} catch (e) {
|
|
981
|
+
callback(core.failCause(internalCause.die(e)))
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
pushStack(cont: core.Continuation) {
|
|
986
|
+
this._stack.push(cont)
|
|
987
|
+
if (cont._op === "OnStep") {
|
|
988
|
+
this._steps.push(true)
|
|
989
|
+
}
|
|
990
|
+
if (cont._op === "RevertFlags") {
|
|
991
|
+
this._steps.push(false)
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
popStack() {
|
|
996
|
+
const item = this._stack.pop()
|
|
997
|
+
if (item) {
|
|
998
|
+
if (item._op === "OnStep" || item._op === "RevertFlags") {
|
|
999
|
+
this._steps.pop()
|
|
1000
|
+
}
|
|
1001
|
+
return item
|
|
1002
|
+
}
|
|
1003
|
+
return
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
getNextSuccessCont() {
|
|
1007
|
+
let frame = this.popStack()
|
|
1008
|
+
while (frame) {
|
|
1009
|
+
if (frame._op !== OpCodes.OP_ON_FAILURE) {
|
|
1010
|
+
return frame
|
|
1011
|
+
}
|
|
1012
|
+
frame = this.popStack()
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
getNextFailCont() {
|
|
1017
|
+
let frame = this.popStack()
|
|
1018
|
+
while (frame) {
|
|
1019
|
+
if (frame._op !== OpCodes.OP_ON_SUCCESS && frame._op !== OpCodes.OP_WHILE) {
|
|
1020
|
+
return frame
|
|
1021
|
+
}
|
|
1022
|
+
frame = this.popStack()
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
[OpCodes.OP_TAG](op: core.Primitive & { _op: OpCodes.OP_SYNC }) {
|
|
1027
|
+
return core.map(
|
|
1028
|
+
core.fiberRefGet(core.currentContext),
|
|
1029
|
+
(context) => {
|
|
1030
|
+
try {
|
|
1031
|
+
return Context.unsafeGet(context, op as unknown as Context.Tag<any, any>)
|
|
1032
|
+
} catch (e) {
|
|
1033
|
+
console.log(e)
|
|
1034
|
+
throw e
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
)
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
["Left"](op: core.Primitive & { _op: "Left" }) {
|
|
1041
|
+
return core.fail(op.left)
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
["None"](_: core.Primitive & { _op: "None" }) {
|
|
1045
|
+
return core.fail(internalCause.NoSuchElementException())
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
["Right"](op: core.Primitive & { _op: "Right" }) {
|
|
1049
|
+
return core.exitSucceed(op.right)
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
["Some"](op: core.Primitive & { _op: "Some" }) {
|
|
1053
|
+
return core.exitSucceed(op.value)
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
[OpCodes.OP_SYNC](op: core.Primitive & { _op: OpCodes.OP_SYNC }) {
|
|
1057
|
+
const value = op.i0()
|
|
1058
|
+
const cont = this.getNextSuccessCont()
|
|
1059
|
+
if (cont !== undefined) {
|
|
1060
|
+
if (!(cont._op in contOpSuccess)) {
|
|
1061
|
+
// @ts-expect-error
|
|
1062
|
+
absurd(cont)
|
|
1063
|
+
}
|
|
1064
|
+
// @ts-expect-error
|
|
1065
|
+
return contOpSuccess[cont._op](this, cont, value)
|
|
1066
|
+
} else {
|
|
1067
|
+
throw core.exitSucceed(value)
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
[OpCodes.OP_SUCCESS](op: core.Primitive & { _op: OpCodes.OP_SUCCESS }) {
|
|
1072
|
+
const oldCur = op
|
|
1073
|
+
const cont = this.getNextSuccessCont()
|
|
1074
|
+
if (cont !== undefined) {
|
|
1075
|
+
if (!(cont._op in contOpSuccess)) {
|
|
1076
|
+
// @ts-expect-error
|
|
1077
|
+
absurd(cont)
|
|
1078
|
+
}
|
|
1079
|
+
// @ts-expect-error
|
|
1080
|
+
return contOpSuccess[cont._op](this, cont, oldCur.i0)
|
|
1081
|
+
} else {
|
|
1082
|
+
throw oldCur
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
[OpCodes.OP_FAILURE](op: core.Primitive & { _op: OpCodes.OP_FAILURE }) {
|
|
1087
|
+
const cause = op.i0
|
|
1088
|
+
const cont = this.getNextFailCont()
|
|
1089
|
+
if (cont !== undefined) {
|
|
1090
|
+
switch (cont._op) {
|
|
1091
|
+
case OpCodes.OP_ON_FAILURE:
|
|
1092
|
+
case OpCodes.OP_ON_SUCCESS_AND_FAILURE: {
|
|
1093
|
+
if (!(_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted())) {
|
|
1094
|
+
return cont.i1(cause)
|
|
1095
|
+
} else {
|
|
1096
|
+
return core.exitFailCause(internalCause.stripFailures(cause))
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
case "OnStep": {
|
|
1100
|
+
if (!(_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted())) {
|
|
1101
|
+
return cont.i1(core.exitFailCause(cause))
|
|
1102
|
+
} else {
|
|
1103
|
+
return core.exitFailCause(internalCause.stripFailures(cause))
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
case OpCodes.OP_REVERT_FLAGS: {
|
|
1107
|
+
this.patchRuntimeFlags(this._runtimeFlags, cont.patch)
|
|
1108
|
+
if (_runtimeFlags.interruptible(this._runtimeFlags) && this.isInterrupted()) {
|
|
1109
|
+
return core.exitFailCause(internalCause.sequential(cause, this.getInterruptedCause()))
|
|
1110
|
+
} else {
|
|
1111
|
+
return core.exitFailCause(cause)
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
default: {
|
|
1115
|
+
absurd(cont)
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
} else {
|
|
1119
|
+
throw core.exitFailCause(cause)
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
[OpCodes.OP_WITH_RUNTIME](op: core.Primitive & { _op: OpCodes.OP_WITH_RUNTIME }) {
|
|
1124
|
+
return op.i0(
|
|
1125
|
+
this as FiberRuntime<unknown, unknown>,
|
|
1126
|
+
FiberStatus.running(this._runtimeFlags) as FiberStatus.Running
|
|
1127
|
+
)
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
["Blocked"](op: core.Primitive & { _op: "Blocked" }) {
|
|
1131
|
+
if (this._steps[this._steps.length - 1]) {
|
|
1132
|
+
const nextOp = this.popStack()
|
|
1133
|
+
if (nextOp) {
|
|
1134
|
+
switch (nextOp._op) {
|
|
1135
|
+
case "OnStep": {
|
|
1136
|
+
return nextOp.i1(op)
|
|
1137
|
+
}
|
|
1138
|
+
case "OnSuccess": {
|
|
1139
|
+
return core.blocked(op.i0, core.flatMap(op.i1, nextOp.i1))
|
|
1140
|
+
}
|
|
1141
|
+
case "OnSuccessAndFailure": {
|
|
1142
|
+
return core.blocked(
|
|
1143
|
+
op.i0,
|
|
1144
|
+
core.matchCauseEffect(op.i1, {
|
|
1145
|
+
onFailure: nextOp.i1,
|
|
1146
|
+
onSuccess: nextOp.i2
|
|
1147
|
+
})
|
|
1148
|
+
)
|
|
1149
|
+
}
|
|
1150
|
+
case "OnFailure": {
|
|
1151
|
+
return core.blocked(op.i0, core.catchAllCause(op.i1, nextOp.i1))
|
|
1152
|
+
}
|
|
1153
|
+
case "While": {
|
|
1154
|
+
return core.blocked(
|
|
1155
|
+
op.i0,
|
|
1156
|
+
core.flatMap(op.i1, (a) => {
|
|
1157
|
+
nextOp.i2(a)
|
|
1158
|
+
if (nextOp.i0()) {
|
|
1159
|
+
return core.whileLoop({
|
|
1160
|
+
while: nextOp.i0,
|
|
1161
|
+
body: nextOp.i1,
|
|
1162
|
+
step: nextOp.i2
|
|
1163
|
+
})
|
|
1164
|
+
}
|
|
1165
|
+
return core.unit
|
|
1166
|
+
})
|
|
1167
|
+
)
|
|
1168
|
+
}
|
|
1169
|
+
case "RevertFlags": {
|
|
1170
|
+
this.pushStack(nextOp)
|
|
1171
|
+
break
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
return core.uninterruptibleMask((restore) =>
|
|
1177
|
+
core.flatMap(
|
|
1178
|
+
fork(core.runRequestBlock(op.i0)),
|
|
1179
|
+
() => restore(op.i1)
|
|
1180
|
+
)
|
|
1181
|
+
)
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
["RunBlocked"](op: core.Primitive & { _op: "RunBlocked" }) {
|
|
1185
|
+
return runBlockedRequests(op.i0)
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
[OpCodes.OP_UPDATE_RUNTIME_FLAGS](op: core.Primitive & { _op: OpCodes.OP_UPDATE_RUNTIME_FLAGS }) {
|
|
1189
|
+
const updateFlags = op.i0
|
|
1190
|
+
const oldRuntimeFlags = this._runtimeFlags
|
|
1191
|
+
const newRuntimeFlags = _runtimeFlags.patch(oldRuntimeFlags, updateFlags)
|
|
1192
|
+
// One more chance to short circuit: if we're immediately going
|
|
1193
|
+
// to interrupt. Interruption will cause immediate reversion of
|
|
1194
|
+
// the flag, so as long as we "peek ahead", there's no need to
|
|
1195
|
+
// set them to begin with.
|
|
1196
|
+
if (_runtimeFlags.interruptible(newRuntimeFlags) && this.isInterrupted()) {
|
|
1197
|
+
return core.exitFailCause(this.getInterruptedCause())
|
|
1198
|
+
} else {
|
|
1199
|
+
// Impossible to short circuit, so record the changes
|
|
1200
|
+
this.patchRuntimeFlags(this._runtimeFlags, updateFlags)
|
|
1201
|
+
if (op.i1) {
|
|
1202
|
+
// Since we updated the flags, we need to revert them
|
|
1203
|
+
const revertFlags = _runtimeFlags.diff(newRuntimeFlags, oldRuntimeFlags)
|
|
1204
|
+
this.pushStack(new core.RevertFlags(revertFlags, op))
|
|
1205
|
+
return op.i1(oldRuntimeFlags)
|
|
1206
|
+
} else {
|
|
1207
|
+
return core.exitUnit
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
[OpCodes.OP_ON_SUCCESS](op: core.Primitive & { _op: OpCodes.OP_ON_SUCCESS }) {
|
|
1213
|
+
this.pushStack(op)
|
|
1214
|
+
return op.i0
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
["OnStep"](op: core.Primitive & { _op: "OnStep" }) {
|
|
1218
|
+
this.pushStack(op)
|
|
1219
|
+
return op.i0
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
[OpCodes.OP_ON_FAILURE](op: core.Primitive & { _op: OpCodes.OP_ON_FAILURE }) {
|
|
1223
|
+
this.pushStack(op)
|
|
1224
|
+
return op.i0
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
[OpCodes.OP_ON_SUCCESS_AND_FAILURE](op: core.Primitive & { _op: OpCodes.OP_ON_SUCCESS_AND_FAILURE }) {
|
|
1228
|
+
this.pushStack(op)
|
|
1229
|
+
return op.i0
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
[OpCodes.OP_ASYNC](op: core.Primitive & { _op: OpCodes.OP_ASYNC }) {
|
|
1233
|
+
this._asyncBlockingOn = op.i1
|
|
1234
|
+
this.initiateAsync(this._runtimeFlags, op.i0)
|
|
1235
|
+
throw op
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
[OpCodes.OP_YIELD](op: core.Primitive & { op: OpCodes.OP_YIELD }) {
|
|
1239
|
+
this.isYielding = false
|
|
1240
|
+
throw op
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
[OpCodes.OP_WHILE](op: core.Primitive & { _op: OpCodes.OP_WHILE }) {
|
|
1244
|
+
const check = op.i0
|
|
1245
|
+
const body = op.i1
|
|
1246
|
+
if (check()) {
|
|
1247
|
+
this.pushStack(op)
|
|
1248
|
+
return body()
|
|
1249
|
+
} else {
|
|
1250
|
+
return core.exitUnit
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
[OpCodes.OP_COMMIT](op: core.Primitive & { _op: OpCodes.OP_COMMIT }) {
|
|
1255
|
+
return op.commit()
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* The main run-loop for evaluating effects.
|
|
1260
|
+
*
|
|
1261
|
+
* **NOTE**: This method must be invoked by the fiber itself.
|
|
1262
|
+
*/
|
|
1263
|
+
runLoop(effect0: Effect.Effect<any, any, any>): Exit.Exit<any, any> {
|
|
1264
|
+
let cur = effect0
|
|
1265
|
+
this.currentOpCount = 0
|
|
1266
|
+
// eslint-disable-next-line no-constant-condition
|
|
1267
|
+
while (true) {
|
|
1268
|
+
if ((this._runtimeFlags & OpSupervision) !== 0) {
|
|
1269
|
+
this._supervisor.onEffect(this, cur)
|
|
1270
|
+
}
|
|
1271
|
+
if (this._queue.length > 0) {
|
|
1272
|
+
cur = this.drainQueueWhileRunning(this._runtimeFlags, cur)
|
|
1273
|
+
}
|
|
1274
|
+
if (!this.isYielding) {
|
|
1275
|
+
this.currentOpCount += 1
|
|
1276
|
+
const shouldYield = this._scheduler.shouldYield(this)
|
|
1277
|
+
if (shouldYield !== false) {
|
|
1278
|
+
this.isYielding = true
|
|
1279
|
+
this.currentOpCount = 0
|
|
1280
|
+
const oldCur = cur
|
|
1281
|
+
cur = core.flatMap(core.yieldNow({ priority: shouldYield }), () => oldCur)
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
try {
|
|
1285
|
+
if (!("_op" in cur)) {
|
|
1286
|
+
console.log(cur)
|
|
1287
|
+
}
|
|
1288
|
+
if (!((cur as core.Primitive)._op in this)) {
|
|
1289
|
+
if (typeof cur === "function") {
|
|
1290
|
+
console.log((cur as any)())
|
|
1291
|
+
}
|
|
1292
|
+
// @ts-expect-error
|
|
1293
|
+
absurd(cur)
|
|
1294
|
+
}
|
|
1295
|
+
// @ts-expect-error
|
|
1296
|
+
cur = this._tracer.context(
|
|
1297
|
+
// @ts-expect-error
|
|
1298
|
+
() => this[(cur as core.Primitive)._op](cur as core.Primitive),
|
|
1299
|
+
this
|
|
1300
|
+
)
|
|
1301
|
+
} catch (e) {
|
|
1302
|
+
if (core.isEffect(e)) {
|
|
1303
|
+
if (
|
|
1304
|
+
(e as core.Primitive)._op === OpCodes.OP_YIELD ||
|
|
1305
|
+
(e as core.Primitive)._op === OpCodes.OP_ASYNC
|
|
1306
|
+
) {
|
|
1307
|
+
throw e
|
|
1308
|
+
}
|
|
1309
|
+
if (
|
|
1310
|
+
(e as core.Primitive)._op === OpCodes.OP_SUCCESS ||
|
|
1311
|
+
(e as core.Primitive)._op === OpCodes.OP_FAILURE
|
|
1312
|
+
) {
|
|
1313
|
+
return e as Exit.Exit<E, A>
|
|
1314
|
+
}
|
|
1315
|
+
} else {
|
|
1316
|
+
if (core.isEffectError(e)) {
|
|
1317
|
+
cur = core.exitFailCause(e.cause)
|
|
1318
|
+
} else if (internalCause.isInterruptedException(e)) {
|
|
1319
|
+
cur = core.exitFailCause(
|
|
1320
|
+
internalCause.sequential(internalCause.die(e), internalCause.interrupt(FiberId.none))
|
|
1321
|
+
)
|
|
1322
|
+
} else {
|
|
1323
|
+
cur = core.exitFailCause(internalCause.die(e))
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
run = () => {
|
|
1331
|
+
this.drainQueueOnCurrentThread()
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// circular with Logger
|
|
1336
|
+
|
|
1337
|
+
/** @internal */
|
|
1338
|
+
export const currentMinimumLogLevel: FiberRef.FiberRef<LogLevel.LogLevel> = core.fiberRefUnsafeMake<LogLevel.LogLevel>(
|
|
1339
|
+
LogLevel.fromLiteral("Info")
|
|
1340
|
+
)
|
|
1341
|
+
|
|
1342
|
+
/** @internal */
|
|
1343
|
+
export const getConsole = (refs: FiberRefs.FiberRefs) => {
|
|
1344
|
+
const defaultServicesValue = FiberRefs.getOrDefault(refs, defaultServices.currentServices)
|
|
1345
|
+
const cnsl = Context.get(defaultServicesValue, consoleTag)
|
|
1346
|
+
return cnsl.unsafe
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/** @internal */
|
|
1350
|
+
export const defaultLogger: Logger<unknown, void> = internalLogger.makeLogger((options) => {
|
|
1351
|
+
const formatted = internalLogger.stringLogger.log(options)
|
|
1352
|
+
getConsole(options.context).log(formatted)
|
|
1353
|
+
})
|
|
1354
|
+
|
|
1355
|
+
/** @internal */
|
|
1356
|
+
export const filterMinimumLogLevel: Logger<unknown, void> = internalLogger.makeLogger((options) => {
|
|
1357
|
+
const formatted = internalLogger.stringLogger.log(options)
|
|
1358
|
+
getConsole(options.context).log(formatted)
|
|
1359
|
+
})
|
|
1360
|
+
|
|
1361
|
+
/** @internal */
|
|
1362
|
+
export const logFmtLogger: Logger<unknown, void> = internalLogger.makeLogger((options) => {
|
|
1363
|
+
const formatted = internalLogger.logfmtLogger.log(options)
|
|
1364
|
+
getConsole(options.context).log(formatted)
|
|
1365
|
+
})
|
|
1366
|
+
|
|
1367
|
+
/** @internal */
|
|
1368
|
+
export const tracerLogger = internalLogger.makeLogger<unknown, void>(({
|
|
1369
|
+
annotations,
|
|
1370
|
+
cause,
|
|
1371
|
+
context,
|
|
1372
|
+
fiberId,
|
|
1373
|
+
logLevel,
|
|
1374
|
+
message
|
|
1375
|
+
}) => {
|
|
1376
|
+
const span = Option.flatMap(fiberRefs.get(context, core.currentTracerSpan), List.head)
|
|
1377
|
+
const clockService = Option.map(
|
|
1378
|
+
fiberRefs.get(context, defaultServices.currentServices),
|
|
1379
|
+
(_) => Context.get(_, clock.clockTag)
|
|
1380
|
+
)
|
|
1381
|
+
if (span._tag === "None" || span.value._tag === "ExternalSpan" || clockService._tag === "None") {
|
|
1382
|
+
return
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
const attributes = Object.fromEntries(annotations)
|
|
1386
|
+
attributes["effect.fiberId"] = FiberId.threadName(fiberId)
|
|
1387
|
+
attributes["effect.logLevel"] = logLevel.label
|
|
1388
|
+
|
|
1389
|
+
if (cause !== null && cause._tag !== "Empty") {
|
|
1390
|
+
attributes["effect.cause"] = internalCause.pretty(cause)
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
span.value.event(
|
|
1394
|
+
String(message),
|
|
1395
|
+
clockService.value.unsafeCurrentTimeNanos(),
|
|
1396
|
+
attributes
|
|
1397
|
+
)
|
|
1398
|
+
})
|
|
1399
|
+
|
|
1400
|
+
/** @internal */
|
|
1401
|
+
export const currentLoggers: FiberRef.FiberRef<
|
|
1402
|
+
HashSet.HashSet<Logger<unknown, any>>
|
|
1403
|
+
> = core.fiberRefUnsafeMakeHashSet(HashSet.make(defaultLogger, tracerLogger))
|
|
1404
|
+
|
|
1405
|
+
// circular with Effect
|
|
1406
|
+
|
|
1407
|
+
/* @internal */
|
|
1408
|
+
export const acquireRelease: {
|
|
1409
|
+
<A, R2, X>(
|
|
1410
|
+
release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1411
|
+
): <R, E>(acquire: Effect.Effect<R, E, A>) => Effect.Effect<R2 | R | Scope.Scope, E, A>
|
|
1412
|
+
<R, E, A, R2, X>(
|
|
1413
|
+
acquire: Effect.Effect<R, E, A>,
|
|
1414
|
+
release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1415
|
+
): Effect.Effect<Scope.Scope | R | R2, E, A>
|
|
1416
|
+
} = dual<
|
|
1417
|
+
{
|
|
1418
|
+
<A, R2, X>(
|
|
1419
|
+
release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1420
|
+
): <R, E>(acquire: Effect.Effect<R, E, A>) => Effect.Effect<R | R2 | Scope.Scope, E, A>
|
|
1421
|
+
},
|
|
1422
|
+
{
|
|
1423
|
+
<R, E, A, R2, X>(
|
|
1424
|
+
acquire: Effect.Effect<R, E, A>,
|
|
1425
|
+
release: (a: A, exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1426
|
+
): Effect.Effect<R | R2 | Scope.Scope, E, A>
|
|
1427
|
+
}
|
|
1428
|
+
>((args) => core.isEffect(args[0]), (acquire, release) => {
|
|
1429
|
+
return core.uninterruptible(
|
|
1430
|
+
core.tap(acquire, (a) => addFinalizer((exit) => release(a, exit)))
|
|
1431
|
+
)
|
|
1432
|
+
})
|
|
1433
|
+
|
|
1434
|
+
/* @internal */
|
|
1435
|
+
export const acquireReleaseInterruptible: {
|
|
1436
|
+
<A, R2, X>(
|
|
1437
|
+
release: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1438
|
+
): <R, E>(acquire: Effect.Effect<R, E, A>) => Effect.Effect<Scope.Scope | R2 | R, E, A>
|
|
1439
|
+
<R, E, A, R2, X>(
|
|
1440
|
+
acquire: Effect.Effect<R, E, A>,
|
|
1441
|
+
release: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1442
|
+
): Effect.Effect<Scope.Scope | R | R2, E, A>
|
|
1443
|
+
} = dual<
|
|
1444
|
+
{
|
|
1445
|
+
<A, R2, X>(
|
|
1446
|
+
release: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1447
|
+
): <R, E>(acquire: Effect.Effect<R, E, A>) => Effect.Effect<R | R2 | Scope.Scope, E, A>
|
|
1448
|
+
},
|
|
1449
|
+
{
|
|
1450
|
+
<R, E, A, R2, X>(
|
|
1451
|
+
acquire: Effect.Effect<R, E, A>,
|
|
1452
|
+
release: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R2, never, X>
|
|
1453
|
+
): Effect.Effect<R | R2 | Scope.Scope, E, A>
|
|
1454
|
+
}
|
|
1455
|
+
>((args) => core.isEffect(args[0]), (acquire, release) => {
|
|
1456
|
+
return ensuring(
|
|
1457
|
+
acquire,
|
|
1458
|
+
addFinalizer((exit) => release(exit))
|
|
1459
|
+
)
|
|
1460
|
+
})
|
|
1461
|
+
|
|
1462
|
+
/* @internal */
|
|
1463
|
+
export const addFinalizer = <R, X>(
|
|
1464
|
+
finalizer: (exit: Exit.Exit<unknown, unknown>) => Effect.Effect<R, never, X>
|
|
1465
|
+
): Effect.Effect<R | Scope.Scope, never, void> =>
|
|
1466
|
+
core.withFiberRuntime(
|
|
1467
|
+
(runtime) => {
|
|
1468
|
+
const acquireRefs = runtime.getFiberRefs()
|
|
1469
|
+
const acquireFlags = runtime._runtimeFlags
|
|
1470
|
+
return core.flatMap(scope, (scope) =>
|
|
1471
|
+
core.scopeAddFinalizerExit(scope, (exit) =>
|
|
1472
|
+
core.withFiberRuntime((runtimeFinalizer) => {
|
|
1473
|
+
const preRefs = runtimeFinalizer.getFiberRefs()
|
|
1474
|
+
const preFlags = runtimeFinalizer._runtimeFlags
|
|
1475
|
+
const patchRefs = FiberRefsPatch.diff(preRefs, acquireRefs)
|
|
1476
|
+
const patchFlags = _runtimeFlags.diff(preFlags, acquireFlags)
|
|
1477
|
+
const inverseRefs = FiberRefsPatch.diff(acquireRefs, preRefs)
|
|
1478
|
+
runtimeFinalizer.setFiberRefs(
|
|
1479
|
+
FiberRefsPatch.patch(patchRefs, runtimeFinalizer.id(), acquireRefs)
|
|
1480
|
+
)
|
|
1481
|
+
|
|
1482
|
+
return ensuring(
|
|
1483
|
+
core.withRuntimeFlags(finalizer(exit) as Effect.Effect<never, never, X>, patchFlags),
|
|
1484
|
+
core.sync(() => {
|
|
1485
|
+
runtimeFinalizer.setFiberRefs(
|
|
1486
|
+
FiberRefsPatch.patch(inverseRefs, runtimeFinalizer.id(), runtimeFinalizer.getFiberRefs())
|
|
1487
|
+
)
|
|
1488
|
+
})
|
|
1489
|
+
)
|
|
1490
|
+
})))
|
|
1491
|
+
}
|
|
1492
|
+
)
|
|
1493
|
+
|
|
1494
|
+
/* @internal */
|
|
1495
|
+
export const daemonChildren = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> => {
|
|
1496
|
+
const forkScope = core.fiberRefLocally(core.currentForkScopeOverride, Option.some(fiberScope.globalScope))
|
|
1497
|
+
return forkScope(self)
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
/** @internal */
|
|
1501
|
+
const _existsParFound = Symbol.for("effect/Effect/existsPar/found")
|
|
1502
|
+
|
|
1503
|
+
/* @internal */
|
|
1504
|
+
export const exists = dual<
|
|
1505
|
+
<R, E, A>(f: (a: A, i: number) => Effect.Effect<R, E, boolean>, options?: {
|
|
1506
|
+
readonly concurrency?: Concurrency
|
|
1507
|
+
readonly batching?: boolean | "inherit"
|
|
1508
|
+
}) => (elements: Iterable<A>) => Effect.Effect<R, E, boolean>,
|
|
1509
|
+
<R, E, A>(elements: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, boolean>, options?: {
|
|
1510
|
+
readonly concurrency: Concurrency
|
|
1511
|
+
readonly batching?: boolean | "inherit"
|
|
1512
|
+
}) => Effect.Effect<R, E, boolean>
|
|
1513
|
+
>((args) => Predicate.isIterable(args[0]), (elements, f, options) =>
|
|
1514
|
+
concurrency.matchSimple(
|
|
1515
|
+
options,
|
|
1516
|
+
() => core.suspend(() => existsLoop(elements[Symbol.iterator](), 0, f)),
|
|
1517
|
+
() =>
|
|
1518
|
+
core.matchEffect(
|
|
1519
|
+
forEachOptions(
|
|
1520
|
+
elements,
|
|
1521
|
+
(a, i) => core.if_(f(a, i), { onTrue: core.fail(_existsParFound), onFalse: core.unit }),
|
|
1522
|
+
options
|
|
1523
|
+
),
|
|
1524
|
+
{
|
|
1525
|
+
onFailure: (e) => e === _existsParFound ? core.succeed(true) : core.fail(e),
|
|
1526
|
+
onSuccess: () => core.succeed(false)
|
|
1527
|
+
}
|
|
1528
|
+
)
|
|
1529
|
+
))
|
|
1530
|
+
|
|
1531
|
+
const existsLoop = <R, E, A>(
|
|
1532
|
+
iterator: Iterator<A>,
|
|
1533
|
+
index: number,
|
|
1534
|
+
f: (a: A, i: number) => Effect.Effect<R, E, boolean>
|
|
1535
|
+
): Effect.Effect<R, E, boolean> => {
|
|
1536
|
+
const next = iterator.next()
|
|
1537
|
+
if (next.done) {
|
|
1538
|
+
return core.succeed(false)
|
|
1539
|
+
}
|
|
1540
|
+
return pipe(core.flatMap(
|
|
1541
|
+
f(next.value, index),
|
|
1542
|
+
(b) => b ? core.succeed(b) : existsLoop(iterator, index + 1, f)
|
|
1543
|
+
))
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
/* @internal */
|
|
1547
|
+
export const filter = dual<
|
|
1548
|
+
<A, R, E>(
|
|
1549
|
+
f: (a: A, i: number) => Effect.Effect<R, E, boolean>,
|
|
1550
|
+
options?: {
|
|
1551
|
+
readonly concurrency?: Concurrency
|
|
1552
|
+
readonly batching?: boolean | "inherit"
|
|
1553
|
+
readonly negate?: boolean
|
|
1554
|
+
}
|
|
1555
|
+
) => (elements: Iterable<A>) => Effect.Effect<R, E, Array<A>>,
|
|
1556
|
+
<A, R, E>(elements: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, boolean>, options?: {
|
|
1557
|
+
readonly concurrency?: Concurrency
|
|
1558
|
+
readonly batching?: boolean | "inherit"
|
|
1559
|
+
readonly negate?: boolean
|
|
1560
|
+
}) => Effect.Effect<R, E, Array<A>>
|
|
1561
|
+
>(
|
|
1562
|
+
(args) => Predicate.isIterable(args[0]),
|
|
1563
|
+
<A, R, E>(elements: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, boolean>, options?: {
|
|
1564
|
+
readonly concurrency?: Concurrency
|
|
1565
|
+
readonly batching?: boolean | "inherit"
|
|
1566
|
+
readonly negate?: boolean
|
|
1567
|
+
}) => {
|
|
1568
|
+
const predicate = options?.negate ? (a: A, i: number) => core.map(f(a, i), Boolean.not) : f
|
|
1569
|
+
return concurrency.matchSimple(
|
|
1570
|
+
options,
|
|
1571
|
+
() =>
|
|
1572
|
+
core.suspend(() =>
|
|
1573
|
+
RA.fromIterable(elements).reduceRight(
|
|
1574
|
+
(effect, a, i) =>
|
|
1575
|
+
core.zipWith(
|
|
1576
|
+
effect,
|
|
1577
|
+
core.suspend(() => predicate(a, i)),
|
|
1578
|
+
(list, b) => b ? [a, ...list] : list
|
|
1579
|
+
),
|
|
1580
|
+
core.sync(() => new Array<A>()) as Effect.Effect<R, E, Array<A>>
|
|
1581
|
+
)
|
|
1582
|
+
),
|
|
1583
|
+
() =>
|
|
1584
|
+
core.map(
|
|
1585
|
+
forEachOptions(
|
|
1586
|
+
elements,
|
|
1587
|
+
(a, i) => core.map(predicate(a, i), (b) => (b ? Option.some(a) : Option.none())),
|
|
1588
|
+
options
|
|
1589
|
+
),
|
|
1590
|
+
RA.compact
|
|
1591
|
+
)
|
|
1592
|
+
)
|
|
1593
|
+
}
|
|
1594
|
+
)
|
|
1595
|
+
|
|
1596
|
+
// === all
|
|
1597
|
+
|
|
1598
|
+
const allResolveInput = (
|
|
1599
|
+
input: Iterable<Effect.Effect<any, any, any>> | Record<string, Effect.Effect<any, any, any>>
|
|
1600
|
+
): readonly [Iterable<Effect.Effect<any, any, any>>, Option.Option<(as: ReadonlyArray<any>) => any>] => {
|
|
1601
|
+
if (Array.isArray(input) || Predicate.isIterable(input)) {
|
|
1602
|
+
return [input, Option.none()]
|
|
1603
|
+
}
|
|
1604
|
+
const keys = Object.keys(input)
|
|
1605
|
+
const size = keys.length
|
|
1606
|
+
return [
|
|
1607
|
+
keys.map((k) => input[k]),
|
|
1608
|
+
Option.some((values: ReadonlyArray<any>) => {
|
|
1609
|
+
const res = {}
|
|
1610
|
+
for (let i = 0; i < size; i++) {
|
|
1611
|
+
;(res as any)[keys[i]] = values[i]
|
|
1612
|
+
}
|
|
1613
|
+
return res
|
|
1614
|
+
})
|
|
1615
|
+
]
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
const allValidate = (
|
|
1619
|
+
effects: Iterable<Effect.Effect<any, any, any>>,
|
|
1620
|
+
reconcile: Option.Option<(as: ReadonlyArray<any>) => any>,
|
|
1621
|
+
options?: {
|
|
1622
|
+
readonly concurrency?: Concurrency
|
|
1623
|
+
readonly batching?: boolean | "inherit"
|
|
1624
|
+
readonly discard?: boolean
|
|
1625
|
+
readonly mode?: "default" | "validate" | "either"
|
|
1626
|
+
}
|
|
1627
|
+
) => {
|
|
1628
|
+
const eitherEffects: Array<Effect.Effect<unknown, never, Either.Either<unknown, unknown>>> = []
|
|
1629
|
+
for (const effect of effects) {
|
|
1630
|
+
eitherEffects.push(core.either(effect))
|
|
1631
|
+
}
|
|
1632
|
+
return core.flatMap(
|
|
1633
|
+
forEachOptions(eitherEffects, identity, {
|
|
1634
|
+
concurrency: options?.concurrency,
|
|
1635
|
+
batching: options?.batching
|
|
1636
|
+
}),
|
|
1637
|
+
(eithers) => {
|
|
1638
|
+
const none = Option.none()
|
|
1639
|
+
const size = eithers.length
|
|
1640
|
+
const errors: Array<unknown> = new Array(size)
|
|
1641
|
+
const successes: Array<unknown> = new Array(size)
|
|
1642
|
+
let errored = false
|
|
1643
|
+
for (let i = 0; i < size; i++) {
|
|
1644
|
+
const either = eithers[i] as Either.Either<unknown, unknown>
|
|
1645
|
+
if (either._tag === "Left") {
|
|
1646
|
+
errors[i] = Option.some(either.left)
|
|
1647
|
+
errored = true
|
|
1648
|
+
} else {
|
|
1649
|
+
successes[i] = either.right
|
|
1650
|
+
errors[i] = none
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
if (errored) {
|
|
1654
|
+
return reconcile._tag === "Some" ?
|
|
1655
|
+
core.fail(reconcile.value(errors)) :
|
|
1656
|
+
core.fail(errors)
|
|
1657
|
+
} else if (options?.discard) {
|
|
1658
|
+
return core.unit
|
|
1659
|
+
}
|
|
1660
|
+
return reconcile._tag === "Some" ?
|
|
1661
|
+
core.succeed(reconcile.value(successes)) :
|
|
1662
|
+
core.succeed(successes)
|
|
1663
|
+
}
|
|
1664
|
+
)
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
const allEither = (
|
|
1668
|
+
effects: Iterable<Effect.Effect<any, any, any>>,
|
|
1669
|
+
reconcile: Option.Option<(as: ReadonlyArray<any>) => any>,
|
|
1670
|
+
options?: {
|
|
1671
|
+
readonly concurrency?: Concurrency
|
|
1672
|
+
readonly batching?: boolean | "inherit"
|
|
1673
|
+
readonly discard?: boolean
|
|
1674
|
+
readonly mode?: "default" | "validate" | "either"
|
|
1675
|
+
}
|
|
1676
|
+
) => {
|
|
1677
|
+
const eitherEffects: Array<Effect.Effect<unknown, never, Either.Either<unknown, unknown>>> = []
|
|
1678
|
+
for (const effect of effects) {
|
|
1679
|
+
eitherEffects.push(core.either(effect))
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
if (options?.discard) {
|
|
1683
|
+
return forEachOptions(eitherEffects, identity, {
|
|
1684
|
+
concurrency: options?.concurrency,
|
|
1685
|
+
batching: options?.batching,
|
|
1686
|
+
discard: true
|
|
1687
|
+
})
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
return core.map(
|
|
1691
|
+
forEachOptions(eitherEffects, identity, {
|
|
1692
|
+
concurrency: options?.concurrency,
|
|
1693
|
+
batching: options?.batching
|
|
1694
|
+
}),
|
|
1695
|
+
(eithers) =>
|
|
1696
|
+
reconcile._tag === "Some" ?
|
|
1697
|
+
reconcile.value(eithers) :
|
|
1698
|
+
eithers
|
|
1699
|
+
)
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
/* @internal */
|
|
1703
|
+
export const all = <
|
|
1704
|
+
const Arg extends Iterable<Effect.Effect<any, any, any>> | Record<string, Effect.Effect<any, any, any>>,
|
|
1705
|
+
O extends {
|
|
1706
|
+
readonly concurrency?: Concurrency
|
|
1707
|
+
readonly batching?: boolean | "inherit"
|
|
1708
|
+
readonly discard?: boolean
|
|
1709
|
+
readonly mode?: "default" | "validate" | "either"
|
|
1710
|
+
}
|
|
1711
|
+
>(
|
|
1712
|
+
arg: Arg,
|
|
1713
|
+
options?: O
|
|
1714
|
+
): Effect.All.Return<Arg, O> => {
|
|
1715
|
+
const [effects, reconcile] = allResolveInput(arg)
|
|
1716
|
+
|
|
1717
|
+
if (options?.mode === "validate") {
|
|
1718
|
+
return allValidate(effects, reconcile, options) as any
|
|
1719
|
+
} else if (options?.mode === "either") {
|
|
1720
|
+
return allEither(effects, reconcile, options) as any
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
return reconcile._tag === "Some"
|
|
1724
|
+
? core.map(
|
|
1725
|
+
forEachOptions(effects, identity, options as any),
|
|
1726
|
+
reconcile.value
|
|
1727
|
+
) as any
|
|
1728
|
+
: forEachOptions(effects, identity, options as any) as any
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/* @internal */
|
|
1732
|
+
export const allWith = <
|
|
1733
|
+
O extends {
|
|
1734
|
+
readonly concurrency?: Concurrency
|
|
1735
|
+
readonly batching?: boolean | "inherit"
|
|
1736
|
+
readonly discard?: boolean
|
|
1737
|
+
readonly mode?: "default" | "validate" | "either"
|
|
1738
|
+
}
|
|
1739
|
+
>(options?: O) =>
|
|
1740
|
+
<const Arg extends Iterable<Effect.Effect<any, any, any>> | Record<string, Effect.Effect<any, any, any>>>(
|
|
1741
|
+
arg: Arg
|
|
1742
|
+
): Effect.All.Return<Arg, O> => all(arg, options)
|
|
1743
|
+
|
|
1744
|
+
/* @internal */
|
|
1745
|
+
export const allSuccesses = <R, E, A>(
|
|
1746
|
+
elements: Iterable<Effect.Effect<R, E, A>>,
|
|
1747
|
+
options?: {
|
|
1748
|
+
readonly concurrency?: Concurrency
|
|
1749
|
+
readonly batching?: boolean | "inherit"
|
|
1750
|
+
}
|
|
1751
|
+
): Effect.Effect<R, never, Array<A>> =>
|
|
1752
|
+
core.map(
|
|
1753
|
+
all(RA.fromIterable(elements).map(core.exit), options),
|
|
1754
|
+
RA.filterMap((exit) => core.exitIsSuccess(exit) ? Option.some(exit.i0) : Option.none())
|
|
1755
|
+
)
|
|
1756
|
+
|
|
1757
|
+
/* @internal */
|
|
1758
|
+
export const replicate = dual<
|
|
1759
|
+
(n: number) => <R, E, A>(self: Effect.Effect<R, E, A>) => Array<Effect.Effect<R, E, A>>,
|
|
1760
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, n: number) => Array<Effect.Effect<R, E, A>>
|
|
1761
|
+
>(2, (self, n) => Array.from({ length: n }, () => self))
|
|
1762
|
+
|
|
1763
|
+
/* @internal */
|
|
1764
|
+
export const replicateEffect = dual<
|
|
1765
|
+
{
|
|
1766
|
+
(n: number, options?: {
|
|
1767
|
+
readonly concurrency?: Concurrency
|
|
1768
|
+
readonly batching?: boolean | "inherit"
|
|
1769
|
+
readonly discard?: false
|
|
1770
|
+
}): <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, Array<A>>
|
|
1771
|
+
(n: number, options: {
|
|
1772
|
+
readonly concurrency?: Concurrency
|
|
1773
|
+
readonly batching?: boolean | "inherit"
|
|
1774
|
+
readonly discard: true
|
|
1775
|
+
}): <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, void>
|
|
1776
|
+
},
|
|
1777
|
+
{
|
|
1778
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, n: number, options?: {
|
|
1779
|
+
readonly concurrency?: Concurrency
|
|
1780
|
+
readonly batching?: boolean | "inherit"
|
|
1781
|
+
readonly discard?: false
|
|
1782
|
+
}): Effect.Effect<R, E, Array<A>>
|
|
1783
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, n: number, options: {
|
|
1784
|
+
readonly concurrency?: Concurrency
|
|
1785
|
+
readonly batching?: boolean | "inherit"
|
|
1786
|
+
readonly discard: true
|
|
1787
|
+
}): Effect.Effect<R, E, void>
|
|
1788
|
+
}
|
|
1789
|
+
>(
|
|
1790
|
+
(args) => core.isEffect(args[0]),
|
|
1791
|
+
(self, n, options) =>
|
|
1792
|
+
all(
|
|
1793
|
+
replicate(self, n),
|
|
1794
|
+
options as {
|
|
1795
|
+
readonly concurrency?: Concurrency
|
|
1796
|
+
readonly batching?: boolean | "inherit"
|
|
1797
|
+
readonly discard?: boolean
|
|
1798
|
+
}
|
|
1799
|
+
)
|
|
1800
|
+
)
|
|
1801
|
+
|
|
1802
|
+
// @ts-expect-error
|
|
1803
|
+
export const forEachOptions = dual<
|
|
1804
|
+
{
|
|
1805
|
+
<A, R, E, B>(f: (a: A, i: number) => Effect.Effect<R, E, B>, options?: {
|
|
1806
|
+
readonly concurrency?: Concurrency
|
|
1807
|
+
readonly batching?: boolean | "inherit"
|
|
1808
|
+
readonly discard?: false
|
|
1809
|
+
}): (self: Iterable<A>) => Effect.Effect<R, E, Array<B>>
|
|
1810
|
+
<A, R, E, B>(f: (a: A, i: number) => Effect.Effect<R, E, B>, options: {
|
|
1811
|
+
readonly concurrency?: Concurrency
|
|
1812
|
+
readonly batching?: boolean | "inherit"
|
|
1813
|
+
readonly discard: true
|
|
1814
|
+
}): (self: Iterable<A>) => Effect.Effect<R, E, void>
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
<A, R, E, B>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, B>, options?: {
|
|
1818
|
+
readonly concurrency?: Concurrency
|
|
1819
|
+
readonly batching?: boolean | "inherit"
|
|
1820
|
+
readonly discard?: false
|
|
1821
|
+
}): Effect.Effect<R, E, Array<B>>
|
|
1822
|
+
<A, R, E, B>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, B>, options: {
|
|
1823
|
+
readonly concurrency?: Concurrency
|
|
1824
|
+
readonly batching?: boolean | "inherit"
|
|
1825
|
+
readonly discard: true
|
|
1826
|
+
}): Effect.Effect<R, E, void>
|
|
1827
|
+
}
|
|
1828
|
+
>((args) => Predicate.isIterable(args[0]), (self, f, options) =>
|
|
1829
|
+
core.withFiberRuntime((r) => {
|
|
1830
|
+
const requestBatchingEnabled = options?.batching === true ||
|
|
1831
|
+
(options?.batching === "inherit" && r.getFiberRef(core.currentRequestBatching))
|
|
1832
|
+
|
|
1833
|
+
if (options?.discard) {
|
|
1834
|
+
return concurrency.match(
|
|
1835
|
+
options,
|
|
1836
|
+
() =>
|
|
1837
|
+
finalizersMask(ExecutionStrategy.sequential)((restore) =>
|
|
1838
|
+
requestBatchingEnabled
|
|
1839
|
+
? forEachBatchedDiscard(self, (a, i) => restore(f(a, i)))
|
|
1840
|
+
: core.forEachSequentialDiscard(self, (a, i) => restore(f(a, i)))
|
|
1841
|
+
),
|
|
1842
|
+
() =>
|
|
1843
|
+
finalizersMask(ExecutionStrategy.parallel)((restore) =>
|
|
1844
|
+
forEachParUnboundedDiscard(self, (a, i) => restore(f(a, i)), requestBatchingEnabled)
|
|
1845
|
+
),
|
|
1846
|
+
(n) =>
|
|
1847
|
+
finalizersMask(ExecutionStrategy.parallelN(n))((restore) =>
|
|
1848
|
+
forEachParNDiscard(self, n, (a, i) => restore(f(a, i)), requestBatchingEnabled)
|
|
1849
|
+
)
|
|
1850
|
+
)
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
return concurrency.match(
|
|
1854
|
+
options,
|
|
1855
|
+
() =>
|
|
1856
|
+
finalizersMask(ExecutionStrategy.sequential)((restore) =>
|
|
1857
|
+
requestBatchingEnabled
|
|
1858
|
+
? forEachParN(self, 1, (a, i) => restore(f(a, i)), true)
|
|
1859
|
+
: core.forEachSequential(self, (a, i) => restore(f(a, i)))
|
|
1860
|
+
),
|
|
1861
|
+
() =>
|
|
1862
|
+
finalizersMask(ExecutionStrategy.parallel)((restore) =>
|
|
1863
|
+
forEachParUnbounded(self, (a, i) => restore(f(a, i)), requestBatchingEnabled)
|
|
1864
|
+
),
|
|
1865
|
+
(n) =>
|
|
1866
|
+
finalizersMask(ExecutionStrategy.parallelN(n))((restore) =>
|
|
1867
|
+
forEachParN(self, n, (a, i) => restore(f(a, i)), requestBatchingEnabled)
|
|
1868
|
+
)
|
|
1869
|
+
)
|
|
1870
|
+
}))
|
|
1871
|
+
|
|
1872
|
+
/* @internal */
|
|
1873
|
+
export const forEachParUnbounded = <A, R, E, B>(
|
|
1874
|
+
self: Iterable<A>,
|
|
1875
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
1876
|
+
batching: boolean
|
|
1877
|
+
): Effect.Effect<R, E, Array<B>> =>
|
|
1878
|
+
core.suspend(() => {
|
|
1879
|
+
const as = RA.fromIterable(self)
|
|
1880
|
+
const array = new Array<B>(as.length)
|
|
1881
|
+
const fn = (a: A, i: number) => core.flatMap(f(a, i), (b) => core.sync(() => array[i] = b))
|
|
1882
|
+
return core.zipRight(forEachParUnboundedDiscard(as, fn, batching), core.succeed(array))
|
|
1883
|
+
})
|
|
1884
|
+
|
|
1885
|
+
const forEachBatchedDiscard = <R, E, A, _>(
|
|
1886
|
+
self: Iterable<A>,
|
|
1887
|
+
f: (a: A, i: number) => Effect.Effect<R, E, _>
|
|
1888
|
+
): Effect.Effect<R, E, void> =>
|
|
1889
|
+
core.suspend(() => {
|
|
1890
|
+
const as = RA.fromIterable(self)
|
|
1891
|
+
const size = as.length
|
|
1892
|
+
if (size === 0) {
|
|
1893
|
+
return core.unit
|
|
1894
|
+
} else if (size === 1) {
|
|
1895
|
+
return core.asUnit(f(as[0], 0))
|
|
1896
|
+
}
|
|
1897
|
+
const effects = as.map(f)
|
|
1898
|
+
const blocked = new Array<Effect.Blocked<R, E, void>>()
|
|
1899
|
+
const loop = (i: number): Effect.Effect<R, E, void> =>
|
|
1900
|
+
i === effects.length ?
|
|
1901
|
+
core.suspend(() => {
|
|
1902
|
+
if (blocked.length > 0) {
|
|
1903
|
+
const requests = blocked.map((b) => b.i0).reduce(_RequestBlock.par)
|
|
1904
|
+
return core.blocked(
|
|
1905
|
+
requests,
|
|
1906
|
+
forEachBatchedDiscard(blocked.map((b) => b.i1), identity)
|
|
1907
|
+
)
|
|
1908
|
+
}
|
|
1909
|
+
return core.unit
|
|
1910
|
+
}) :
|
|
1911
|
+
core.flatMapStep(effects[i], (s) => {
|
|
1912
|
+
if (s._op === "Blocked") {
|
|
1913
|
+
blocked.push(s)
|
|
1914
|
+
return loop(i + 1)
|
|
1915
|
+
} else if (s._op === "Failure") {
|
|
1916
|
+
return core.suspend(() => {
|
|
1917
|
+
if (blocked.length > 0) {
|
|
1918
|
+
const requests = blocked.map((b) => b.i0).reduce(_RequestBlock.par)
|
|
1919
|
+
return core.blocked(
|
|
1920
|
+
requests,
|
|
1921
|
+
core.flatMap(forEachBatchedDiscard(blocked.map((b) => b.i1), identity), () => s)
|
|
1922
|
+
)
|
|
1923
|
+
}
|
|
1924
|
+
return core.unit
|
|
1925
|
+
})
|
|
1926
|
+
} else {
|
|
1927
|
+
return loop(i + 1)
|
|
1928
|
+
}
|
|
1929
|
+
})
|
|
1930
|
+
return loop(0)
|
|
1931
|
+
})
|
|
1932
|
+
|
|
1933
|
+
/* @internal */
|
|
1934
|
+
export const forEachParUnboundedDiscard = <R, E, A, _>(
|
|
1935
|
+
self: Iterable<A>,
|
|
1936
|
+
f: (a: A, i: number) => Effect.Effect<R, E, _>,
|
|
1937
|
+
batching: boolean
|
|
1938
|
+
): Effect.Effect<R, E, void> =>
|
|
1939
|
+
core.suspend(() => {
|
|
1940
|
+
const as = RA.fromIterable(self)
|
|
1941
|
+
const size = as.length
|
|
1942
|
+
if (size === 0) {
|
|
1943
|
+
return core.unit
|
|
1944
|
+
} else if (size === 1) {
|
|
1945
|
+
return core.asUnit(f(as[0], 0))
|
|
1946
|
+
}
|
|
1947
|
+
return core.uninterruptibleMask((restore) => {
|
|
1948
|
+
const deferred = core.deferredUnsafeMake<void, Effect.Effect<any, any, any>>(FiberId.none)
|
|
1949
|
+
let ref = 0
|
|
1950
|
+
const residual: Array<Effect.Blocked<any, any, any>> = []
|
|
1951
|
+
const joinOrder: Array<Fiber.RuntimeFiber<any, any>> = []
|
|
1952
|
+
const process = core.transplant((graft) =>
|
|
1953
|
+
core.forEachSequential(as, (a, i) =>
|
|
1954
|
+
pipe(
|
|
1955
|
+
graft(pipe(
|
|
1956
|
+
core.suspend(() => restore((batching ? core.step : core.exit)(f(a, i)))),
|
|
1957
|
+
core.flatMap(
|
|
1958
|
+
(exit) => {
|
|
1959
|
+
switch (exit._op) {
|
|
1960
|
+
case "Failure": {
|
|
1961
|
+
if (residual.length > 0) {
|
|
1962
|
+
const requests = residual.map((blocked) => blocked.i0).reduce(_RequestBlock.par)
|
|
1963
|
+
const _continue = forEachParUnboundedDiscard(residual, (blocked) => blocked.i1, batching)
|
|
1964
|
+
return core.blocked(
|
|
1965
|
+
requests,
|
|
1966
|
+
core.matchCauseEffect(_continue, {
|
|
1967
|
+
onFailure: (cause) =>
|
|
1968
|
+
core.zipRight(
|
|
1969
|
+
core.deferredFail(deferred, void 0),
|
|
1970
|
+
core.failCause(internalCause.parallel(cause, exit.cause))
|
|
1971
|
+
),
|
|
1972
|
+
onSuccess: () =>
|
|
1973
|
+
core.zipRight(
|
|
1974
|
+
core.deferredFail(deferred, void 0),
|
|
1975
|
+
core.failCause(exit.cause)
|
|
1976
|
+
)
|
|
1977
|
+
})
|
|
1978
|
+
)
|
|
1979
|
+
}
|
|
1980
|
+
return core.zipRight(
|
|
1981
|
+
core.deferredFail(deferred, void 0),
|
|
1982
|
+
core.failCause(exit.cause)
|
|
1983
|
+
)
|
|
1984
|
+
}
|
|
1985
|
+
default: {
|
|
1986
|
+
if (exit._op === "Blocked") {
|
|
1987
|
+
residual.push(exit)
|
|
1988
|
+
}
|
|
1989
|
+
if (ref + 1 === size) {
|
|
1990
|
+
if (residual.length > 0) {
|
|
1991
|
+
const requests = residual.map((blocked) => blocked.i0).reduce(_RequestBlock.par)
|
|
1992
|
+
const _continue = forEachParUnboundedDiscard(residual, (blocked) => blocked.i1, batching)
|
|
1993
|
+
return core.deferredSucceed(deferred, core.blocked(requests, _continue))
|
|
1994
|
+
} else {
|
|
1995
|
+
core.deferredUnsafeDone(deferred, core.exitSucceed(core.exitUnit))
|
|
1996
|
+
}
|
|
1997
|
+
} else {
|
|
1998
|
+
ref = ref + 1
|
|
1999
|
+
}
|
|
2000
|
+
return core.unit
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
)
|
|
2005
|
+
)),
|
|
2006
|
+
forkDaemon,
|
|
2007
|
+
core.map((fiber) => {
|
|
2008
|
+
fiber.addObserver(() => {
|
|
2009
|
+
joinOrder.push(fiber)
|
|
2010
|
+
})
|
|
2011
|
+
return fiber
|
|
2012
|
+
})
|
|
2013
|
+
))
|
|
2014
|
+
)
|
|
2015
|
+
return core.flatMap(process, (fibers) =>
|
|
2016
|
+
core.matchCauseEffect(
|
|
2017
|
+
restore(core.deferredAwait(deferred)),
|
|
2018
|
+
{
|
|
2019
|
+
onFailure: (cause) =>
|
|
2020
|
+
core.flatMap(
|
|
2021
|
+
forEachParUnbounded(fibers, core.interruptFiber, batching),
|
|
2022
|
+
(exits) => {
|
|
2023
|
+
const exit = core.exitCollectAll(exits, { parallel: true })
|
|
2024
|
+
if (exit._tag === "Some" && core.exitIsFailure(exit.value)) {
|
|
2025
|
+
return core.failCause(
|
|
2026
|
+
internalCause.parallel(internalCause.stripFailures(cause), exit.value.i0)
|
|
2027
|
+
)
|
|
2028
|
+
} else {
|
|
2029
|
+
return core.failCause(internalCause.stripFailures(cause))
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
),
|
|
2033
|
+
onSuccess: (rest) =>
|
|
2034
|
+
core.flatMap(rest, () => core.forEachSequentialDiscard(joinOrder, (f) => f.inheritAll()))
|
|
2035
|
+
}
|
|
2036
|
+
))
|
|
2037
|
+
})
|
|
2038
|
+
})
|
|
2039
|
+
|
|
2040
|
+
/* @internal */
|
|
2041
|
+
export const forEachParN = <A, R, E, B>(
|
|
2042
|
+
self: Iterable<A>,
|
|
2043
|
+
n: number,
|
|
2044
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2045
|
+
batching: boolean
|
|
2046
|
+
): Effect.Effect<R, E, Array<B>> =>
|
|
2047
|
+
core.suspend(() => {
|
|
2048
|
+
const as = RA.fromIterable(self)
|
|
2049
|
+
const array = new Array<B>(as.length)
|
|
2050
|
+
const fn = (a: A, i: number) => core.map(f(a, i), (b) => array[i] = b)
|
|
2051
|
+
return core.zipRight(forEachParNDiscard(as, n, fn, batching), core.succeed(array))
|
|
2052
|
+
})
|
|
2053
|
+
|
|
2054
|
+
/* @internal */
|
|
2055
|
+
export const forEachParNDiscard = <A, R, E, _>(
|
|
2056
|
+
self: Iterable<A>,
|
|
2057
|
+
n: number,
|
|
2058
|
+
f: (a: A, i: number) => Effect.Effect<R, E, _>,
|
|
2059
|
+
batching: boolean
|
|
2060
|
+
): Effect.Effect<R, E, void> =>
|
|
2061
|
+
core.suspend(() => {
|
|
2062
|
+
let i = 0
|
|
2063
|
+
const iterator = self[Symbol.iterator]()
|
|
2064
|
+
const residual: Array<Effect.Blocked<any, any, any>> = []
|
|
2065
|
+
const worker: Effect.Effect<R, E, void> = core.flatMap(
|
|
2066
|
+
core.sync(() => iterator.next()),
|
|
2067
|
+
(next) =>
|
|
2068
|
+
next.done ?
|
|
2069
|
+
core.unit :
|
|
2070
|
+
core.flatMap((batching ? core.step : core.exit)(core.asUnit(f(next.value, i++))), (res) => {
|
|
2071
|
+
switch (res._op) {
|
|
2072
|
+
case "Blocked": {
|
|
2073
|
+
residual.push(res)
|
|
2074
|
+
return worker
|
|
2075
|
+
}
|
|
2076
|
+
case "Failure": {
|
|
2077
|
+
return res
|
|
2078
|
+
}
|
|
2079
|
+
case "Success":
|
|
2080
|
+
return worker
|
|
2081
|
+
}
|
|
2082
|
+
})
|
|
2083
|
+
)
|
|
2084
|
+
const effects: Array<Effect.Effect<R, E, void>> = []
|
|
2085
|
+
for (let i = 0; i < n; i++) {
|
|
2086
|
+
effects.push(worker)
|
|
2087
|
+
}
|
|
2088
|
+
return core.flatMap(core.exit(forEachParUnboundedDiscard(effects, identity, batching)), (exit) => {
|
|
2089
|
+
if (residual.length === 0) {
|
|
2090
|
+
return exit
|
|
2091
|
+
}
|
|
2092
|
+
const requests = residual.map((blocked) => blocked.i0).reduce(_RequestBlock.par)
|
|
2093
|
+
const _continue = forEachParNDiscard(residual, n, (blocked) => blocked.i1, batching)
|
|
2094
|
+
if (exit._tag === "Failure") {
|
|
2095
|
+
return core.blocked(
|
|
2096
|
+
requests,
|
|
2097
|
+
core.matchCauseEffect(_continue, {
|
|
2098
|
+
onFailure: (cause) => core.exitFailCause(internalCause.parallel(exit.cause, cause)),
|
|
2099
|
+
onSuccess: () => exit
|
|
2100
|
+
})
|
|
2101
|
+
)
|
|
2102
|
+
}
|
|
2103
|
+
return core.blocked(requests, _continue)
|
|
2104
|
+
})
|
|
2105
|
+
})
|
|
2106
|
+
|
|
2107
|
+
/* @internal */
|
|
2108
|
+
export const fork = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, never, Fiber.RuntimeFiber<E, A>> =>
|
|
2109
|
+
core.withFiberRuntime<R, never, Fiber.RuntimeFiber<E, A>>((state, status) =>
|
|
2110
|
+
core.succeed(unsafeFork(self, state, status.runtimeFlags))
|
|
2111
|
+
)
|
|
2112
|
+
|
|
2113
|
+
/* @internal */
|
|
2114
|
+
export const forkDaemon = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, never, Fiber.RuntimeFiber<E, A>> =>
|
|
2115
|
+
forkWithScopeOverride(self, fiberScope.globalScope)
|
|
2116
|
+
|
|
2117
|
+
/* @internal */
|
|
2118
|
+
export const forkWithErrorHandler = dual<
|
|
2119
|
+
<E, X>(
|
|
2120
|
+
handler: (e: E) => Effect.Effect<never, never, X>
|
|
2121
|
+
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, never, Fiber.RuntimeFiber<E, A>>,
|
|
2122
|
+
<R, E, A, X>(
|
|
2123
|
+
self: Effect.Effect<R, E, A>,
|
|
2124
|
+
handler: (e: E) => Effect.Effect<never, never, X>
|
|
2125
|
+
) => Effect.Effect<R, never, Fiber.RuntimeFiber<E, A>>
|
|
2126
|
+
>(2, (self, handler) =>
|
|
2127
|
+
fork(core.onError(self, (cause) => {
|
|
2128
|
+
const either = internalCause.failureOrCause(cause)
|
|
2129
|
+
switch (either._tag) {
|
|
2130
|
+
case "Left": {
|
|
2131
|
+
return handler(either.left)
|
|
2132
|
+
}
|
|
2133
|
+
case "Right": {
|
|
2134
|
+
return core.failCause(either.right)
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
})))
|
|
2138
|
+
|
|
2139
|
+
/** @internal */
|
|
2140
|
+
export const unsafeFork = <R, E, A, E2, B>(
|
|
2141
|
+
effect: Effect.Effect<R, E, A>,
|
|
2142
|
+
parentFiber: FiberRuntime<E2, B>,
|
|
2143
|
+
parentRuntimeFlags: RuntimeFlags.RuntimeFlags,
|
|
2144
|
+
overrideScope: fiberScope.FiberScope | null = null
|
|
2145
|
+
): FiberRuntime<E, A> => {
|
|
2146
|
+
const childFiber = unsafeMakeChildFiber(effect, parentFiber, parentRuntimeFlags, overrideScope)
|
|
2147
|
+
childFiber.resume(effect)
|
|
2148
|
+
return childFiber
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
/** @internal */
|
|
2152
|
+
export const unsafeMakeChildFiber = <R, E, A, E2, B>(
|
|
2153
|
+
effect: Effect.Effect<R, E, A>,
|
|
2154
|
+
parentFiber: FiberRuntime<E2, B>,
|
|
2155
|
+
parentRuntimeFlags: RuntimeFlags.RuntimeFlags,
|
|
2156
|
+
overrideScope: fiberScope.FiberScope | null = null
|
|
2157
|
+
): FiberRuntime<E, A> => {
|
|
2158
|
+
const childId = FiberId.unsafeMake()
|
|
2159
|
+
const parentFiberRefs = parentFiber.getFiberRefs()
|
|
2160
|
+
const childFiberRefs = fiberRefs.forkAs(parentFiberRefs, childId)
|
|
2161
|
+
const childFiber = new FiberRuntime<E, A>(childId, childFiberRefs, parentRuntimeFlags)
|
|
2162
|
+
const childContext = fiberRefs.getOrDefault(
|
|
2163
|
+
childFiberRefs,
|
|
2164
|
+
core.currentContext as unknown as FiberRef.FiberRef<Context.Context<R>>
|
|
2165
|
+
)
|
|
2166
|
+
const supervisor = childFiber._supervisor
|
|
2167
|
+
|
|
2168
|
+
supervisor.onStart(
|
|
2169
|
+
childContext,
|
|
2170
|
+
effect,
|
|
2171
|
+
Option.some(parentFiber),
|
|
2172
|
+
childFiber
|
|
2173
|
+
)
|
|
2174
|
+
|
|
2175
|
+
childFiber.addObserver((exit) => supervisor.onEnd(exit, childFiber))
|
|
2176
|
+
|
|
2177
|
+
const parentScope = overrideScope !== null ? overrideScope : pipe(
|
|
2178
|
+
parentFiber.getFiberRef(core.currentForkScopeOverride),
|
|
2179
|
+
Option.getOrElse(() => parentFiber.scope())
|
|
2180
|
+
)
|
|
2181
|
+
|
|
2182
|
+
parentScope.add(parentRuntimeFlags, childFiber)
|
|
2183
|
+
|
|
2184
|
+
return childFiber
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
/* @internal */
|
|
2188
|
+
const forkWithScopeOverride = <R, E, A>(
|
|
2189
|
+
self: Effect.Effect<R, E, A>,
|
|
2190
|
+
scopeOverride: fiberScope.FiberScope
|
|
2191
|
+
): Effect.Effect<R, never, Fiber.RuntimeFiber<E, A>> =>
|
|
2192
|
+
core.withFiberRuntime<R, never, Fiber.RuntimeFiber<E, A>>((parentFiber, parentStatus) =>
|
|
2193
|
+
core.succeed(unsafeFork(self, parentFiber, parentStatus.runtimeFlags, scopeOverride))
|
|
2194
|
+
)
|
|
2195
|
+
|
|
2196
|
+
/* @internal */
|
|
2197
|
+
export const mergeAll = dual<
|
|
2198
|
+
<Z, A>(zero: Z, f: (z: Z, a: A, i: number) => Z, options?: {
|
|
2199
|
+
readonly concurrency?: Concurrency
|
|
2200
|
+
readonly batching?: boolean | "inherit"
|
|
2201
|
+
}) => <R, E>(elements: Iterable<Effect.Effect<R, E, A>>) => Effect.Effect<R, E, Z>,
|
|
2202
|
+
<R, E, A, Z>(elements: Iterable<Effect.Effect<R, E, A>>, zero: Z, f: (z: Z, a: A, i: number) => Z, options?: {
|
|
2203
|
+
readonly concurrency?: Concurrency
|
|
2204
|
+
readonly batching?: boolean | "inherit"
|
|
2205
|
+
}) => Effect.Effect<R, E, Z>
|
|
2206
|
+
>(
|
|
2207
|
+
(args) => Predicate.isIterable(args[0]),
|
|
2208
|
+
<R, E, A, Z>(elements: Iterable<Effect.Effect<R, E, A>>, zero: Z, f: (z: Z, a: A, i: number) => Z, options?: {
|
|
2209
|
+
readonly concurrency?: Concurrency
|
|
2210
|
+
readonly batching?: boolean | "inherit"
|
|
2211
|
+
}) =>
|
|
2212
|
+
concurrency.matchSimple(
|
|
2213
|
+
options,
|
|
2214
|
+
() =>
|
|
2215
|
+
RA.fromIterable(elements).reduce(
|
|
2216
|
+
(acc, a, i) => core.zipWith(acc, a, (acc, a) => f(acc, a, i)),
|
|
2217
|
+
core.succeed(zero) as Effect.Effect<R, E, Z>
|
|
2218
|
+
),
|
|
2219
|
+
() =>
|
|
2220
|
+
core.flatMap(Ref.make(zero), (acc) =>
|
|
2221
|
+
core.flatMap(
|
|
2222
|
+
forEachOptions(
|
|
2223
|
+
elements,
|
|
2224
|
+
(effect, i) => core.flatMap(effect, (a) => Ref.update(acc, (b) => f(b, a, i))),
|
|
2225
|
+
options
|
|
2226
|
+
),
|
|
2227
|
+
() => Ref.get(acc)
|
|
2228
|
+
))
|
|
2229
|
+
)
|
|
2230
|
+
)
|
|
2231
|
+
|
|
2232
|
+
/* @internal */
|
|
2233
|
+
export const partition = dual<
|
|
2234
|
+
<R, E, A, B>(
|
|
2235
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2236
|
+
options?: {
|
|
2237
|
+
readonly concurrency?: Concurrency
|
|
2238
|
+
readonly batching?: boolean | "inherit"
|
|
2239
|
+
}
|
|
2240
|
+
) => (elements: Iterable<A>) => Effect.Effect<R, never, readonly [Array<E>, Array<B>]>,
|
|
2241
|
+
<R, E, A, B>(
|
|
2242
|
+
elements: Iterable<A>,
|
|
2243
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2244
|
+
options?: {
|
|
2245
|
+
readonly concurrency?: Concurrency
|
|
2246
|
+
readonly batching?: boolean | "inherit"
|
|
2247
|
+
}
|
|
2248
|
+
) => Effect.Effect<R, never, readonly [Array<E>, Array<B>]>
|
|
2249
|
+
>((args) => Predicate.isIterable(args[0]), (elements, f, options) =>
|
|
2250
|
+
pipe(
|
|
2251
|
+
forEachOptions(elements, (a, i) => core.either(f(a, i)), options),
|
|
2252
|
+
core.map((chunk) => core.partitionMap(chunk, identity))
|
|
2253
|
+
))
|
|
2254
|
+
|
|
2255
|
+
/* @internal */
|
|
2256
|
+
export const validateAll = dual<
|
|
2257
|
+
{
|
|
2258
|
+
<R, E, A, B>(
|
|
2259
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2260
|
+
options?: {
|
|
2261
|
+
readonly concurrency?: Concurrency
|
|
2262
|
+
readonly batching?: boolean | "inherit"
|
|
2263
|
+
readonly discard?: false
|
|
2264
|
+
}
|
|
2265
|
+
): (elements: Iterable<A>) => Effect.Effect<R, Array<E>, Array<B>>
|
|
2266
|
+
<R, E, A, B>(
|
|
2267
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2268
|
+
options: {
|
|
2269
|
+
readonly concurrency?: Concurrency
|
|
2270
|
+
readonly batching?: boolean | "inherit"
|
|
2271
|
+
readonly discard: true
|
|
2272
|
+
}
|
|
2273
|
+
): (elements: Iterable<A>) => Effect.Effect<R, Array<E>, void>
|
|
2274
|
+
},
|
|
2275
|
+
{
|
|
2276
|
+
<R, E, A, B>(
|
|
2277
|
+
elements: Iterable<A>,
|
|
2278
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2279
|
+
options?: {
|
|
2280
|
+
readonly concurrency?: Concurrency
|
|
2281
|
+
readonly batching?: boolean | "inherit"
|
|
2282
|
+
readonly discard?: false
|
|
2283
|
+
}
|
|
2284
|
+
): Effect.Effect<R, Array<E>, Array<B>>
|
|
2285
|
+
<R, E, A, B>(
|
|
2286
|
+
elements: Iterable<A>,
|
|
2287
|
+
f: (a: A, i: number) => Effect.Effect<R, E, B>,
|
|
2288
|
+
options: {
|
|
2289
|
+
readonly concurrency?: Concurrency
|
|
2290
|
+
readonly batching?: boolean | "inherit"
|
|
2291
|
+
readonly discard: true
|
|
2292
|
+
}
|
|
2293
|
+
): Effect.Effect<R, Array<E>, void>
|
|
2294
|
+
}
|
|
2295
|
+
>(
|
|
2296
|
+
(args) => Predicate.isIterable(args[0]),
|
|
2297
|
+
<R, E, A, B>(elements: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, B>, options?: {
|
|
2298
|
+
readonly concurrency?: Concurrency
|
|
2299
|
+
readonly batching?: boolean | "inherit"
|
|
2300
|
+
readonly discard?: boolean
|
|
2301
|
+
}): Effect.Effect<R, Array<E>, any> =>
|
|
2302
|
+
core.flatMap(
|
|
2303
|
+
partition(elements, f, {
|
|
2304
|
+
concurrency: options?.concurrency,
|
|
2305
|
+
batching: options?.batching
|
|
2306
|
+
}),
|
|
2307
|
+
([es, bs]) =>
|
|
2308
|
+
es.length === 0
|
|
2309
|
+
? options?.discard ? core.unit : core.succeed(bs)
|
|
2310
|
+
: core.fail(es)
|
|
2311
|
+
)
|
|
2312
|
+
)
|
|
2313
|
+
|
|
2314
|
+
/* @internal */
|
|
2315
|
+
export const raceAll = <R, E, A>(all: Iterable<Effect.Effect<R, E, A>>) => {
|
|
2316
|
+
const list = Chunk.fromIterable(all)
|
|
2317
|
+
if (!Chunk.isNonEmpty(list)) {
|
|
2318
|
+
return core.dieSync(() => internalCause.IllegalArgumentException(`Received an empty collection of effects`))
|
|
2319
|
+
}
|
|
2320
|
+
const self = Chunk.headNonEmpty(list)
|
|
2321
|
+
const effects = Chunk.tailNonEmpty(list)
|
|
2322
|
+
const inheritAll = (res: readonly [A, Fiber.Fiber<E, A>]) =>
|
|
2323
|
+
pipe(
|
|
2324
|
+
internalFiber.inheritAll(res[1]),
|
|
2325
|
+
core.as(res[0])
|
|
2326
|
+
)
|
|
2327
|
+
return pipe(
|
|
2328
|
+
core.deferredMake<E, readonly [A, Fiber.Fiber<E, A>]>(),
|
|
2329
|
+
core.flatMap((done) =>
|
|
2330
|
+
pipe(
|
|
2331
|
+
Ref.make(effects.length),
|
|
2332
|
+
core.flatMap((fails) =>
|
|
2333
|
+
core.uninterruptibleMask<R, E, A>((restore) =>
|
|
2334
|
+
pipe(
|
|
2335
|
+
fork(core.interruptible(self)),
|
|
2336
|
+
core.flatMap((head) =>
|
|
2337
|
+
pipe(
|
|
2338
|
+
effects,
|
|
2339
|
+
core.forEachSequential((effect) => fork(core.interruptible(effect))),
|
|
2340
|
+
core.map(Chunk.unsafeFromArray),
|
|
2341
|
+
core.map((tail) => pipe(tail, Chunk.prepend(head)) as Chunk.Chunk<Fiber.RuntimeFiber<E, A>>),
|
|
2342
|
+
core.tap((fibers) =>
|
|
2343
|
+
pipe(
|
|
2344
|
+
fibers,
|
|
2345
|
+
RA.reduce(core.unit, (effect, fiber) =>
|
|
2346
|
+
pipe(
|
|
2347
|
+
effect,
|
|
2348
|
+
core.zipRight(
|
|
2349
|
+
pipe(
|
|
2350
|
+
internalFiber._await(fiber),
|
|
2351
|
+
core.flatMap(raceAllArbiter(fibers, fiber, done, fails)),
|
|
2352
|
+
fork,
|
|
2353
|
+
core.asUnit
|
|
2354
|
+
)
|
|
2355
|
+
)
|
|
2356
|
+
))
|
|
2357
|
+
)
|
|
2358
|
+
),
|
|
2359
|
+
core.flatMap((fibers) =>
|
|
2360
|
+
pipe(
|
|
2361
|
+
restore(pipe(Deferred.await(done), core.flatMap(inheritAll))),
|
|
2362
|
+
core.onInterrupt(() =>
|
|
2363
|
+
pipe(
|
|
2364
|
+
fibers,
|
|
2365
|
+
RA.reduce(
|
|
2366
|
+
core.unit,
|
|
2367
|
+
(effect, fiber) => pipe(effect, core.zipLeft(core.interruptFiber(fiber)))
|
|
2368
|
+
)
|
|
2369
|
+
)
|
|
2370
|
+
)
|
|
2371
|
+
)
|
|
2372
|
+
)
|
|
2373
|
+
)
|
|
2374
|
+
)
|
|
2375
|
+
)
|
|
2376
|
+
)
|
|
2377
|
+
)
|
|
2378
|
+
)
|
|
2379
|
+
)
|
|
2380
|
+
)
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
/* @internal */
|
|
2384
|
+
const raceAllArbiter = <E, E1, A, A1>(
|
|
2385
|
+
fibers: Iterable<Fiber.Fiber<E | E1, A | A1>>,
|
|
2386
|
+
winner: Fiber.Fiber<E | E1, A | A1>,
|
|
2387
|
+
deferred: Deferred.Deferred<E | E1, readonly [A | A1, Fiber.Fiber<E | E1, A | A1>]>,
|
|
2388
|
+
fails: Ref.Ref<number>
|
|
2389
|
+
) =>
|
|
2390
|
+
(exit: Exit.Exit<E | E1, A | A1>): Effect.Effect<never, never, void> =>
|
|
2391
|
+
core.exitMatchEffect(exit, {
|
|
2392
|
+
onFailure: (cause) =>
|
|
2393
|
+
pipe(
|
|
2394
|
+
Ref.modify(fails, (fails) =>
|
|
2395
|
+
[
|
|
2396
|
+
fails === 0 ?
|
|
2397
|
+
pipe(core.deferredFailCause(deferred, cause), core.asUnit) :
|
|
2398
|
+
core.unit,
|
|
2399
|
+
fails - 1
|
|
2400
|
+
] as const),
|
|
2401
|
+
core.flatten
|
|
2402
|
+
),
|
|
2403
|
+
onSuccess: (value): Effect.Effect<never, never, void> =>
|
|
2404
|
+
pipe(
|
|
2405
|
+
core.deferredSucceed(deferred, [value, winner] as const),
|
|
2406
|
+
core.flatMap((set) =>
|
|
2407
|
+
set ?
|
|
2408
|
+
pipe(
|
|
2409
|
+
Chunk.fromIterable(fibers),
|
|
2410
|
+
RA.reduce(
|
|
2411
|
+
core.unit,
|
|
2412
|
+
(effect, fiber) =>
|
|
2413
|
+
fiber === winner ?
|
|
2414
|
+
effect :
|
|
2415
|
+
pipe(effect, core.zipLeft(core.interruptFiber(fiber)))
|
|
2416
|
+
)
|
|
2417
|
+
) :
|
|
2418
|
+
core.unit
|
|
2419
|
+
)
|
|
2420
|
+
)
|
|
2421
|
+
})
|
|
2422
|
+
|
|
2423
|
+
/* @internal */
|
|
2424
|
+
export const reduceEffect = dual<
|
|
2425
|
+
<R, E, A>(
|
|
2426
|
+
zero: Effect.Effect<R, E, A>,
|
|
2427
|
+
f: (acc: A, a: A, i: number) => A,
|
|
2428
|
+
options?: {
|
|
2429
|
+
readonly concurrency?: Concurrency
|
|
2430
|
+
readonly batching?: boolean | "inherit"
|
|
2431
|
+
}
|
|
2432
|
+
) => (elements: Iterable<Effect.Effect<R, E, A>>) => Effect.Effect<R, E, A>,
|
|
2433
|
+
<R, E, A>(
|
|
2434
|
+
elements: Iterable<Effect.Effect<R, E, A>>,
|
|
2435
|
+
zero: Effect.Effect<R, E, A>,
|
|
2436
|
+
f: (acc: A, a: A, i: number) => A,
|
|
2437
|
+
options?: {
|
|
2438
|
+
readonly concurrency?: Concurrency
|
|
2439
|
+
readonly batching?: boolean | "inherit"
|
|
2440
|
+
}
|
|
2441
|
+
) => Effect.Effect<R, E, A>
|
|
2442
|
+
>((args) => Predicate.isIterable(args[0]), <R, E, A>(
|
|
2443
|
+
elements: Iterable<Effect.Effect<R, E, A>>,
|
|
2444
|
+
zero: Effect.Effect<R, E, A>,
|
|
2445
|
+
f: (acc: A, a: A, i: number) => A,
|
|
2446
|
+
options?: {
|
|
2447
|
+
readonly concurrency?: Concurrency
|
|
2448
|
+
readonly batching?: boolean | "inherit"
|
|
2449
|
+
}
|
|
2450
|
+
) =>
|
|
2451
|
+
concurrency.matchSimple(
|
|
2452
|
+
options,
|
|
2453
|
+
() => RA.fromIterable(elements).reduce((acc, a, i) => core.zipWith(acc, a, (acc, a) => f(acc, a, i)), zero),
|
|
2454
|
+
() =>
|
|
2455
|
+
core.suspend(() =>
|
|
2456
|
+
pipe(
|
|
2457
|
+
mergeAll(
|
|
2458
|
+
[zero, ...elements],
|
|
2459
|
+
Option.none() as Option.Option<A>,
|
|
2460
|
+
(acc, elem, i) => {
|
|
2461
|
+
switch (acc._tag) {
|
|
2462
|
+
case "None": {
|
|
2463
|
+
return Option.some(elem)
|
|
2464
|
+
}
|
|
2465
|
+
case "Some": {
|
|
2466
|
+
return Option.some(f(acc.value, elem, i))
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
},
|
|
2470
|
+
options
|
|
2471
|
+
),
|
|
2472
|
+
core.map((option) => {
|
|
2473
|
+
switch (option._tag) {
|
|
2474
|
+
case "None": {
|
|
2475
|
+
throw new Error(
|
|
2476
|
+
"BUG: Effect.reduceEffect - please report an issue at https://github.com/Effect-TS/io/issues"
|
|
2477
|
+
)
|
|
2478
|
+
}
|
|
2479
|
+
case "Some": {
|
|
2480
|
+
return option.value
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
})
|
|
2484
|
+
)
|
|
2485
|
+
)
|
|
2486
|
+
))
|
|
2487
|
+
|
|
2488
|
+
/* @internal */
|
|
2489
|
+
export const parallelFinalizers = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> =>
|
|
2490
|
+
core.contextWithEffect((context) =>
|
|
2491
|
+
Option.match(Context.getOption(context, scopeTag), {
|
|
2492
|
+
onNone: () => self,
|
|
2493
|
+
onSome: (scope) => {
|
|
2494
|
+
switch (scope.strategy._tag) {
|
|
2495
|
+
case "Parallel":
|
|
2496
|
+
return self
|
|
2497
|
+
case "Sequential":
|
|
2498
|
+
case "ParallelN":
|
|
2499
|
+
return core.flatMap(
|
|
2500
|
+
core.scopeFork(scope, ExecutionStrategy.parallel),
|
|
2501
|
+
(inner) => scopeExtend(self, inner)
|
|
2502
|
+
)
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
})
|
|
2506
|
+
)
|
|
2507
|
+
|
|
2508
|
+
/* @internal */
|
|
2509
|
+
export const parallelNFinalizers =
|
|
2510
|
+
(parallelism: number) => <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> =>
|
|
2511
|
+
core.contextWithEffect((context) =>
|
|
2512
|
+
Option.match(Context.getOption(context, scopeTag), {
|
|
2513
|
+
onNone: () => self,
|
|
2514
|
+
onSome: (scope) => {
|
|
2515
|
+
if (scope.strategy._tag === "ParallelN" && scope.strategy.parallelism === parallelism) {
|
|
2516
|
+
return self
|
|
2517
|
+
}
|
|
2518
|
+
return core.flatMap(
|
|
2519
|
+
core.scopeFork(scope, ExecutionStrategy.parallelN(parallelism)),
|
|
2520
|
+
(inner) => scopeExtend(self, inner)
|
|
2521
|
+
)
|
|
2522
|
+
}
|
|
2523
|
+
})
|
|
2524
|
+
)
|
|
2525
|
+
|
|
2526
|
+
/* @internal */
|
|
2527
|
+
export const finalizersMask = (strategy: ExecutionStrategy.ExecutionStrategy) =>
|
|
2528
|
+
<R, E, A>(
|
|
2529
|
+
self: (restore: <R1, E1, A1>(self: Effect.Effect<R1, E1, A1>) => Effect.Effect<R1, E1, A1>) => Effect.Effect<R, E, A>
|
|
2530
|
+
): Effect.Effect<R, E, A> =>
|
|
2531
|
+
core.contextWithEffect((context) =>
|
|
2532
|
+
Option.match(Context.getOption(context, scopeTag), {
|
|
2533
|
+
onNone: () => self(identity),
|
|
2534
|
+
onSome: (scope) => {
|
|
2535
|
+
const patch = strategy._tag === "Parallel"
|
|
2536
|
+
? parallelFinalizers
|
|
2537
|
+
: strategy._tag === "Sequential"
|
|
2538
|
+
? sequentialFinalizers
|
|
2539
|
+
: parallelNFinalizers(strategy.parallelism)
|
|
2540
|
+
switch (scope.strategy._tag) {
|
|
2541
|
+
case "Parallel":
|
|
2542
|
+
return patch(self(parallelFinalizers))
|
|
2543
|
+
case "Sequential":
|
|
2544
|
+
return patch(self(sequentialFinalizers))
|
|
2545
|
+
case "ParallelN":
|
|
2546
|
+
return patch(self(parallelNFinalizers(scope.strategy.parallelism)))
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
})
|
|
2550
|
+
)
|
|
2551
|
+
|
|
2552
|
+
/* @internal */
|
|
2553
|
+
export const scopeWith = <R, E, A>(
|
|
2554
|
+
f: (scope: Scope.Scope) => Effect.Effect<R, E, A>
|
|
2555
|
+
): Effect.Effect<R | Scope.Scope, E, A> => core.flatMap(scopeTag, f)
|
|
2556
|
+
|
|
2557
|
+
/* @internal */
|
|
2558
|
+
export const scopedEffect = <R, E, A>(effect: Effect.Effect<R, E, A>): Effect.Effect<Exclude<R, Scope.Scope>, E, A> =>
|
|
2559
|
+
core.flatMap(scopeMake(), (scope) => scopeUse(scope)(effect))
|
|
2560
|
+
|
|
2561
|
+
/* @internal */
|
|
2562
|
+
export const sequentialFinalizers = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> =>
|
|
2563
|
+
core.contextWithEffect((context) =>
|
|
2564
|
+
Option.match(Context.getOption(context, scopeTag), {
|
|
2565
|
+
onNone: () => self,
|
|
2566
|
+
onSome: (scope) => {
|
|
2567
|
+
switch (scope.strategy._tag) {
|
|
2568
|
+
case "Sequential":
|
|
2569
|
+
return self
|
|
2570
|
+
case "Parallel":
|
|
2571
|
+
case "ParallelN":
|
|
2572
|
+
return core.flatMap(
|
|
2573
|
+
core.scopeFork(scope, ExecutionStrategy.sequential),
|
|
2574
|
+
(inner) => scopeExtend(self, inner)
|
|
2575
|
+
)
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
})
|
|
2579
|
+
)
|
|
2580
|
+
|
|
2581
|
+
/* @internal */
|
|
2582
|
+
export const tagMetricsScoped = (key: string, value: string): Effect.Effect<Scope.Scope, never, void> =>
|
|
2583
|
+
labelMetricsScoped([metricLabel.make(key, value)])
|
|
2584
|
+
|
|
2585
|
+
/* @internal */
|
|
2586
|
+
export const labelMetricsScoped = (
|
|
2587
|
+
labels: ReadonlyArray<MetricLabel.MetricLabel>
|
|
2588
|
+
): Effect.Effect<Scope.Scope, never, void> => labelMetricsScopedSet(HashSet.fromIterable(labels))
|
|
2589
|
+
|
|
2590
|
+
/* @internal */
|
|
2591
|
+
export const labelMetricsScopedSet = (
|
|
2592
|
+
labels: HashSet.HashSet<MetricLabel.MetricLabel>
|
|
2593
|
+
): Effect.Effect<Scope.Scope, never, void> =>
|
|
2594
|
+
fiberRefLocallyScopedWith(core.currentMetricLabels, (set) => pipe(set, HashSet.union(labels)))
|
|
2595
|
+
|
|
2596
|
+
/* @internal */
|
|
2597
|
+
export const using = dual<
|
|
2598
|
+
<A, R2, E2, A2>(
|
|
2599
|
+
use: (a: A) => Effect.Effect<R2, E2, A2>
|
|
2600
|
+
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<Exclude<R, Scope.Scope> | R2, E | E2, A2>,
|
|
2601
|
+
<R, E, A, R2, E2, A2>(
|
|
2602
|
+
self: Effect.Effect<R, E, A>,
|
|
2603
|
+
use: (a: A) => Effect.Effect<R2, E2, A2>
|
|
2604
|
+
) => Effect.Effect<Exclude<R, Scope.Scope> | R2, E | E2, A2>
|
|
2605
|
+
>(2, (self, use) =>
|
|
2606
|
+
core.acquireUseRelease(
|
|
2607
|
+
scopeMake(),
|
|
2608
|
+
(scope) => core.flatMap(scopeExtend(self, scope), use),
|
|
2609
|
+
(scope, exit) => core.scopeClose(scope, exit)
|
|
2610
|
+
))
|
|
2611
|
+
|
|
2612
|
+
/** @internal */
|
|
2613
|
+
export const validate = dual<
|
|
2614
|
+
<R1, E1, B>(
|
|
2615
|
+
that: Effect.Effect<R1, E1, B>,
|
|
2616
|
+
options?: {
|
|
2617
|
+
readonly concurrent?: boolean
|
|
2618
|
+
readonly batching?: boolean | "inherit"
|
|
2619
|
+
}
|
|
2620
|
+
) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E1, [A, B]>,
|
|
2621
|
+
<R, E, A, R1, E1, B>(
|
|
2622
|
+
self: Effect.Effect<R, E, A>,
|
|
2623
|
+
that: Effect.Effect<R1, E1, B>,
|
|
2624
|
+
options?: {
|
|
2625
|
+
readonly concurrent?: boolean
|
|
2626
|
+
readonly batching?: boolean | "inherit"
|
|
2627
|
+
}
|
|
2628
|
+
) => Effect.Effect<R | R1, E | E1, [A, B]>
|
|
2629
|
+
>(
|
|
2630
|
+
(args) => core.isEffect(args[1]),
|
|
2631
|
+
(self, that, options) => validateWith(self, that, (a, b) => [a, b], options)
|
|
2632
|
+
)
|
|
2633
|
+
|
|
2634
|
+
/** @internal */
|
|
2635
|
+
export const validateWith = dual<
|
|
2636
|
+
<A, R1, E1, B, C>(
|
|
2637
|
+
that: Effect.Effect<R1, E1, B>,
|
|
2638
|
+
f: (a: A, b: B) => C,
|
|
2639
|
+
options?: {
|
|
2640
|
+
readonly concurrent?: boolean
|
|
2641
|
+
readonly batching?: boolean | "inherit"
|
|
2642
|
+
}
|
|
2643
|
+
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E1, C>,
|
|
2644
|
+
<R, E, A, R1, E1, B, C>(
|
|
2645
|
+
self: Effect.Effect<R, E, A>,
|
|
2646
|
+
that: Effect.Effect<R1, E1, B>,
|
|
2647
|
+
f: (a: A, b: B) => C,
|
|
2648
|
+
options?: {
|
|
2649
|
+
readonly concurrent?: boolean
|
|
2650
|
+
readonly batching?: boolean | "inherit"
|
|
2651
|
+
}
|
|
2652
|
+
) => Effect.Effect<R | R1, E | E1, C>
|
|
2653
|
+
>((args) => core.isEffect(args[1]), (self, that, f, options) =>
|
|
2654
|
+
core.flatten(zipWithOptions(
|
|
2655
|
+
core.exit(self),
|
|
2656
|
+
core.exit(that),
|
|
2657
|
+
(ea, eb) =>
|
|
2658
|
+
core.exitZipWith(ea, eb, {
|
|
2659
|
+
onSuccess: f,
|
|
2660
|
+
onFailure: (ca, cb) => options?.concurrent ? internalCause.parallel(ca, cb) : internalCause.sequential(ca, cb)
|
|
2661
|
+
}),
|
|
2662
|
+
options
|
|
2663
|
+
)))
|
|
2664
|
+
|
|
2665
|
+
/* @internal */
|
|
2666
|
+
export const validateAllPar = dual<
|
|
2667
|
+
<R, E, A, B>(
|
|
2668
|
+
f: (a: A) => Effect.Effect<R, E, B>
|
|
2669
|
+
) => (elements: Iterable<A>) => Effect.Effect<R, Array<E>, Array<B>>,
|
|
2670
|
+
<R, E, A, B>(
|
|
2671
|
+
elements: Iterable<A>,
|
|
2672
|
+
f: (a: A) => Effect.Effect<R, E, B>
|
|
2673
|
+
) => Effect.Effect<R, Array<E>, Array<B>>
|
|
2674
|
+
>(2, (elements, f) =>
|
|
2675
|
+
core.flatMap(
|
|
2676
|
+
partition(elements, f),
|
|
2677
|
+
([es, bs]) =>
|
|
2678
|
+
es.length === 0
|
|
2679
|
+
? core.succeed(bs)
|
|
2680
|
+
: core.fail(es)
|
|
2681
|
+
))
|
|
2682
|
+
|
|
2683
|
+
/* @internal */
|
|
2684
|
+
export const validateAllParDiscard = dual<
|
|
2685
|
+
<R, E, A, B>(
|
|
2686
|
+
f: (a: A) => Effect.Effect<R, E, B>
|
|
2687
|
+
) => (elements: Iterable<A>) => Effect.Effect<R, Array<E>, void>,
|
|
2688
|
+
<R, E, A, B>(elements: Iterable<A>, f: (a: A) => Effect.Effect<R, E, B>) => Effect.Effect<R, Array<E>, void>
|
|
2689
|
+
>(2, (elements, f) =>
|
|
2690
|
+
core.flatMap(
|
|
2691
|
+
partition(elements, f),
|
|
2692
|
+
([es, _]) =>
|
|
2693
|
+
es.length === 0
|
|
2694
|
+
? core.unit
|
|
2695
|
+
: core.fail(es)
|
|
2696
|
+
))
|
|
2697
|
+
|
|
2698
|
+
/* @internal */
|
|
2699
|
+
export const validateFirst = dual<
|
|
2700
|
+
<R, E, A, B>(f: (a: A, i: number) => Effect.Effect<R, E, B>, options?: {
|
|
2701
|
+
readonly concurrency?: Concurrency
|
|
2702
|
+
readonly batching?: boolean | "inherit"
|
|
2703
|
+
}) => (elements: Iterable<A>) => Effect.Effect<R, Array<E>, B>,
|
|
2704
|
+
<R, E, A, B>(elements: Iterable<A>, f: (a: A, i: number) => Effect.Effect<R, E, B>, options?: {
|
|
2705
|
+
readonly concurrency?: Concurrency
|
|
2706
|
+
readonly batching?: boolean | "inherit"
|
|
2707
|
+
}) => Effect.Effect<R, Array<E>, B>
|
|
2708
|
+
>(
|
|
2709
|
+
(args) => Predicate.isIterable(args[0]),
|
|
2710
|
+
(elements, f, options) => core.flip(forEachOptions(elements, (a, i) => core.flip(f(a, i)), options))
|
|
2711
|
+
)
|
|
2712
|
+
|
|
2713
|
+
/* @internal */
|
|
2714
|
+
export const withClockScoped = <A extends Clock.Clock>(value: A) =>
|
|
2715
|
+
fiberRefLocallyScopedWith(defaultServices.currentServices, Context.add(clock.clockTag, value))
|
|
2716
|
+
|
|
2717
|
+
/* @internal */
|
|
2718
|
+
export const withConfigProviderScoped = (value: ConfigProvider) =>
|
|
2719
|
+
fiberRefLocallyScopedWith(defaultServices.currentServices, Context.add(configProviderTag, value))
|
|
2720
|
+
|
|
2721
|
+
/* @internal */
|
|
2722
|
+
export const withEarlyRelease = <R, E, A>(
|
|
2723
|
+
self: Effect.Effect<R, E, A>
|
|
2724
|
+
): Effect.Effect<R | Scope.Scope, E, readonly [Effect.Effect<never, never, void>, A]> =>
|
|
2725
|
+
scopeWith((parent) =>
|
|
2726
|
+
core.flatMap(core.scopeFork(parent, executionStrategy.sequential), (child) =>
|
|
2727
|
+
pipe(
|
|
2728
|
+
self,
|
|
2729
|
+
scopeExtend(child),
|
|
2730
|
+
core.map((value) =>
|
|
2731
|
+
[
|
|
2732
|
+
core.fiberIdWith((fiberId) => core.scopeClose(child, core.exitInterrupt(fiberId))),
|
|
2733
|
+
value
|
|
2734
|
+
] as const
|
|
2735
|
+
)
|
|
2736
|
+
))
|
|
2737
|
+
)
|
|
2738
|
+
|
|
2739
|
+
/** @internal */
|
|
2740
|
+
export const zipOptions = dual<
|
|
2741
|
+
<R2, E2, A2>(
|
|
2742
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2743
|
+
options?: {
|
|
2744
|
+
readonly concurrent?: boolean
|
|
2745
|
+
readonly batching?: boolean | "inherit"
|
|
2746
|
+
}
|
|
2747
|
+
) => <R, E, A>(
|
|
2748
|
+
self: Effect.Effect<R, E, A>
|
|
2749
|
+
) => Effect.Effect<R | R2, E | E2, [A, A2]>,
|
|
2750
|
+
<R, E, A, R2, E2, A2>(
|
|
2751
|
+
self: Effect.Effect<R, E, A>,
|
|
2752
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2753
|
+
options?: {
|
|
2754
|
+
readonly concurrent?: boolean
|
|
2755
|
+
readonly batching?: boolean | "inherit"
|
|
2756
|
+
}
|
|
2757
|
+
) => Effect.Effect<R | R2, E | E2, [A, A2]>
|
|
2758
|
+
>((args) => core.isEffect(args[1]), (
|
|
2759
|
+
self,
|
|
2760
|
+
that,
|
|
2761
|
+
options
|
|
2762
|
+
) => zipWithOptions(self, that, (a, b) => [a, b], options))
|
|
2763
|
+
|
|
2764
|
+
/** @internal */
|
|
2765
|
+
export const zipLeftOptions = dual<
|
|
2766
|
+
<R2, E2, A2>(
|
|
2767
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2768
|
+
options?: {
|
|
2769
|
+
readonly concurrent?: boolean
|
|
2770
|
+
readonly batching?: boolean | "inherit"
|
|
2771
|
+
}
|
|
2772
|
+
) => <R, E, A>(
|
|
2773
|
+
self: Effect.Effect<R, E, A>
|
|
2774
|
+
) => Effect.Effect<R | R2, E | E2, A>,
|
|
2775
|
+
<R, E, A, R2, E2, A2>(
|
|
2776
|
+
self: Effect.Effect<R, E, A>,
|
|
2777
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2778
|
+
options?: {
|
|
2779
|
+
readonly concurrent?: boolean
|
|
2780
|
+
readonly batching?: boolean | "inherit"
|
|
2781
|
+
}
|
|
2782
|
+
) => Effect.Effect<R | R2, E | E2, A>
|
|
2783
|
+
>(
|
|
2784
|
+
(args) => core.isEffect(args[1]),
|
|
2785
|
+
(self, that, options) => zipWithOptions(self, that, (a, _) => a, options)
|
|
2786
|
+
)
|
|
2787
|
+
|
|
2788
|
+
/** @internal */
|
|
2789
|
+
export const zipRightOptions = dual<
|
|
2790
|
+
<R2, E2, A2>(
|
|
2791
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2792
|
+
options?: {
|
|
2793
|
+
readonly concurrent?: boolean
|
|
2794
|
+
readonly batching?: boolean | "inherit"
|
|
2795
|
+
}
|
|
2796
|
+
) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A2>,
|
|
2797
|
+
<R, E, A, R2, E2, A2>(
|
|
2798
|
+
self: Effect.Effect<R, E, A>,
|
|
2799
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2800
|
+
options?: {
|
|
2801
|
+
readonly concurrent?: boolean
|
|
2802
|
+
readonly batching?: boolean | "inherit"
|
|
2803
|
+
}
|
|
2804
|
+
) => Effect.Effect<R | R2, E | E2, A2>
|
|
2805
|
+
>((args) => core.isEffect(args[1]), (self, that, options) => zipWithOptions(self, that, (_, b) => b, options))
|
|
2806
|
+
|
|
2807
|
+
/** @internal */
|
|
2808
|
+
export const zipWithOptions = dual<
|
|
2809
|
+
<R2, E2, A2, A, B>(
|
|
2810
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2811
|
+
f: (a: A, b: A2) => B,
|
|
2812
|
+
options?: {
|
|
2813
|
+
readonly concurrent?: boolean
|
|
2814
|
+
readonly batching?: boolean | "inherit"
|
|
2815
|
+
}
|
|
2816
|
+
) => <R, E>(
|
|
2817
|
+
self: Effect.Effect<R, E, A>
|
|
2818
|
+
) => Effect.Effect<R | R2, E | E2, B>,
|
|
2819
|
+
<R, E, A, R2, E2, A2, B>(
|
|
2820
|
+
self: Effect.Effect<R, E, A>,
|
|
2821
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2822
|
+
f: (a: A, b: A2) => B,
|
|
2823
|
+
options?: {
|
|
2824
|
+
readonly concurrent?: boolean
|
|
2825
|
+
readonly batching?: boolean | "inherit"
|
|
2826
|
+
}
|
|
2827
|
+
) => Effect.Effect<R | R2, E | E2, B>
|
|
2828
|
+
>((args) => core.isEffect(args[1]), <R, E, A, R2, E2, A2, B>(
|
|
2829
|
+
self: Effect.Effect<R, E, A>,
|
|
2830
|
+
that: Effect.Effect<R2, E2, A2>,
|
|
2831
|
+
f: (a: A, b: A2) => B,
|
|
2832
|
+
options?: {
|
|
2833
|
+
readonly concurrent?: boolean
|
|
2834
|
+
readonly batching?: boolean | "inherit"
|
|
2835
|
+
}
|
|
2836
|
+
): Effect.Effect<R | R2, E | E2, B> =>
|
|
2837
|
+
core.map(
|
|
2838
|
+
all([self, that], {
|
|
2839
|
+
concurrency: options?.concurrent ? 2 : 1,
|
|
2840
|
+
batching: options?.batching
|
|
2841
|
+
}),
|
|
2842
|
+
([a, a2]) => f(a, a2)
|
|
2843
|
+
))
|
|
2844
|
+
|
|
2845
|
+
/* @internal */
|
|
2846
|
+
export const withRuntimeFlagsScoped = (
|
|
2847
|
+
update: RuntimeFlagsPatch.RuntimeFlagsPatch
|
|
2848
|
+
): Effect.Effect<Scope.Scope, never, void> => {
|
|
2849
|
+
if (update === RuntimeFlagsPatch.empty) {
|
|
2850
|
+
return core.unit
|
|
2851
|
+
}
|
|
2852
|
+
return pipe(
|
|
2853
|
+
core.runtimeFlags,
|
|
2854
|
+
core.flatMap((runtimeFlags) => {
|
|
2855
|
+
const updatedRuntimeFlags = _runtimeFlags.patch(runtimeFlags, update)
|
|
2856
|
+
const revertRuntimeFlags = _runtimeFlags.diff(updatedRuntimeFlags, runtimeFlags)
|
|
2857
|
+
return pipe(
|
|
2858
|
+
core.updateRuntimeFlags(update),
|
|
2859
|
+
core.zipRight(addFinalizer(() => core.updateRuntimeFlags(revertRuntimeFlags))),
|
|
2860
|
+
core.asUnit
|
|
2861
|
+
)
|
|
2862
|
+
}),
|
|
2863
|
+
core.uninterruptible
|
|
2864
|
+
)
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
// circular with ReleaseMap
|
|
2868
|
+
|
|
2869
|
+
/* @internal */
|
|
2870
|
+
export const releaseMapReleaseAll = (
|
|
2871
|
+
strategy: ExecutionStrategy.ExecutionStrategy,
|
|
2872
|
+
exit: Exit.Exit<unknown, unknown>
|
|
2873
|
+
) =>
|
|
2874
|
+
(self: core.ReleaseMap): Effect.Effect<never, never, void> =>
|
|
2875
|
+
core.suspend(() => {
|
|
2876
|
+
switch (self.state._tag) {
|
|
2877
|
+
case "Exited": {
|
|
2878
|
+
return core.unit
|
|
2879
|
+
}
|
|
2880
|
+
case "Running": {
|
|
2881
|
+
const finalizersMap = self.state.finalizers
|
|
2882
|
+
const update = self.state.update
|
|
2883
|
+
const finalizers = Array.from(finalizersMap.keys()).sort((a, b) => b - a).map((key) => finalizersMap.get(key)!)
|
|
2884
|
+
self.state = { _tag: "Exited", nextKey: self.state.nextKey, exit, update }
|
|
2885
|
+
return executionStrategy.isSequential(strategy) ?
|
|
2886
|
+
pipe(
|
|
2887
|
+
finalizers,
|
|
2888
|
+
core.forEachSequential((fin) => core.exit(update(fin)(exit))),
|
|
2889
|
+
core.flatMap((results) =>
|
|
2890
|
+
pipe(
|
|
2891
|
+
core.exitCollectAll(results),
|
|
2892
|
+
Option.map(core.exitAsUnit),
|
|
2893
|
+
Option.getOrElse(() => core.exitUnit)
|
|
2894
|
+
)
|
|
2895
|
+
)
|
|
2896
|
+
) :
|
|
2897
|
+
executionStrategy.isParallel(strategy) ?
|
|
2898
|
+
pipe(
|
|
2899
|
+
forEachParUnbounded(finalizers, (fin) => core.exit(update(fin)(exit)), false),
|
|
2900
|
+
core.flatMap((results) =>
|
|
2901
|
+
pipe(
|
|
2902
|
+
core.exitCollectAll(results, { parallel: true }),
|
|
2903
|
+
Option.map(core.exitAsUnit),
|
|
2904
|
+
Option.getOrElse(() => core.exitUnit)
|
|
2905
|
+
)
|
|
2906
|
+
)
|
|
2907
|
+
) :
|
|
2908
|
+
pipe(
|
|
2909
|
+
forEachParN(finalizers, strategy.parallelism, (fin) => core.exit(update(fin)(exit)), false),
|
|
2910
|
+
core.flatMap((results) =>
|
|
2911
|
+
pipe(
|
|
2912
|
+
core.exitCollectAll(results, { parallel: true }),
|
|
2913
|
+
Option.map(core.exitAsUnit),
|
|
2914
|
+
Option.getOrElse(() => core.exitUnit)
|
|
2915
|
+
)
|
|
2916
|
+
)
|
|
2917
|
+
)
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
})
|
|
2921
|
+
|
|
2922
|
+
// circular with Scope
|
|
2923
|
+
|
|
2924
|
+
/** @internal */
|
|
2925
|
+
export const scopeTag = Context.Tag<Scope.Scope>(core.ScopeTypeId)
|
|
2926
|
+
|
|
2927
|
+
/* @internal */
|
|
2928
|
+
export const scope: Effect.Effect<Scope.Scope, never, Scope.Scope> = scopeTag
|
|
2929
|
+
|
|
2930
|
+
/* @internal */
|
|
2931
|
+
export const scopeMake = (
|
|
2932
|
+
strategy: ExecutionStrategy.ExecutionStrategy = executionStrategy.sequential
|
|
2933
|
+
): Effect.Effect<never, never, Scope.Scope.Closeable> =>
|
|
2934
|
+
core.map(core.releaseMapMake, (rm): Scope.Scope.Closeable => ({
|
|
2935
|
+
[core.ScopeTypeId]: core.ScopeTypeId,
|
|
2936
|
+
[core.CloseableScopeTypeId]: core.CloseableScopeTypeId,
|
|
2937
|
+
strategy,
|
|
2938
|
+
pipe() {
|
|
2939
|
+
return pipeArguments(this, arguments)
|
|
2940
|
+
},
|
|
2941
|
+
fork: (strategy) =>
|
|
2942
|
+
core.uninterruptible(
|
|
2943
|
+
pipe(
|
|
2944
|
+
scopeMake(strategy),
|
|
2945
|
+
core.flatMap((scope) =>
|
|
2946
|
+
pipe(
|
|
2947
|
+
core.releaseMapAdd(rm, (exit) => core.scopeClose(scope, exit)),
|
|
2948
|
+
core.tap((fin) => core.scopeAddFinalizerExit(scope, fin)),
|
|
2949
|
+
core.as(scope)
|
|
2950
|
+
)
|
|
2951
|
+
)
|
|
2952
|
+
)
|
|
2953
|
+
),
|
|
2954
|
+
close: (exit) => core.asUnit(releaseMapReleaseAll(strategy, exit)(rm)),
|
|
2955
|
+
addFinalizer: (fin) => core.asUnit(core.releaseMapAdd(fin)(rm))
|
|
2956
|
+
}))
|
|
2957
|
+
|
|
2958
|
+
/* @internal */
|
|
2959
|
+
export const scopeExtend = dual<
|
|
2960
|
+
(scope: Scope.Scope) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<Exclude<R, Scope.Scope>, E, A>,
|
|
2961
|
+
<R, E, A>(effect: Effect.Effect<R, E, A>, scope: Scope.Scope) => Effect.Effect<Exclude<R, Scope.Scope>, E, A>
|
|
2962
|
+
>(
|
|
2963
|
+
2,
|
|
2964
|
+
<R, E, A>(effect: Effect.Effect<R, E, A>, scope: Scope.Scope) =>
|
|
2965
|
+
core.mapInputContext<Exclude<R, Scope.Scope>, R, E, A>(
|
|
2966
|
+
effect,
|
|
2967
|
+
// @ts-expect-error
|
|
2968
|
+
Context.merge(Context.make(scopeTag, scope))
|
|
2969
|
+
)
|
|
2970
|
+
)
|
|
2971
|
+
|
|
2972
|
+
/* @internal */
|
|
2973
|
+
export const scopeUse = dual<
|
|
2974
|
+
(
|
|
2975
|
+
scope: Scope.Scope.Closeable
|
|
2976
|
+
) => <R, E, A>(effect: Effect.Effect<R, E, A>) => Effect.Effect<Exclude<R, Scope.Scope>, E, A>,
|
|
2977
|
+
<R, E, A>(
|
|
2978
|
+
effect: Effect.Effect<R, E, A>,
|
|
2979
|
+
scope: Scope.Scope.Closeable
|
|
2980
|
+
) => Effect.Effect<Exclude<R, Scope.Scope>, E, A>
|
|
2981
|
+
>(2, (effect, scope) =>
|
|
2982
|
+
pipe(
|
|
2983
|
+
effect,
|
|
2984
|
+
scopeExtend(scope),
|
|
2985
|
+
core.onExit((exit) => scope.close(exit))
|
|
2986
|
+
))
|
|
2987
|
+
|
|
2988
|
+
// circular with Supervisor
|
|
2989
|
+
|
|
2990
|
+
/** @internal */
|
|
2991
|
+
export const fiberRefUnsafeMakeSupervisor = (
|
|
2992
|
+
initial: Supervisor.Supervisor<any>
|
|
2993
|
+
): FiberRef.FiberRef<Supervisor.Supervisor<any>> =>
|
|
2994
|
+
core.fiberRefUnsafeMakePatch(initial, {
|
|
2995
|
+
differ: SupervisorPatch.differ,
|
|
2996
|
+
fork: SupervisorPatch.empty
|
|
2997
|
+
})
|
|
2998
|
+
|
|
2999
|
+
// circular with FiberRef
|
|
3000
|
+
|
|
3001
|
+
/* @internal */
|
|
3002
|
+
export const fiberRefLocallyScoped = dual<
|
|
3003
|
+
<A>(value: A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<Scope.Scope, never, void>,
|
|
3004
|
+
<A>(self: FiberRef.FiberRef<A>, value: A) => Effect.Effect<Scope.Scope, never, void>
|
|
3005
|
+
>(2, (self, value) =>
|
|
3006
|
+
core.asUnit(
|
|
3007
|
+
acquireRelease(
|
|
3008
|
+
core.flatMap(
|
|
3009
|
+
core.fiberRefGet(self),
|
|
3010
|
+
(oldValue) => core.as(core.fiberRefSet(self, value), oldValue)
|
|
3011
|
+
),
|
|
3012
|
+
(oldValue) => core.fiberRefSet(self, oldValue)
|
|
3013
|
+
)
|
|
3014
|
+
))
|
|
3015
|
+
|
|
3016
|
+
/* @internal */
|
|
3017
|
+
export const fiberRefLocallyScopedWith = dual<
|
|
3018
|
+
<A>(f: (a: A) => A) => (self: FiberRef.FiberRef<A>) => Effect.Effect<Scope.Scope, never, void>,
|
|
3019
|
+
<A>(self: FiberRef.FiberRef<A>, f: (a: A) => A) => Effect.Effect<Scope.Scope, never, void>
|
|
3020
|
+
>(2, (self, f) => core.fiberRefGetWith(self, (a) => fiberRefLocallyScoped(self, f(a))))
|
|
3021
|
+
|
|
3022
|
+
/* @internal */
|
|
3023
|
+
export const fiberRefMake = <A>(
|
|
3024
|
+
initial: A,
|
|
3025
|
+
options?: {
|
|
3026
|
+
readonly fork?: (a: A) => A
|
|
3027
|
+
readonly join?: (left: A, right: A) => A
|
|
3028
|
+
}
|
|
3029
|
+
): Effect.Effect<Scope.Scope, never, FiberRef.FiberRef<A>> =>
|
|
3030
|
+
fiberRefMakeWith(() => core.fiberRefUnsafeMake(initial, options))
|
|
3031
|
+
|
|
3032
|
+
/* @internal */
|
|
3033
|
+
export const fiberRefMakeWith = <Value>(
|
|
3034
|
+
ref: LazyArg<FiberRef.FiberRef<Value>>
|
|
3035
|
+
): Effect.Effect<Scope.Scope, never, FiberRef.FiberRef<Value>> =>
|
|
3036
|
+
acquireRelease(
|
|
3037
|
+
core.tap(core.sync(ref), (ref) => core.fiberRefUpdate(ref, identity)),
|
|
3038
|
+
(fiberRef) => core.fiberRefDelete(fiberRef)
|
|
3039
|
+
)
|
|
3040
|
+
|
|
3041
|
+
/* @internal */
|
|
3042
|
+
export const fiberRefMakeContext = <A>(
|
|
3043
|
+
initial: Context.Context<A>
|
|
3044
|
+
): Effect.Effect<Scope.Scope, never, FiberRef.FiberRef<Context.Context<A>>> =>
|
|
3045
|
+
fiberRefMakeWith(() => core.fiberRefUnsafeMakeContext(initial))
|
|
3046
|
+
|
|
3047
|
+
/* @internal */
|
|
3048
|
+
export const fiberRefMakeRuntimeFlags = (
|
|
3049
|
+
initial: RuntimeFlags.RuntimeFlags
|
|
3050
|
+
): Effect.Effect<Scope.Scope, never, FiberRef.FiberRef<RuntimeFlags.RuntimeFlags>> =>
|
|
3051
|
+
fiberRefMakeWith(() => core.fiberRefUnsafeMakeRuntimeFlags(initial))
|
|
3052
|
+
|
|
3053
|
+
/** @internal */
|
|
3054
|
+
export const currentRuntimeFlags: FiberRef.FiberRef<RuntimeFlags.RuntimeFlags> = core.fiberRefUnsafeMakeRuntimeFlags(
|
|
3055
|
+
_runtimeFlags.none
|
|
3056
|
+
)
|
|
3057
|
+
|
|
3058
|
+
/** @internal */
|
|
3059
|
+
export const currentSupervisor: FiberRef.FiberRef<Supervisor.Supervisor<any>> = fiberRefUnsafeMakeSupervisor(
|
|
3060
|
+
supervisor.none
|
|
3061
|
+
)
|
|
3062
|
+
|
|
3063
|
+
// circular with Fiber
|
|
3064
|
+
|
|
3065
|
+
/* @internal */
|
|
3066
|
+
export const fiberAwaitAll = (fibers: Iterable<Fiber.Fiber<any, any>>): Effect.Effect<never, never, void> =>
|
|
3067
|
+
core.asUnit(internalFiber._await(fiberAll(fibers)))
|
|
3068
|
+
|
|
3069
|
+
/** @internal */
|
|
3070
|
+
export const fiberAll = <E, A>(fibers: Iterable<Fiber.Fiber<E, A>>): Fiber.Fiber<E, Array<A>> => ({
|
|
3071
|
+
[internalFiber.FiberTypeId]: internalFiber.fiberVariance,
|
|
3072
|
+
id: () => RA.fromIterable(fibers).reduce((id, fiber) => FiberId.combine(id, fiber.id()), FiberId.none),
|
|
3073
|
+
await: () => core.exit(forEachParUnbounded(fibers, (fiber) => core.flatten(fiber.await()), false)),
|
|
3074
|
+
children: () => core.map(forEachParUnbounded(fibers, (fiber) => fiber.children(), false), RA.flatten),
|
|
3075
|
+
inheritAll: () => core.forEachSequentialDiscard(fibers, (fiber) => fiber.inheritAll()),
|
|
3076
|
+
poll: () =>
|
|
3077
|
+
core.map(
|
|
3078
|
+
core.forEachSequential(fibers, (fiber) => fiber.poll()),
|
|
3079
|
+
RA.reduceRight(
|
|
3080
|
+
Option.some<Exit.Exit<E, Array<A>>>(core.exitSucceed(new Array())),
|
|
3081
|
+
(optionB, optionA) => {
|
|
3082
|
+
switch (optionA._tag) {
|
|
3083
|
+
case "None": {
|
|
3084
|
+
return Option.none()
|
|
3085
|
+
}
|
|
3086
|
+
case "Some": {
|
|
3087
|
+
switch (optionB._tag) {
|
|
3088
|
+
case "None": {
|
|
3089
|
+
return Option.none()
|
|
3090
|
+
}
|
|
3091
|
+
case "Some": {
|
|
3092
|
+
return Option.some(
|
|
3093
|
+
core.exitZipWith(optionA.value, optionB.value, {
|
|
3094
|
+
onSuccess: (a, chunk) => [a, ...chunk],
|
|
3095
|
+
onFailure: internalCause.parallel
|
|
3096
|
+
})
|
|
3097
|
+
)
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
)
|
|
3104
|
+
),
|
|
3105
|
+
interruptAsFork: (fiberId) => core.forEachSequentialDiscard(fibers, (fiber) => fiber.interruptAsFork(fiberId)),
|
|
3106
|
+
pipe() {
|
|
3107
|
+
return pipeArguments(this, arguments)
|
|
3108
|
+
}
|
|
3109
|
+
})
|
|
3110
|
+
|
|
3111
|
+
/* @internal */
|
|
3112
|
+
export const fiberInterruptFork = <E, A>(self: Fiber.Fiber<E, A>): Effect.Effect<never, never, void> =>
|
|
3113
|
+
core.asUnit(forkDaemon(core.interruptFiber(self)))
|
|
3114
|
+
|
|
3115
|
+
/* @internal */
|
|
3116
|
+
export const fiberJoinAll = <E, A>(fibers: Iterable<Fiber.Fiber<E, A>>): Effect.Effect<never, E, void> =>
|
|
3117
|
+
core.asUnit(internalFiber.join(fiberAll(fibers)))
|
|
3118
|
+
|
|
3119
|
+
/* @internal */
|
|
3120
|
+
export const fiberScoped = <E, A>(self: Fiber.Fiber<E, A>): Effect.Effect<Scope.Scope, never, Fiber.Fiber<E, A>> =>
|
|
3121
|
+
acquireRelease(core.succeed(self), core.interruptFiber)
|
|
3122
|
+
|
|
3123
|
+
//
|
|
3124
|
+
// circular race
|
|
3125
|
+
//
|
|
3126
|
+
|
|
3127
|
+
/** @internal */
|
|
3128
|
+
export const raceWith = dual<
|
|
3129
|
+
<E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3130
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3131
|
+
options: {
|
|
3132
|
+
readonly onSelfDone: (exit: Exit.Exit<E, A>, fiber: Fiber.Fiber<E1, A1>) => Effect.Effect<R2, E2, A2>
|
|
3133
|
+
readonly onOtherDone: (exit: Exit.Exit<E1, A1>, fiber: Fiber.Fiber<E, A>) => Effect.Effect<R3, E3, A3>
|
|
3134
|
+
}
|
|
3135
|
+
) => <R>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1 | R2 | R3, E2 | E3, A2 | A3>,
|
|
3136
|
+
<R, E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3137
|
+
self: Effect.Effect<R, E, A>,
|
|
3138
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3139
|
+
options: {
|
|
3140
|
+
readonly onSelfDone: (exit: Exit.Exit<E, A>, fiber: Fiber.Fiber<E1, A1>) => Effect.Effect<R2, E2, A2>
|
|
3141
|
+
readonly onOtherDone: (exit: Exit.Exit<E1, A1>, fiber: Fiber.Fiber<E, A>) => Effect.Effect<R3, E3, A3>
|
|
3142
|
+
}
|
|
3143
|
+
) => Effect.Effect<R | R1 | R2 | R3, E2 | E3, A2 | A3>
|
|
3144
|
+
>(3, <R, E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3145
|
+
self: Effect.Effect<R, E, A>,
|
|
3146
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3147
|
+
options: {
|
|
3148
|
+
readonly onSelfDone: (exit: Exit.Exit<E, A>, fiber: Fiber.Fiber<E1, A1>) => Effect.Effect<R2, E2, A2>
|
|
3149
|
+
readonly onOtherDone: (exit: Exit.Exit<E1, A1>, fiber: Fiber.Fiber<E, A>) => Effect.Effect<R3, E3, A3>
|
|
3150
|
+
}
|
|
3151
|
+
) =>
|
|
3152
|
+
raceFibersWith(self, other, {
|
|
3153
|
+
onSelfWin: (winner, loser) =>
|
|
3154
|
+
core.flatMap(winner.await(), (exit) => {
|
|
3155
|
+
switch (exit._tag) {
|
|
3156
|
+
case OpCodes.OP_SUCCESS: {
|
|
3157
|
+
return core.flatMap(
|
|
3158
|
+
winner.inheritAll(),
|
|
3159
|
+
() => options.onSelfDone(exit, loser)
|
|
3160
|
+
)
|
|
3161
|
+
}
|
|
3162
|
+
case OpCodes.OP_FAILURE: {
|
|
3163
|
+
return options.onSelfDone(exit, loser)
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
}),
|
|
3167
|
+
onOtherWin: (winner, loser) =>
|
|
3168
|
+
core.flatMap(winner.await(), (exit) => {
|
|
3169
|
+
switch (exit._tag) {
|
|
3170
|
+
case OpCodes.OP_SUCCESS: {
|
|
3171
|
+
return core.flatMap(
|
|
3172
|
+
winner.inheritAll(),
|
|
3173
|
+
() => options.onOtherDone(exit, loser)
|
|
3174
|
+
)
|
|
3175
|
+
}
|
|
3176
|
+
case OpCodes.OP_FAILURE: {
|
|
3177
|
+
return options.onOtherDone(exit, loser)
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
})
|
|
3181
|
+
}))
|
|
3182
|
+
|
|
3183
|
+
/** @internal */
|
|
3184
|
+
export const disconnect = <R, E, A>(self: Effect.Effect<R, E, A>): Effect.Effect<R, E, A> =>
|
|
3185
|
+
core.uninterruptibleMask((restore) =>
|
|
3186
|
+
core.fiberIdWith((fiberId) =>
|
|
3187
|
+
core.flatMap(forkDaemon(restore(self)), (fiber) =>
|
|
3188
|
+
pipe(
|
|
3189
|
+
restore(internalFiber.join(fiber)),
|
|
3190
|
+
core.onInterrupt(() => pipe(fiber, internalFiber.interruptAsFork(fiberId)))
|
|
3191
|
+
))
|
|
3192
|
+
)
|
|
3193
|
+
)
|
|
3194
|
+
|
|
3195
|
+
/** @internal */
|
|
3196
|
+
export const race = dual<
|
|
3197
|
+
<R2, E2, A2>(
|
|
3198
|
+
that: Effect.Effect<R2, E2, A2>
|
|
3199
|
+
) => <R, E, A>(
|
|
3200
|
+
self: Effect.Effect<R, E, A>
|
|
3201
|
+
) => Effect.Effect<R | R2, E | E2, A | A2>,
|
|
3202
|
+
<R, E, A, R2, E2, A2>(
|
|
3203
|
+
self: Effect.Effect<R, E, A>,
|
|
3204
|
+
that: Effect.Effect<R2, E2, A2>
|
|
3205
|
+
) => Effect.Effect<R | R2, E | E2, A | A2>
|
|
3206
|
+
>(
|
|
3207
|
+
2,
|
|
3208
|
+
(self, that) =>
|
|
3209
|
+
core.fiberIdWith((parentFiberId) =>
|
|
3210
|
+
raceWith(self, that, {
|
|
3211
|
+
onSelfDone: (exit, right) =>
|
|
3212
|
+
core.exitMatchEffect(exit, {
|
|
3213
|
+
onFailure: (cause) =>
|
|
3214
|
+
pipe(
|
|
3215
|
+
internalFiber.join(right),
|
|
3216
|
+
internalEffect.mapErrorCause((cause2) => internalCause.parallel(cause, cause2))
|
|
3217
|
+
),
|
|
3218
|
+
onSuccess: (value) =>
|
|
3219
|
+
pipe(
|
|
3220
|
+
right,
|
|
3221
|
+
core.interruptAsFiber(parentFiberId),
|
|
3222
|
+
core.as(value)
|
|
3223
|
+
)
|
|
3224
|
+
}),
|
|
3225
|
+
onOtherDone: (exit, left) =>
|
|
3226
|
+
core.exitMatchEffect(exit, {
|
|
3227
|
+
onFailure: (cause) =>
|
|
3228
|
+
pipe(
|
|
3229
|
+
internalFiber.join(left),
|
|
3230
|
+
internalEffect.mapErrorCause((cause2) => internalCause.parallel(cause2, cause))
|
|
3231
|
+
),
|
|
3232
|
+
onSuccess: (value) =>
|
|
3233
|
+
pipe(
|
|
3234
|
+
left,
|
|
3235
|
+
core.interruptAsFiber(parentFiberId),
|
|
3236
|
+
core.as(value)
|
|
3237
|
+
)
|
|
3238
|
+
})
|
|
3239
|
+
})
|
|
3240
|
+
)
|
|
3241
|
+
)
|
|
3242
|
+
|
|
3243
|
+
/** @internal */
|
|
3244
|
+
export const raceFibersWith = dual<
|
|
3245
|
+
<E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3246
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3247
|
+
options: {
|
|
3248
|
+
readonly onSelfWin: (
|
|
3249
|
+
winner: Fiber.RuntimeFiber<E, A>,
|
|
3250
|
+
loser: Fiber.RuntimeFiber<E1, A1>
|
|
3251
|
+
) => Effect.Effect<R2, E2, A2>
|
|
3252
|
+
readonly onOtherWin: (
|
|
3253
|
+
winner: Fiber.RuntimeFiber<E1, A1>,
|
|
3254
|
+
loser: Fiber.RuntimeFiber<E, A>
|
|
3255
|
+
) => Effect.Effect<R3, E3, A3>
|
|
3256
|
+
readonly selfScope?: fiberScope.FiberScope
|
|
3257
|
+
readonly otherScope?: fiberScope.FiberScope
|
|
3258
|
+
}
|
|
3259
|
+
) => <R>(self: Effect.Effect<R, E, A>) => Effect.Effect<
|
|
3260
|
+
R | R1 | R2 | R3,
|
|
3261
|
+
E2 | E3,
|
|
3262
|
+
A2 | A3
|
|
3263
|
+
>,
|
|
3264
|
+
<R, E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3265
|
+
self: Effect.Effect<R, E, A>,
|
|
3266
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3267
|
+
options: {
|
|
3268
|
+
readonly onSelfWin: (
|
|
3269
|
+
winner: Fiber.RuntimeFiber<E, A>,
|
|
3270
|
+
loser: Fiber.RuntimeFiber<E1, A1>
|
|
3271
|
+
) => Effect.Effect<R2, E2, A2>
|
|
3272
|
+
readonly onOtherWin: (
|
|
3273
|
+
winner: Fiber.RuntimeFiber<E1, A1>,
|
|
3274
|
+
loser: Fiber.RuntimeFiber<E, A>
|
|
3275
|
+
) => Effect.Effect<R3, E3, A3>
|
|
3276
|
+
readonly selfScope?: fiberScope.FiberScope
|
|
3277
|
+
readonly otherScope?: fiberScope.FiberScope
|
|
3278
|
+
}
|
|
3279
|
+
) => Effect.Effect<
|
|
3280
|
+
R | R1 | R2 | R3,
|
|
3281
|
+
E2 | E3,
|
|
3282
|
+
A2 | A3
|
|
3283
|
+
>
|
|
3284
|
+
>(3, <R, E, A, R1, E1, A1, R2, E2, A2, R3, E3, A3>(
|
|
3285
|
+
self: Effect.Effect<R, E, A>,
|
|
3286
|
+
other: Effect.Effect<R1, E1, A1>,
|
|
3287
|
+
options: {
|
|
3288
|
+
readonly onSelfWin: (
|
|
3289
|
+
winner: Fiber.RuntimeFiber<E, A>,
|
|
3290
|
+
loser: Fiber.RuntimeFiber<E1, A1>
|
|
3291
|
+
) => Effect.Effect<R2, E2, A2>
|
|
3292
|
+
readonly onOtherWin: (
|
|
3293
|
+
winner: Fiber.RuntimeFiber<E1, A1>,
|
|
3294
|
+
loser: Fiber.RuntimeFiber<E, A>
|
|
3295
|
+
) => Effect.Effect<R3, E3, A3>
|
|
3296
|
+
readonly selfScope?: fiberScope.FiberScope
|
|
3297
|
+
readonly otherScope?: fiberScope.FiberScope
|
|
3298
|
+
}
|
|
3299
|
+
) =>
|
|
3300
|
+
core.withFiberRuntime<R | R1 | R2 | R3, E2 | E3, A2 | A3>((parentFiber, parentStatus) => {
|
|
3301
|
+
const parentRuntimeFlags = parentStatus.runtimeFlags
|
|
3302
|
+
const raceIndicator = MRef.make(true)
|
|
3303
|
+
const leftFiber: FiberRuntime<E, A> = unsafeMakeChildFiber(
|
|
3304
|
+
self,
|
|
3305
|
+
parentFiber,
|
|
3306
|
+
parentRuntimeFlags,
|
|
3307
|
+
options.selfScope
|
|
3308
|
+
)
|
|
3309
|
+
const rightFiber: FiberRuntime<E1, A1> = unsafeMakeChildFiber(
|
|
3310
|
+
other,
|
|
3311
|
+
parentFiber,
|
|
3312
|
+
parentRuntimeFlags,
|
|
3313
|
+
options.otherScope
|
|
3314
|
+
)
|
|
3315
|
+
return core.async<R | R1 | R2 | R3, E2 | E3, A2 | A3>((cb) => {
|
|
3316
|
+
leftFiber.addObserver(() => completeRace(leftFiber, rightFiber, options.onSelfWin, raceIndicator, cb))
|
|
3317
|
+
rightFiber.addObserver(() => completeRace(rightFiber, leftFiber, options.onOtherWin, raceIndicator, cb))
|
|
3318
|
+
leftFiber.startFork(self)
|
|
3319
|
+
rightFiber.startFork(other)
|
|
3320
|
+
}, FiberId.combine(leftFiber.id(), rightFiber.id()))
|
|
3321
|
+
}))
|
|
3322
|
+
|
|
3323
|
+
const completeRace = <R, R1, R2, E2, A2, R3, E3, A3>(
|
|
3324
|
+
winner: Fiber.RuntimeFiber<any, any>,
|
|
3325
|
+
loser: Fiber.RuntimeFiber<any, any>,
|
|
3326
|
+
cont: (winner: Fiber.RuntimeFiber<any, any>, loser: Fiber.RuntimeFiber<any, any>) => Effect.Effect<any, any, any>,
|
|
3327
|
+
ab: MRef.MutableRef<boolean>,
|
|
3328
|
+
cb: (_: Effect.Effect<R | R1 | R2 | R3, E2 | E3, A2 | A3>) => void
|
|
3329
|
+
): void => {
|
|
3330
|
+
if (MRef.compareAndSet(true, false)(ab)) {
|
|
3331
|
+
cb(cont(winner, loser))
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
/** @internal */
|
|
3336
|
+
export const ensuring = dual<
|
|
3337
|
+
<R1, X>(
|
|
3338
|
+
finalizer: Effect.Effect<R1, never, X>
|
|
3339
|
+
) => <R, E, A>(
|
|
3340
|
+
self: Effect.Effect<R, E, A>
|
|
3341
|
+
) => Effect.Effect<R | R1, E, A>,
|
|
3342
|
+
<R, E, A, R1, X>(
|
|
3343
|
+
self: Effect.Effect<R, E, A>,
|
|
3344
|
+
finalizer: Effect.Effect<R1, never, X>
|
|
3345
|
+
) => Effect.Effect<R | R1, E, A>
|
|
3346
|
+
>(2, (self, finalizer) =>
|
|
3347
|
+
core.uninterruptibleMask((restore) =>
|
|
3348
|
+
core.matchCauseEffect(restore(self), {
|
|
3349
|
+
onFailure: (cause1) =>
|
|
3350
|
+
core.matchCauseEffect(finalizer, {
|
|
3351
|
+
onFailure: (cause2) => core.failCause(internalCause.sequential(cause1, cause2)),
|
|
3352
|
+
onSuccess: () => core.failCause(cause1)
|
|
3353
|
+
}),
|
|
3354
|
+
onSuccess: (a) => core.as(finalizer, a)
|
|
3355
|
+
})
|
|
3356
|
+
))
|
|
3357
|
+
|
|
3358
|
+
/** @internal */
|
|
3359
|
+
export const invokeWithInterrupt: <R, E, A>(
|
|
3360
|
+
self: Effect.Effect<R, E, A>,
|
|
3361
|
+
entries: ReadonlyArray<Entry<unknown>>
|
|
3362
|
+
) => Effect.Effect<R, E, void> = <R, E, A>(dataSource: Effect.Effect<R, E, A>, all: ReadonlyArray<Entry<unknown>>) =>
|
|
3363
|
+
core.fiberIdWith((id) =>
|
|
3364
|
+
core.flatMap(
|
|
3365
|
+
core.flatMap(
|
|
3366
|
+
forkDaemon(core.interruptible(dataSource)),
|
|
3367
|
+
(processing) =>
|
|
3368
|
+
core.async<never, E, void>((cb) => {
|
|
3369
|
+
const counts = all.map((_) => _.listeners.count)
|
|
3370
|
+
const checkDone = () => {
|
|
3371
|
+
if (counts.every((count) => count === 0)) {
|
|
3372
|
+
cleanup.forEach((f) => f())
|
|
3373
|
+
cb(core.interruptFiber(processing))
|
|
3374
|
+
}
|
|
3375
|
+
}
|
|
3376
|
+
processing.addObserver((exit) => {
|
|
3377
|
+
cleanup.forEach((f) => f())
|
|
3378
|
+
cb(exit)
|
|
3379
|
+
})
|
|
3380
|
+
const cleanup = all.map((r, i) => {
|
|
3381
|
+
const observer = (count: number) => {
|
|
3382
|
+
counts[i] = count
|
|
3383
|
+
checkDone()
|
|
3384
|
+
}
|
|
3385
|
+
r.listeners.addObserver(observer)
|
|
3386
|
+
return () => r.listeners.removeObserver(observer)
|
|
3387
|
+
})
|
|
3388
|
+
checkDone()
|
|
3389
|
+
return core.sync(() => {
|
|
3390
|
+
cleanup.forEach((f) => f())
|
|
3391
|
+
})
|
|
3392
|
+
})
|
|
3393
|
+
),
|
|
3394
|
+
() =>
|
|
3395
|
+
core.suspend(() => {
|
|
3396
|
+
const residual = all.flatMap((entry) => {
|
|
3397
|
+
if (!entry.state.completed) {
|
|
3398
|
+
return [entry]
|
|
3399
|
+
}
|
|
3400
|
+
return []
|
|
3401
|
+
})
|
|
3402
|
+
return core.forEachSequentialDiscard(
|
|
3403
|
+
residual,
|
|
3404
|
+
(entry) => complete(entry.request as any, core.exitInterrupt(id))
|
|
3405
|
+
)
|
|
3406
|
+
})
|
|
3407
|
+
)
|
|
3408
|
+
)
|
|
3409
|
+
|
|
3410
|
+
/** @internal */
|
|
3411
|
+
export const interruptWhenPossible = dual<
|
|
3412
|
+
(all: Iterable<Request<any, any>>) => <R, E, A>(
|
|
3413
|
+
self: Effect.Effect<R, E, A>
|
|
3414
|
+
) => Effect.Effect<R, E, void>,
|
|
3415
|
+
<R, E, A>(
|
|
3416
|
+
self: Effect.Effect<R, E, A>,
|
|
3417
|
+
all: Iterable<Request<any, any>>
|
|
3418
|
+
) => Effect.Effect<R, E, void>
|
|
3419
|
+
>(2, (self, all) =>
|
|
3420
|
+
core.fiberRefGetWith(
|
|
3421
|
+
currentRequestMap,
|
|
3422
|
+
(map) =>
|
|
3423
|
+
core.suspend(() => {
|
|
3424
|
+
const entries = RA.fromIterable(all).flatMap((_) => map.has(_) ? [map.get(_)!] : [])
|
|
3425
|
+
return invokeWithInterrupt(self, entries)
|
|
3426
|
+
})
|
|
3427
|
+
))
|
|
3428
|
+
|
|
3429
|
+
// circular Tracer
|
|
3430
|
+
|
|
3431
|
+
/** @internal */
|
|
3432
|
+
export const useSpanScoped = (
|
|
3433
|
+
name: string,
|
|
3434
|
+
options?: {
|
|
3435
|
+
readonly attributes?: Record<string, Tracer.AttributeValue>
|
|
3436
|
+
readonly links?: ReadonlyArray<Tracer.SpanLink>
|
|
3437
|
+
readonly parent?: Tracer.ParentSpan
|
|
3438
|
+
readonly root?: boolean
|
|
3439
|
+
readonly context?: Context.Context<never>
|
|
3440
|
+
}
|
|
3441
|
+
): Effect.Effect<Scope.Scope, never, Tracer.Span> =>
|
|
3442
|
+
acquireRelease(
|
|
3443
|
+
internalEffect.makeSpan(name, options),
|
|
3444
|
+
(span, exit) =>
|
|
3445
|
+
core.flatMap(
|
|
3446
|
+
internalEffect.currentTimeNanosTracing,
|
|
3447
|
+
(endTime) => core.sync(() => span.end(endTime, exit))
|
|
3448
|
+
)
|
|
3449
|
+
)
|
|
3450
|
+
|
|
3451
|
+
/* @internal */
|
|
3452
|
+
export const withSpanScoped = (
|
|
3453
|
+
name: string,
|
|
3454
|
+
options?: {
|
|
3455
|
+
readonly attributes?: Record<string, Tracer.AttributeValue>
|
|
3456
|
+
readonly links?: ReadonlyArray<Tracer.SpanLink>
|
|
3457
|
+
readonly parent?: Tracer.ParentSpan
|
|
3458
|
+
readonly root?: boolean
|
|
3459
|
+
readonly context?: Context.Context<never>
|
|
3460
|
+
}
|
|
3461
|
+
): Effect.Effect<Scope.Scope, never, void> =>
|
|
3462
|
+
core.flatMap(
|
|
3463
|
+
useSpanScoped(name, options),
|
|
3464
|
+
(span) =>
|
|
3465
|
+
fiberRefLocallyScopedWith(
|
|
3466
|
+
core.currentTracerSpan,
|
|
3467
|
+
List.prepend(span)
|
|
3468
|
+
)
|
|
3469
|
+
)
|
|
3470
|
+
|
|
3471
|
+
/* @internal */
|
|
3472
|
+
export const withTracerScoped = (value: Tracer.Tracer): Effect.Effect<Scope.Scope, never, void> =>
|
|
3473
|
+
fiberRefLocallyScopedWith(defaultServices.currentServices, Context.add(tracer.tracerTag, value))
|
|
3474
|
+
|
|
3475
|
+
/* @internal */
|
|
3476
|
+
export const withParentSpanScoped = (span: Tracer.ParentSpan): Effect.Effect<Scope.Scope, never, void> =>
|
|
3477
|
+
fiberRefLocallyScopedWith(core.currentTracerSpan, List.prepend(span))
|