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,2096 @@
|
|
|
1
|
+
import type * as Cause from "../Cause"
|
|
2
|
+
import * as Chunk from "../Chunk"
|
|
3
|
+
import * as Clock from "../Clock"
|
|
4
|
+
import * as Context from "../Context"
|
|
5
|
+
import * as Duration from "../Duration"
|
|
6
|
+
import type * as Effect from "../Effect"
|
|
7
|
+
import * as Either from "../Either"
|
|
8
|
+
import * as Equal from "../Equal"
|
|
9
|
+
import type { LazyArg } from "../Function"
|
|
10
|
+
import { constVoid, dual, pipe } from "../Function"
|
|
11
|
+
import * as internalCause from "../internal/cause"
|
|
12
|
+
import * as core from "../internal/core"
|
|
13
|
+
import * as ref from "../internal/ref"
|
|
14
|
+
import * as Option from "../Option"
|
|
15
|
+
import { pipeArguments } from "../Pipeable"
|
|
16
|
+
import type { Predicate, Refinement } from "../Predicate"
|
|
17
|
+
import * as Random from "../Random"
|
|
18
|
+
import type * as Ref from "../Ref"
|
|
19
|
+
import type * as Schedule from "../Schedule"
|
|
20
|
+
import * as ScheduleDecision from "../ScheduleDecision"
|
|
21
|
+
import * as Interval from "../ScheduleInterval"
|
|
22
|
+
import * as Intervals from "../ScheduleIntervals"
|
|
23
|
+
import * as effect from "./core-effect"
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
const ScheduleSymbolKey = "effect/Schedule"
|
|
27
|
+
|
|
28
|
+
/** @internal */
|
|
29
|
+
export const ScheduleTypeId: Schedule.ScheduleTypeId = Symbol.for(
|
|
30
|
+
ScheduleSymbolKey
|
|
31
|
+
) as Schedule.ScheduleTypeId
|
|
32
|
+
|
|
33
|
+
/** @internal */
|
|
34
|
+
const ScheduleDriverSymbolKey = "effect/ScheduleDriver"
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
export const ScheduleDriverTypeId: Schedule.ScheduleDriverTypeId = Symbol.for(
|
|
38
|
+
ScheduleDriverSymbolKey
|
|
39
|
+
) as Schedule.ScheduleDriverTypeId
|
|
40
|
+
|
|
41
|
+
/** @internal */
|
|
42
|
+
const scheduleVariance = {
|
|
43
|
+
_Env: (_: never) => _,
|
|
44
|
+
_In: (_: unknown) => _,
|
|
45
|
+
_Out: (_: never) => _
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const scheduleDriverVariance = {
|
|
49
|
+
_Env: (_: never) => _,
|
|
50
|
+
_In: (_: unknown) => _,
|
|
51
|
+
_Out: (_: never) => _
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** @internal */
|
|
55
|
+
class ScheduleImpl<S, Env, In, Out> implements Schedule.Schedule<Env, In, Out> {
|
|
56
|
+
[ScheduleTypeId] = scheduleVariance
|
|
57
|
+
constructor(
|
|
58
|
+
readonly initial: S,
|
|
59
|
+
readonly step: (
|
|
60
|
+
now: number,
|
|
61
|
+
input: In,
|
|
62
|
+
state: S
|
|
63
|
+
) => Effect.Effect<Env, never, readonly [S, Out, ScheduleDecision.ScheduleDecision]>
|
|
64
|
+
) {
|
|
65
|
+
}
|
|
66
|
+
pipe() {
|
|
67
|
+
return pipeArguments(this, arguments)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
class ScheduleDriverImpl<Env, In, Out> implements Schedule.ScheduleDriver<Env, In, Out> {
|
|
73
|
+
[ScheduleDriverTypeId] = scheduleDriverVariance
|
|
74
|
+
|
|
75
|
+
constructor(
|
|
76
|
+
readonly schedule: Schedule.Schedule<Env, In, Out>,
|
|
77
|
+
readonly ref: Ref.Ref<readonly [Option.Option<Out>, any]>
|
|
78
|
+
) {}
|
|
79
|
+
|
|
80
|
+
state(): Effect.Effect<never, never, unknown> {
|
|
81
|
+
return core.map(ref.get(this.ref), (tuple) => tuple[1])
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
last(): Effect.Effect<never, Cause.NoSuchElementException, Out> {
|
|
85
|
+
return core.flatMap(ref.get(this.ref), ([element, _]) => {
|
|
86
|
+
switch (element._tag) {
|
|
87
|
+
case "None": {
|
|
88
|
+
return core.failSync(() => internalCause.NoSuchElementException())
|
|
89
|
+
}
|
|
90
|
+
case "Some": {
|
|
91
|
+
return core.succeed(element.value)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
reset(): Effect.Effect<never, never, void> {
|
|
98
|
+
return ref.set(this.ref, [Option.none(), this.schedule.initial])
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
next(input: In): Effect.Effect<Env, Option.Option<never>, Out> {
|
|
102
|
+
return pipe(
|
|
103
|
+
core.map(ref.get(this.ref), (tuple) => tuple[1]),
|
|
104
|
+
core.flatMap((state) =>
|
|
105
|
+
pipe(
|
|
106
|
+
Clock.currentTimeMillis,
|
|
107
|
+
core.flatMap((now) =>
|
|
108
|
+
pipe(
|
|
109
|
+
core.suspend(() => this.schedule.step(now, input, state)),
|
|
110
|
+
core.flatMap(([state, out, decision]) =>
|
|
111
|
+
ScheduleDecision.isDone(decision) ?
|
|
112
|
+
pipe(
|
|
113
|
+
ref.set(this.ref, [Option.some(out), state] as const),
|
|
114
|
+
core.zipRight(core.fail(Option.none()))
|
|
115
|
+
) :
|
|
116
|
+
pipe(
|
|
117
|
+
ref.set(this.ref, [Option.some(out), state] as const),
|
|
118
|
+
core.zipRight(effect.sleep(Duration.millis(Intervals.start(decision.intervals) - now))),
|
|
119
|
+
core.as(out)
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** @internal */
|
|
131
|
+
export const makeWithState = <S, Env, In, Out>(
|
|
132
|
+
initial: S,
|
|
133
|
+
step: (
|
|
134
|
+
now: number,
|
|
135
|
+
input: In,
|
|
136
|
+
state: S
|
|
137
|
+
) => Effect.Effect<Env, never, readonly [S, Out, ScheduleDecision.ScheduleDecision]>
|
|
138
|
+
): Schedule.Schedule<Env, In, Out> => new ScheduleImpl(initial, step)
|
|
139
|
+
|
|
140
|
+
/** @internal */
|
|
141
|
+
export const addDelay = dual<
|
|
142
|
+
<Out>(
|
|
143
|
+
f: (out: Out) => Duration.DurationInput
|
|
144
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
145
|
+
<Env, In, Out>(
|
|
146
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
147
|
+
f: (out: Out) => Duration.DurationInput
|
|
148
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
149
|
+
>(2, (self, f) => addDelayEffect(self, (out) => core.sync(() => f(out))))
|
|
150
|
+
|
|
151
|
+
/** @internal */
|
|
152
|
+
export const addDelayEffect = dual<
|
|
153
|
+
<Out, Env2>(
|
|
154
|
+
f: (out: Out) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
155
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
156
|
+
<Env, In, Out, Env2>(
|
|
157
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
158
|
+
f: (out: Out) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
159
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
160
|
+
>(2, (self, f) =>
|
|
161
|
+
modifyDelayEffect(self, (out, duration) =>
|
|
162
|
+
core.map(
|
|
163
|
+
f(out),
|
|
164
|
+
(delay) => Duration.sum(duration, Duration.decode(delay))
|
|
165
|
+
)))
|
|
166
|
+
|
|
167
|
+
/** @internal */
|
|
168
|
+
export const andThen = dual<
|
|
169
|
+
<Env1, In1, Out2>(
|
|
170
|
+
that: Schedule.Schedule<Env1, In1, Out2>
|
|
171
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
172
|
+
Env | Env1,
|
|
173
|
+
In & In1,
|
|
174
|
+
Out | Out2
|
|
175
|
+
>,
|
|
176
|
+
<Env, In, Out, Env1, In1, Out2>(
|
|
177
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
178
|
+
that: Schedule.Schedule<Env1, In1, Out2>
|
|
179
|
+
) => Schedule.Schedule<
|
|
180
|
+
Env | Env1,
|
|
181
|
+
In & In1,
|
|
182
|
+
Out | Out2
|
|
183
|
+
>
|
|
184
|
+
>(2, (self, that) => map(andThenEither(self, that), Either.merge))
|
|
185
|
+
|
|
186
|
+
/** @internal */
|
|
187
|
+
export const andThenEither = dual<
|
|
188
|
+
<Env2, In2, Out2>(
|
|
189
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
190
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
191
|
+
Env | Env2,
|
|
192
|
+
In & In2,
|
|
193
|
+
Either.Either<Out, Out2>
|
|
194
|
+
>,
|
|
195
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
196
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
197
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
198
|
+
) => Schedule.Schedule<
|
|
199
|
+
Env | Env2,
|
|
200
|
+
In & In2,
|
|
201
|
+
Either.Either<Out, Out2>
|
|
202
|
+
>
|
|
203
|
+
>(2, <Env, In, Out, Env2, In2, Out2>(
|
|
204
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
205
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
206
|
+
): Schedule.Schedule<
|
|
207
|
+
Env | Env2,
|
|
208
|
+
In & In2,
|
|
209
|
+
Either.Either<Out, Out2>
|
|
210
|
+
> =>
|
|
211
|
+
makeWithState(
|
|
212
|
+
[self.initial, that.initial, true as boolean] as const,
|
|
213
|
+
(now, input, state) =>
|
|
214
|
+
state[2] ?
|
|
215
|
+
core.flatMap(self.step(now, input, state[0]), ([lState, out, decision]) => {
|
|
216
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
217
|
+
return core.map(that.step(now, input, state[1]), ([rState, out, decision]) =>
|
|
218
|
+
[
|
|
219
|
+
[lState, rState, false as boolean] as const,
|
|
220
|
+
Either.right(out) as Either.Either<Out, Out2>,
|
|
221
|
+
decision as ScheduleDecision.ScheduleDecision
|
|
222
|
+
] as const)
|
|
223
|
+
}
|
|
224
|
+
return core.succeed(
|
|
225
|
+
[
|
|
226
|
+
[lState, state[1], true as boolean] as const,
|
|
227
|
+
Either.left(out),
|
|
228
|
+
decision
|
|
229
|
+
] as const
|
|
230
|
+
)
|
|
231
|
+
}) :
|
|
232
|
+
core.map(that.step(now, input, state[1]), ([rState, out, decision]) =>
|
|
233
|
+
[
|
|
234
|
+
[state[0], rState, false as boolean] as const,
|
|
235
|
+
Either.right(out) as Either.Either<Out, Out2>,
|
|
236
|
+
decision
|
|
237
|
+
] as const)
|
|
238
|
+
))
|
|
239
|
+
|
|
240
|
+
/** @internal */
|
|
241
|
+
export const as = dual<
|
|
242
|
+
<Out2>(out: Out2) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out2>,
|
|
243
|
+
<Env, In, Out, Out2>(self: Schedule.Schedule<Env, In, Out>, out: Out2) => Schedule.Schedule<Env, In, Out2>
|
|
244
|
+
>(2, (self, out) => map(self, () => out))
|
|
245
|
+
|
|
246
|
+
/** @internal */
|
|
247
|
+
export const asUnit = <Env, In, Out>(
|
|
248
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
249
|
+
): Schedule.Schedule<Env, In, void> => map(self, constVoid)
|
|
250
|
+
|
|
251
|
+
/** @internal */
|
|
252
|
+
export const bothInOut = dual<
|
|
253
|
+
<Env2, In2, Out2>(
|
|
254
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
255
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
256
|
+
Env | Env2,
|
|
257
|
+
readonly [In, In2],
|
|
258
|
+
readonly [Out, Out2]
|
|
259
|
+
>,
|
|
260
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
261
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
262
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
263
|
+
) => Schedule.Schedule<
|
|
264
|
+
Env | Env2,
|
|
265
|
+
readonly [In, In2],
|
|
266
|
+
readonly [Out, Out2]
|
|
267
|
+
>
|
|
268
|
+
>(2, (self, that) =>
|
|
269
|
+
makeWithState([self.initial, that.initial] as const, (now, [in1, in2], state) =>
|
|
270
|
+
core.zipWith(
|
|
271
|
+
self.step(now, in1, state[0]),
|
|
272
|
+
that.step(now, in2, state[1]),
|
|
273
|
+
([lState, out, lDecision], [rState, out2, rDecision]) => {
|
|
274
|
+
if (ScheduleDecision.isContinue(lDecision) && ScheduleDecision.isContinue(rDecision)) {
|
|
275
|
+
const interval = pipe(lDecision.intervals, Intervals.union(rDecision.intervals))
|
|
276
|
+
return [
|
|
277
|
+
[lState, rState] as const,
|
|
278
|
+
[out, out2] as const,
|
|
279
|
+
ScheduleDecision.continue(interval)
|
|
280
|
+
] as const
|
|
281
|
+
}
|
|
282
|
+
return [[lState, rState] as const, [out, out2] as const, ScheduleDecision.done] as const
|
|
283
|
+
}
|
|
284
|
+
)))
|
|
285
|
+
|
|
286
|
+
/** @internal */
|
|
287
|
+
export const check = dual<
|
|
288
|
+
<In, Out>(
|
|
289
|
+
test: (input: In, output: Out) => boolean
|
|
290
|
+
) => <Env>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
291
|
+
<Env, In, Out>(
|
|
292
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
293
|
+
test: (input: In, output: Out) => boolean
|
|
294
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
295
|
+
>(2, (self, test) => checkEffect(self, (input, out) => core.sync(() => test(input, out))))
|
|
296
|
+
|
|
297
|
+
/** @internal */
|
|
298
|
+
export const checkEffect = dual<
|
|
299
|
+
<In, Out, Env2>(
|
|
300
|
+
test: (input: In, output: Out) => Effect.Effect<Env2, never, boolean>
|
|
301
|
+
) => <Env>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
302
|
+
<Env, In, Out, Env2>(
|
|
303
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
304
|
+
test: (input: In, output: Out) => Effect.Effect<Env2, never, boolean>
|
|
305
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
306
|
+
>(2, (self, test) =>
|
|
307
|
+
makeWithState(
|
|
308
|
+
self.initial,
|
|
309
|
+
(now, input, state) =>
|
|
310
|
+
core.flatMap(self.step(now, input, state), ([state, out, decision]) => {
|
|
311
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
312
|
+
return core.succeed([state, out, ScheduleDecision.done] as const)
|
|
313
|
+
}
|
|
314
|
+
return core.map(test(input, out), (cont) =>
|
|
315
|
+
cont ?
|
|
316
|
+
[state, out, decision] as const :
|
|
317
|
+
[state, out, ScheduleDecision.done] as const)
|
|
318
|
+
})
|
|
319
|
+
))
|
|
320
|
+
/** @internal */
|
|
321
|
+
export const collectAllInputs = <A>(): Schedule.Schedule<never, A, Chunk.Chunk<A>> => collectAllOutputs(identity<A>())
|
|
322
|
+
|
|
323
|
+
/** @internal */
|
|
324
|
+
export const collectAllOutputs = <Env, In, Out>(
|
|
325
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
326
|
+
): Schedule.Schedule<Env, In, Chunk.Chunk<Out>> =>
|
|
327
|
+
reduce(self, Chunk.empty<Out>(), (outs, out) => pipe(outs, Chunk.append(out)))
|
|
328
|
+
|
|
329
|
+
/** @internal */
|
|
330
|
+
export const collectUntil = <A>(f: Predicate<A>): Schedule.Schedule<never, A, Chunk.Chunk<A>> =>
|
|
331
|
+
collectAllOutputs(recurUntil(f))
|
|
332
|
+
|
|
333
|
+
/** @internal */
|
|
334
|
+
export const collectUntilEffect = <Env, A>(
|
|
335
|
+
f: (a: A) => Effect.Effect<Env, never, boolean>
|
|
336
|
+
): Schedule.Schedule<Env, A, Chunk.Chunk<A>> => collectAllOutputs(recurUntilEffect(f))
|
|
337
|
+
|
|
338
|
+
/** @internal */
|
|
339
|
+
export const collectWhile = <A>(f: Predicate<A>): Schedule.Schedule<never, A, Chunk.Chunk<A>> =>
|
|
340
|
+
collectAllOutputs(recurWhile(f))
|
|
341
|
+
|
|
342
|
+
/** @internal */
|
|
343
|
+
export const collectWhileEffect = <Env, A>(
|
|
344
|
+
f: (a: A) => Effect.Effect<Env, never, boolean>
|
|
345
|
+
): Schedule.Schedule<Env, A, Chunk.Chunk<A>> => collectAllOutputs(recurWhileEffect(f))
|
|
346
|
+
|
|
347
|
+
/** @internal */
|
|
348
|
+
export const compose = dual<
|
|
349
|
+
<Env2, Out, Out2>(
|
|
350
|
+
that: Schedule.Schedule<Env2, Out, Out2>
|
|
351
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out2>,
|
|
352
|
+
<Env, In, Out, Env2, Out2>(
|
|
353
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
354
|
+
that: Schedule.Schedule<Env2, Out, Out2>
|
|
355
|
+
) => Schedule.Schedule<Env | Env2, In, Out2>
|
|
356
|
+
>(2, (self, that) =>
|
|
357
|
+
makeWithState(
|
|
358
|
+
[self.initial, that.initial] as const,
|
|
359
|
+
(now, input, state) =>
|
|
360
|
+
core.flatMap(
|
|
361
|
+
self.step(now, input, state[0]),
|
|
362
|
+
([lState, out, lDecision]) =>
|
|
363
|
+
core.map(that.step(now, out, state[1]), ([rState, out2, rDecision]) =>
|
|
364
|
+
ScheduleDecision.isDone(lDecision)
|
|
365
|
+
? [[lState, rState] as const, out2, ScheduleDecision.done] as const
|
|
366
|
+
: ScheduleDecision.isDone(rDecision)
|
|
367
|
+
? [[lState, rState] as const, out2, ScheduleDecision.done] as const
|
|
368
|
+
: [
|
|
369
|
+
[lState, rState] as const,
|
|
370
|
+
out2,
|
|
371
|
+
ScheduleDecision.continue(pipe(lDecision.intervals, Intervals.max(rDecision.intervals)))
|
|
372
|
+
] as const)
|
|
373
|
+
)
|
|
374
|
+
))
|
|
375
|
+
|
|
376
|
+
/** @internal */
|
|
377
|
+
export const mapInput = dual<
|
|
378
|
+
<In, In2>(
|
|
379
|
+
f: (in2: In2) => In
|
|
380
|
+
) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In2, Out>,
|
|
381
|
+
<Env, In, Out, In2>(
|
|
382
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
383
|
+
f: (in2: In2) => In
|
|
384
|
+
) => Schedule.Schedule<Env, In2, Out>
|
|
385
|
+
>(2, (self, f) => mapInputEffect(self, (input2) => core.sync(() => f(input2))))
|
|
386
|
+
|
|
387
|
+
/** @internal */
|
|
388
|
+
export const mapInputContext = dual<
|
|
389
|
+
<Env0, Env>(
|
|
390
|
+
f: (env0: Context.Context<Env0>) => Context.Context<Env>
|
|
391
|
+
) => <In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env0, In, Out>,
|
|
392
|
+
<Env0, Env, In, Out>(
|
|
393
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
394
|
+
f: (env0: Context.Context<Env0>) => Context.Context<Env>
|
|
395
|
+
) => Schedule.Schedule<Env0, In, Out>
|
|
396
|
+
>(2, (self, f) =>
|
|
397
|
+
makeWithState(
|
|
398
|
+
self.initial,
|
|
399
|
+
(now, input, state) => core.mapInputContext(self.step(now, input, state), f)
|
|
400
|
+
))
|
|
401
|
+
|
|
402
|
+
/** @internal */
|
|
403
|
+
export const mapInputEffect = dual<
|
|
404
|
+
<In, Env2, In2>(
|
|
405
|
+
f: (in2: In2) => Effect.Effect<Env2, never, In>
|
|
406
|
+
) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In2, Out>,
|
|
407
|
+
<Env, In, Out, Env2, In2>(
|
|
408
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
409
|
+
f: (in2: In2) => Effect.Effect<Env2, never, In>
|
|
410
|
+
) => Schedule.Schedule<Env | Env2, In2, Out>
|
|
411
|
+
>(2, (self, f) =>
|
|
412
|
+
makeWithState(self.initial, (now, input2, state) =>
|
|
413
|
+
core.flatMap(
|
|
414
|
+
f(input2),
|
|
415
|
+
(input) => self.step(now, input, state)
|
|
416
|
+
)))
|
|
417
|
+
|
|
418
|
+
/** @internal */
|
|
419
|
+
export const dayOfMonth = (day: number): Schedule.Schedule<never, unknown, number> => {
|
|
420
|
+
return makeWithState(
|
|
421
|
+
[Number.NEGATIVE_INFINITY, 0] as readonly [number, number],
|
|
422
|
+
(now, _, state) => {
|
|
423
|
+
if (!Number.isInteger(day) || day < 1 || 31 < day) {
|
|
424
|
+
return core.dieSync(() =>
|
|
425
|
+
internalCause.IllegalArgumentException(
|
|
426
|
+
`Invalid argument in: dayOfMonth(${day}). Must be in range 1...31`
|
|
427
|
+
)
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
const n = state[1]
|
|
431
|
+
const initial = n === 0
|
|
432
|
+
const day0 = nextDayOfMonth(now, day, initial)
|
|
433
|
+
const start = beginningOfDay(day0)
|
|
434
|
+
const end = endOfDay(day0)
|
|
435
|
+
const interval = Interval.make(start, end)
|
|
436
|
+
return core.succeed(
|
|
437
|
+
[
|
|
438
|
+
[end, n + 1] as const,
|
|
439
|
+
n,
|
|
440
|
+
ScheduleDecision.continueWith(interval)
|
|
441
|
+
] as const
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** @internal */
|
|
448
|
+
export const dayOfWeek = (day: number): Schedule.Schedule<never, unknown, number> => {
|
|
449
|
+
return makeWithState(
|
|
450
|
+
[Number.MIN_SAFE_INTEGER, 0] as readonly [number, number],
|
|
451
|
+
(now, _, state) => {
|
|
452
|
+
if (!Number.isInteger(day) || day < 1 || 7 < day) {
|
|
453
|
+
return core.dieSync(() =>
|
|
454
|
+
internalCause.IllegalArgumentException(
|
|
455
|
+
`Invalid argument in: dayOfWeek(${day}). Must be in range 1 (Monday)...7 (Sunday)`
|
|
456
|
+
)
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
const n = state[1]
|
|
460
|
+
const initial = n === 0
|
|
461
|
+
const day0 = nextDay(now, day, initial)
|
|
462
|
+
const start = beginningOfDay(day0)
|
|
463
|
+
const end = endOfDay(day0)
|
|
464
|
+
const interval = Interval.make(start, end)
|
|
465
|
+
return core.succeed(
|
|
466
|
+
[
|
|
467
|
+
[end, n + 1] as const,
|
|
468
|
+
n,
|
|
469
|
+
ScheduleDecision.continueWith(interval)
|
|
470
|
+
] as const
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** @internal */
|
|
477
|
+
export const delayed = dual<
|
|
478
|
+
(
|
|
479
|
+
f: (duration: Duration.Duration) => Duration.DurationInput
|
|
480
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
481
|
+
<Env, In, Out>(
|
|
482
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
483
|
+
f: (duration: Duration.Duration) => Duration.DurationInput
|
|
484
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
485
|
+
>(2, (self, f) => delayedEffect(self, (duration) => core.sync(() => f(duration))))
|
|
486
|
+
|
|
487
|
+
/** @internal */
|
|
488
|
+
export const delayedEffect = dual<
|
|
489
|
+
<Env2>(
|
|
490
|
+
f: (duration: Duration.Duration) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
491
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
492
|
+
<Env, In, Out, Env2>(
|
|
493
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
494
|
+
f: (duration: Duration.Duration) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
495
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
496
|
+
>(2, (self, f) => modifyDelayEffect(self, (_, delay) => f(delay)))
|
|
497
|
+
|
|
498
|
+
/** @internal */
|
|
499
|
+
export const delayedSchedule = <Env, In>(
|
|
500
|
+
schedule: Schedule.Schedule<Env, In, Duration.Duration>
|
|
501
|
+
): Schedule.Schedule<Env, In, Duration.Duration> => addDelay(schedule, (x) => x)
|
|
502
|
+
|
|
503
|
+
/** @internal */
|
|
504
|
+
export const delays = <Env, In, Out>(
|
|
505
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
506
|
+
): Schedule.Schedule<Env, In, Duration.Duration> =>
|
|
507
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
508
|
+
pipe(
|
|
509
|
+
self.step(now, input, state),
|
|
510
|
+
core.flatMap((
|
|
511
|
+
[state, _, decision]
|
|
512
|
+
): Effect.Effect<never, never, readonly [any, Duration.Duration, ScheduleDecision.ScheduleDecision]> => {
|
|
513
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
514
|
+
return core.succeed([state, Duration.zero, decision] as const)
|
|
515
|
+
}
|
|
516
|
+
return core.succeed(
|
|
517
|
+
[
|
|
518
|
+
state,
|
|
519
|
+
Duration.millis(Intervals.start(decision.intervals) - now),
|
|
520
|
+
decision
|
|
521
|
+
] as const
|
|
522
|
+
)
|
|
523
|
+
})
|
|
524
|
+
))
|
|
525
|
+
|
|
526
|
+
/** @internal */
|
|
527
|
+
export const mapBoth = dual<
|
|
528
|
+
<In, Out, In2, Out2>(
|
|
529
|
+
options: {
|
|
530
|
+
readonly onInput: (in2: In2) => In
|
|
531
|
+
readonly onOutput: (out: Out) => Out2
|
|
532
|
+
}
|
|
533
|
+
) => <Env>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In2, Out2>,
|
|
534
|
+
<Env, In, Out, In2, Out2>(
|
|
535
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
536
|
+
options: {
|
|
537
|
+
readonly onInput: (in2: In2) => In
|
|
538
|
+
readonly onOutput: (out: Out) => Out2
|
|
539
|
+
}
|
|
540
|
+
) => Schedule.Schedule<Env, In2, Out2>
|
|
541
|
+
>(2, (self, { onInput, onOutput }) => map(mapInput(self, onInput), onOutput))
|
|
542
|
+
|
|
543
|
+
/** @internal */
|
|
544
|
+
export const mapBothEffect = dual<
|
|
545
|
+
<In2, Env2, In, Out, Env3, Out2>(
|
|
546
|
+
options: {
|
|
547
|
+
readonly onInput: (input: In2) => Effect.Effect<Env2, never, In>
|
|
548
|
+
readonly onOutput: (out: Out) => Effect.Effect<Env3, never, Out2>
|
|
549
|
+
}
|
|
550
|
+
) => <Env>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2 | Env3, In2, Out2>,
|
|
551
|
+
<Env, In, Out, In2, Env2, Env3, Out2>(
|
|
552
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
553
|
+
options: {
|
|
554
|
+
readonly onInput: (input: In2) => Effect.Effect<Env2, never, In>
|
|
555
|
+
readonly onOutput: (out: Out) => Effect.Effect<Env3, never, Out2>
|
|
556
|
+
}
|
|
557
|
+
) => Schedule.Schedule<Env | Env2 | Env3, In2, Out2>
|
|
558
|
+
>(2, (self, { onInput, onOutput }) => mapEffect(mapInputEffect(self, onInput), onOutput))
|
|
559
|
+
|
|
560
|
+
/** @internal */
|
|
561
|
+
export const driver = <Env, In, Out>(
|
|
562
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
563
|
+
): Effect.Effect<never, never, Schedule.ScheduleDriver<Env, In, Out>> =>
|
|
564
|
+
pipe(
|
|
565
|
+
ref.make<readonly [Option.Option<Out>, any]>([Option.none(), self.initial]),
|
|
566
|
+
core.map((ref) => new ScheduleDriverImpl(self, ref))
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
/** @internal */
|
|
570
|
+
export const duration = (
|
|
571
|
+
durationInput: Duration.DurationInput
|
|
572
|
+
): Schedule.Schedule<never, unknown, Duration.Duration> => {
|
|
573
|
+
const duration = Duration.decode(durationInput)
|
|
574
|
+
const durationMillis = Duration.toMillis(duration)
|
|
575
|
+
return makeWithState(true as boolean, (now, _, state) =>
|
|
576
|
+
core.succeed(
|
|
577
|
+
state
|
|
578
|
+
? [
|
|
579
|
+
false,
|
|
580
|
+
duration,
|
|
581
|
+
ScheduleDecision.continueWith(Interval.after(now + durationMillis))
|
|
582
|
+
] as const
|
|
583
|
+
: [false, Duration.zero, ScheduleDecision.done] as const
|
|
584
|
+
))
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/** @internal */
|
|
588
|
+
export const either = dual<
|
|
589
|
+
<Env2, In2, Out2>(
|
|
590
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
591
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
592
|
+
Env | Env2,
|
|
593
|
+
In & In2,
|
|
594
|
+
readonly [Out, Out2]
|
|
595
|
+
>,
|
|
596
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
597
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
598
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
599
|
+
) => Schedule.Schedule<
|
|
600
|
+
Env | Env2,
|
|
601
|
+
In & In2,
|
|
602
|
+
readonly [Out, Out2]
|
|
603
|
+
>
|
|
604
|
+
>(2, (self, that) => union(self, that))
|
|
605
|
+
|
|
606
|
+
/** @internal */
|
|
607
|
+
export const eitherWith = dual<
|
|
608
|
+
<Env2, In2, Out2>(
|
|
609
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
610
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
611
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
612
|
+
Env | Env2,
|
|
613
|
+
In & In2,
|
|
614
|
+
readonly [Out, Out2]
|
|
615
|
+
>,
|
|
616
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
617
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
618
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
619
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
620
|
+
) => Schedule.Schedule<
|
|
621
|
+
Env | Env2,
|
|
622
|
+
In & In2,
|
|
623
|
+
readonly [Out, Out2]
|
|
624
|
+
>
|
|
625
|
+
>(3, (self, that, f) => unionWith(self, that, f))
|
|
626
|
+
|
|
627
|
+
/** @internal */
|
|
628
|
+
export const ensuring = dual<
|
|
629
|
+
<X>(
|
|
630
|
+
finalizer: Effect.Effect<never, never, X>
|
|
631
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
632
|
+
<Env, In, Out, X>(
|
|
633
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
634
|
+
finalizer: Effect.Effect<never, never, X>
|
|
635
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
636
|
+
>(2, (self, finalizer) =>
|
|
637
|
+
makeWithState(
|
|
638
|
+
self.initial,
|
|
639
|
+
(now, input, state) =>
|
|
640
|
+
core.flatMap(self.step(now, input, state), ([state, out, decision]) =>
|
|
641
|
+
ScheduleDecision.isDone(decision)
|
|
642
|
+
? core.as(finalizer, [state, out, decision as ScheduleDecision.ScheduleDecision] as const)
|
|
643
|
+
: core.succeed([state, out, decision] as const))
|
|
644
|
+
))
|
|
645
|
+
|
|
646
|
+
/** @internal */
|
|
647
|
+
export const exponential = (
|
|
648
|
+
baseInput: Duration.DurationInput,
|
|
649
|
+
factor = 2.0
|
|
650
|
+
): Schedule.Schedule<never, unknown, Duration.Duration> => {
|
|
651
|
+
const base = Duration.decode(baseInput)
|
|
652
|
+
return delayedSchedule(map(forever, (i) => Duration.times(base, Math.pow(factor, i))))
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** @internal */
|
|
656
|
+
export const fibonacci = (oneInput: Duration.DurationInput): Schedule.Schedule<never, unknown, Duration.Duration> => {
|
|
657
|
+
const one = Duration.decode(oneInput)
|
|
658
|
+
return delayedSchedule(
|
|
659
|
+
pipe(
|
|
660
|
+
unfold(
|
|
661
|
+
[one, one] as const,
|
|
662
|
+
([a, b]) => [b, Duration.sum(a, b)] as const
|
|
663
|
+
),
|
|
664
|
+
map((out) => out[0])
|
|
665
|
+
)
|
|
666
|
+
)
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** @internal */
|
|
670
|
+
export const fixed = (intervalInput: Duration.DurationInput): Schedule.Schedule<never, unknown, number> => {
|
|
671
|
+
const interval = Duration.decode(intervalInput)
|
|
672
|
+
const intervalMillis = Duration.toMillis(interval)
|
|
673
|
+
return makeWithState(
|
|
674
|
+
[Option.none(), 0] as readonly [Option.Option<readonly [number, number]>, number],
|
|
675
|
+
(now, _, [option, n]) =>
|
|
676
|
+
core.sync(() => {
|
|
677
|
+
switch (option._tag) {
|
|
678
|
+
case "None": {
|
|
679
|
+
return [
|
|
680
|
+
[Option.some([now, now + intervalMillis] as const), n + 1] as const,
|
|
681
|
+
n,
|
|
682
|
+
ScheduleDecision.continueWith(Interval.after(now + intervalMillis))
|
|
683
|
+
] as const
|
|
684
|
+
}
|
|
685
|
+
case "Some": {
|
|
686
|
+
const [startMillis, lastRun] = option.value
|
|
687
|
+
const runningBehind = now > (lastRun + intervalMillis)
|
|
688
|
+
const boundary = Equal.equals(interval, Duration.zero)
|
|
689
|
+
? interval
|
|
690
|
+
: Duration.millis(intervalMillis - ((now - startMillis) % intervalMillis))
|
|
691
|
+
const sleepTime = Equal.equals(boundary, Duration.zero) ? interval : boundary
|
|
692
|
+
const nextRun = runningBehind ? now : now + Duration.toMillis(sleepTime)
|
|
693
|
+
return [
|
|
694
|
+
[Option.some([startMillis, nextRun] as const), n + 1] as const,
|
|
695
|
+
n,
|
|
696
|
+
ScheduleDecision.continueWith(Interval.after(nextRun))
|
|
697
|
+
] as const
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/** @internal */
|
|
705
|
+
export const fromDelay = (delay: Duration.DurationInput): Schedule.Schedule<never, unknown, Duration.Duration> =>
|
|
706
|
+
duration(delay)
|
|
707
|
+
|
|
708
|
+
/** @internal */
|
|
709
|
+
export const fromDelays = (
|
|
710
|
+
delay: Duration.DurationInput,
|
|
711
|
+
...delays: Array<Duration.DurationInput>
|
|
712
|
+
): Schedule.Schedule<never, unknown, Duration.Duration> =>
|
|
713
|
+
makeWithState(
|
|
714
|
+
[[delay, ...delays].map((_) => Duration.decode(_)) as Array<Duration.Duration>, true as boolean] as const,
|
|
715
|
+
(now, _, [durations, cont]) =>
|
|
716
|
+
core.sync(() => {
|
|
717
|
+
if (cont) {
|
|
718
|
+
const x = durations[0]!
|
|
719
|
+
const interval = Interval.after(now + Duration.toMillis(x))
|
|
720
|
+
if (durations.length >= 2) {
|
|
721
|
+
return [
|
|
722
|
+
[durations.slice(1), true] as const,
|
|
723
|
+
x,
|
|
724
|
+
ScheduleDecision.continueWith(interval)
|
|
725
|
+
] as const
|
|
726
|
+
}
|
|
727
|
+
const y = durations.slice(1)
|
|
728
|
+
return [
|
|
729
|
+
[[x, ...y] as Array<Duration.Duration>, false] as const,
|
|
730
|
+
x,
|
|
731
|
+
ScheduleDecision.continueWith(interval)
|
|
732
|
+
] as const
|
|
733
|
+
}
|
|
734
|
+
return [[durations, false] as const, Duration.zero, ScheduleDecision.done] as const
|
|
735
|
+
})
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
/** @internal */
|
|
739
|
+
export const fromFunction = <A, B>(f: (a: A) => B): Schedule.Schedule<never, A, B> => map(identity<A>(), f)
|
|
740
|
+
|
|
741
|
+
/** @internal */
|
|
742
|
+
export const hourOfDay = (hour: number): Schedule.Schedule<never, unknown, number> =>
|
|
743
|
+
makeWithState(
|
|
744
|
+
[Number.NEGATIVE_INFINITY, 0] as readonly [number, number],
|
|
745
|
+
(now, _, state) => {
|
|
746
|
+
if (!Number.isInteger(hour) || hour < 0 || 23 < hour) {
|
|
747
|
+
return core.dieSync(() =>
|
|
748
|
+
internalCause.IllegalArgumentException(
|
|
749
|
+
`Invalid argument in: hourOfDay(${hour}). Must be in range 0...23`
|
|
750
|
+
)
|
|
751
|
+
)
|
|
752
|
+
}
|
|
753
|
+
const n = state[1]
|
|
754
|
+
const initial = n === 0
|
|
755
|
+
const hour0 = nextHour(now, hour, initial)
|
|
756
|
+
const start = beginningOfHour(hour0)
|
|
757
|
+
const end = endOfHour(hour0)
|
|
758
|
+
const interval = Interval.make(start, end)
|
|
759
|
+
return core.succeed(
|
|
760
|
+
[
|
|
761
|
+
[end, n + 1] as const,
|
|
762
|
+
n,
|
|
763
|
+
ScheduleDecision.continueWith(interval)
|
|
764
|
+
] as const
|
|
765
|
+
)
|
|
766
|
+
}
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
/** @internal */
|
|
770
|
+
export const identity = <A>(): Schedule.Schedule<never, A, A> =>
|
|
771
|
+
makeWithState(void 0, (now, input, state) =>
|
|
772
|
+
core.succeed(
|
|
773
|
+
[
|
|
774
|
+
state,
|
|
775
|
+
input,
|
|
776
|
+
ScheduleDecision.continueWith(Interval.after(now))
|
|
777
|
+
] as const
|
|
778
|
+
))
|
|
779
|
+
|
|
780
|
+
/** @internal */
|
|
781
|
+
export const intersect = dual<
|
|
782
|
+
<Env2, In2, Out2>(
|
|
783
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
784
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
785
|
+
Env | Env2,
|
|
786
|
+
In & In2,
|
|
787
|
+
readonly [Out, Out2]
|
|
788
|
+
>,
|
|
789
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
790
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
791
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
792
|
+
) => Schedule.Schedule<
|
|
793
|
+
Env | Env2,
|
|
794
|
+
In & In2,
|
|
795
|
+
readonly [Out, Out2]
|
|
796
|
+
>
|
|
797
|
+
>(2, (self, that) => intersectWith(self, that, Intervals.intersect))
|
|
798
|
+
|
|
799
|
+
/** @internal */
|
|
800
|
+
export const intersectWith = dual<
|
|
801
|
+
<Env2, In2, Out2>(
|
|
802
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
803
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
804
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
805
|
+
Env | Env2,
|
|
806
|
+
In & In2,
|
|
807
|
+
readonly [Out, Out2]
|
|
808
|
+
>,
|
|
809
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
810
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
811
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
812
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
813
|
+
) => Schedule.Schedule<
|
|
814
|
+
Env | Env2,
|
|
815
|
+
In & In2,
|
|
816
|
+
readonly [Out, Out2]
|
|
817
|
+
>
|
|
818
|
+
>(3, <Env, In, Out, Env2, In2, Out2>(
|
|
819
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
820
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
821
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
822
|
+
): Schedule.Schedule<
|
|
823
|
+
Env | Env2,
|
|
824
|
+
In & In2,
|
|
825
|
+
readonly [Out, Out2]
|
|
826
|
+
> =>
|
|
827
|
+
makeWithState([self.initial, that.initial] as const, (now, input: In & In2, state) =>
|
|
828
|
+
pipe(
|
|
829
|
+
core.zipWith(
|
|
830
|
+
self.step(now, input, state[0]),
|
|
831
|
+
that.step(now, input, state[1]),
|
|
832
|
+
(a, b) => [a, b] as const
|
|
833
|
+
),
|
|
834
|
+
core.flatMap(([
|
|
835
|
+
[lState, out, lDecision],
|
|
836
|
+
[rState, out2, rDecision]
|
|
837
|
+
]) => {
|
|
838
|
+
if (ScheduleDecision.isContinue(lDecision) && ScheduleDecision.isContinue(rDecision)) {
|
|
839
|
+
return intersectWithLoop(
|
|
840
|
+
self,
|
|
841
|
+
that,
|
|
842
|
+
input,
|
|
843
|
+
lState,
|
|
844
|
+
out,
|
|
845
|
+
lDecision.intervals,
|
|
846
|
+
rState,
|
|
847
|
+
out2,
|
|
848
|
+
rDecision.intervals,
|
|
849
|
+
f
|
|
850
|
+
)
|
|
851
|
+
}
|
|
852
|
+
return core.succeed(
|
|
853
|
+
[
|
|
854
|
+
[lState, rState] as const,
|
|
855
|
+
[out, out2] as const,
|
|
856
|
+
ScheduleDecision.done
|
|
857
|
+
] as const
|
|
858
|
+
)
|
|
859
|
+
})
|
|
860
|
+
)))
|
|
861
|
+
|
|
862
|
+
/** @internal */
|
|
863
|
+
const intersectWithLoop = <State, State1, Env, In, Out, Env1, In1, Out2>(
|
|
864
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
865
|
+
that: Schedule.Schedule<Env1, In1, Out2>,
|
|
866
|
+
input: In & In1,
|
|
867
|
+
lState: State,
|
|
868
|
+
out: Out,
|
|
869
|
+
lInterval: Intervals.Intervals,
|
|
870
|
+
rState: State1,
|
|
871
|
+
out2: Out2,
|
|
872
|
+
rInterval: Intervals.Intervals,
|
|
873
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
874
|
+
): Effect.Effect<
|
|
875
|
+
Env | Env1,
|
|
876
|
+
never,
|
|
877
|
+
readonly [readonly [State, State1], readonly [Out, Out2], ScheduleDecision.ScheduleDecision]
|
|
878
|
+
> => {
|
|
879
|
+
const combined = f(lInterval, rInterval)
|
|
880
|
+
if (Intervals.isNonEmpty(combined)) {
|
|
881
|
+
return core.succeed([
|
|
882
|
+
[lState, rState],
|
|
883
|
+
[out, out2],
|
|
884
|
+
ScheduleDecision.continue(combined)
|
|
885
|
+
])
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
if (pipe(lInterval, Intervals.lessThan(rInterval))) {
|
|
889
|
+
return core.flatMap(self.step(Intervals.end(lInterval), input, lState), ([lState, out, decision]) => {
|
|
890
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
891
|
+
return core.succeed([
|
|
892
|
+
[lState, rState],
|
|
893
|
+
[out, out2],
|
|
894
|
+
ScheduleDecision.done
|
|
895
|
+
])
|
|
896
|
+
}
|
|
897
|
+
return intersectWithLoop(
|
|
898
|
+
self,
|
|
899
|
+
that,
|
|
900
|
+
input,
|
|
901
|
+
lState,
|
|
902
|
+
out,
|
|
903
|
+
decision.intervals,
|
|
904
|
+
rState,
|
|
905
|
+
out2,
|
|
906
|
+
rInterval,
|
|
907
|
+
f
|
|
908
|
+
)
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
return core.flatMap(that.step(Intervals.end(rInterval), input, rState), ([rState, out2, decision]) => {
|
|
912
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
913
|
+
return core.succeed([
|
|
914
|
+
[lState, rState],
|
|
915
|
+
[out, out2],
|
|
916
|
+
ScheduleDecision.done
|
|
917
|
+
])
|
|
918
|
+
}
|
|
919
|
+
return intersectWithLoop(
|
|
920
|
+
self,
|
|
921
|
+
that,
|
|
922
|
+
input,
|
|
923
|
+
lState,
|
|
924
|
+
out,
|
|
925
|
+
lInterval,
|
|
926
|
+
rState,
|
|
927
|
+
out2,
|
|
928
|
+
decision.intervals,
|
|
929
|
+
f
|
|
930
|
+
)
|
|
931
|
+
})
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** @internal */
|
|
935
|
+
export const jittered = <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>): Schedule.Schedule<Env, In, Out> =>
|
|
936
|
+
jitteredWith(self, { min: 0.8, max: 1.2 })
|
|
937
|
+
|
|
938
|
+
/** @internal */
|
|
939
|
+
export const jitteredWith = dual<
|
|
940
|
+
(options: { min?: number; max?: number }) => <Env, In, Out>(
|
|
941
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
942
|
+
) => Schedule.Schedule<Env, In, Out>,
|
|
943
|
+
<Env, In, Out>(
|
|
944
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
945
|
+
options: { min?: number; max?: number }
|
|
946
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
947
|
+
>(2, (self, options) => {
|
|
948
|
+
const { max, min } = Object.assign({ min: 0.8, max: 1.2 }, options)
|
|
949
|
+
return delayedEffect(self, (duration) =>
|
|
950
|
+
core.map(Random.next, (random) => {
|
|
951
|
+
const d = Duration.toMillis(duration)
|
|
952
|
+
const jittered = d * min * (1 - random) + d * max * random
|
|
953
|
+
return Duration.millis(jittered)
|
|
954
|
+
}))
|
|
955
|
+
})
|
|
956
|
+
|
|
957
|
+
/** @internal */
|
|
958
|
+
export const linear = (baseInput: Duration.DurationInput): Schedule.Schedule<never, unknown, Duration.Duration> => {
|
|
959
|
+
const base = Duration.decode(baseInput)
|
|
960
|
+
return delayedSchedule(map(forever, (i) => Duration.times(base, i + 1)))
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/** @internal */
|
|
964
|
+
export const map = dual<
|
|
965
|
+
<Out, Out2>(
|
|
966
|
+
f: (out: Out) => Out2
|
|
967
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out2>,
|
|
968
|
+
<Env, In, Out, Out2>(
|
|
969
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
970
|
+
f: (out: Out) => Out2
|
|
971
|
+
) => Schedule.Schedule<Env, In, Out2>
|
|
972
|
+
>(2, (self, f) => mapEffect(self, (out) => core.sync(() => f(out))))
|
|
973
|
+
|
|
974
|
+
/** @internal */
|
|
975
|
+
export const mapEffect = dual<
|
|
976
|
+
<Out, Env2, Out2>(
|
|
977
|
+
f: (out: Out) => Effect.Effect<Env2, never, Out2>
|
|
978
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out2>,
|
|
979
|
+
<Env, In, Out, Env2, Out2>(
|
|
980
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
981
|
+
f: (out: Out) => Effect.Effect<Env2, never, Out2>
|
|
982
|
+
) => Schedule.Schedule<Env | Env2, In, Out2>
|
|
983
|
+
>(2, (self, f) =>
|
|
984
|
+
makeWithState(
|
|
985
|
+
self.initial,
|
|
986
|
+
(now, input, state) =>
|
|
987
|
+
core.flatMap(self.step(now, input, state), ([state, out, decision]) =>
|
|
988
|
+
core.map(
|
|
989
|
+
f(out),
|
|
990
|
+
(out2) => [state, out2, decision] as const
|
|
991
|
+
))
|
|
992
|
+
))
|
|
993
|
+
|
|
994
|
+
/** @internal */
|
|
995
|
+
export const minuteOfHour = (minute: number): Schedule.Schedule<never, unknown, number> =>
|
|
996
|
+
makeWithState(
|
|
997
|
+
[Number.MIN_SAFE_INTEGER, 0] as readonly [number, number],
|
|
998
|
+
(now, _, state) => {
|
|
999
|
+
if (!Number.isInteger(minute) || minute < 0 || 59 < minute) {
|
|
1000
|
+
return core.dieSync(() =>
|
|
1001
|
+
internalCause.IllegalArgumentException(
|
|
1002
|
+
`Invalid argument in: minuteOfHour(${minute}). Must be in range 0...59`
|
|
1003
|
+
)
|
|
1004
|
+
)
|
|
1005
|
+
}
|
|
1006
|
+
const n = state[1]
|
|
1007
|
+
const initial = n === 0
|
|
1008
|
+
const minute0 = nextMinute(now, minute, initial)
|
|
1009
|
+
const start = beginningOfMinute(minute0)
|
|
1010
|
+
const end = endOfMinute(minute0)
|
|
1011
|
+
const interval = Interval.make(start, end)
|
|
1012
|
+
return core.succeed(
|
|
1013
|
+
[
|
|
1014
|
+
[end, n + 1],
|
|
1015
|
+
n,
|
|
1016
|
+
ScheduleDecision.continueWith(interval)
|
|
1017
|
+
] as const
|
|
1018
|
+
)
|
|
1019
|
+
}
|
|
1020
|
+
)
|
|
1021
|
+
|
|
1022
|
+
/** @internal */
|
|
1023
|
+
export const modifyDelay = dual<
|
|
1024
|
+
<Out>(
|
|
1025
|
+
f: (out: Out, duration: Duration.Duration) => Duration.DurationInput
|
|
1026
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1027
|
+
<Env, In, Out>(
|
|
1028
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1029
|
+
f: (out: Out, duration: Duration.Duration) => Duration.DurationInput
|
|
1030
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
1031
|
+
>(2, (self, f) => modifyDelayEffect(self, (out, duration) => core.sync(() => f(out, duration))))
|
|
1032
|
+
|
|
1033
|
+
/** @internal */
|
|
1034
|
+
export const modifyDelayEffect = dual<
|
|
1035
|
+
<Out, Env2>(
|
|
1036
|
+
f: (out: Out, duration: Duration.Duration) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
1037
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1038
|
+
<Env, In, Out, Env2>(
|
|
1039
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1040
|
+
f: (out: Out, duration: Duration.Duration) => Effect.Effect<Env2, never, Duration.DurationInput>
|
|
1041
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1042
|
+
>(2, (self, f) =>
|
|
1043
|
+
makeWithState(
|
|
1044
|
+
self.initial,
|
|
1045
|
+
(now, input, state) =>
|
|
1046
|
+
core.flatMap(self.step(now, input, state), ([state, out, decision]) => {
|
|
1047
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
1048
|
+
return core.succeed([state, out, decision] as const)
|
|
1049
|
+
}
|
|
1050
|
+
const intervals = decision.intervals
|
|
1051
|
+
const delay = Interval.size(Interval.make(now, Intervals.start(intervals)))
|
|
1052
|
+
return core.map(f(out, delay), (durationInput) => {
|
|
1053
|
+
const duration = Duration.decode(durationInput)
|
|
1054
|
+
const oldStart = Intervals.start(intervals)
|
|
1055
|
+
const newStart = now + Duration.toMillis(duration)
|
|
1056
|
+
const delta = newStart - oldStart
|
|
1057
|
+
const newEnd = Math.min(Math.max(0, Intervals.end(intervals) + delta), Number.MAX_SAFE_INTEGER)
|
|
1058
|
+
const newInterval = Interval.make(newStart, newEnd)
|
|
1059
|
+
return [state, out, ScheduleDecision.continueWith(newInterval)] as const
|
|
1060
|
+
})
|
|
1061
|
+
})
|
|
1062
|
+
))
|
|
1063
|
+
|
|
1064
|
+
/** @internal */
|
|
1065
|
+
export const onDecision = dual<
|
|
1066
|
+
<Out, Env2, X>(
|
|
1067
|
+
f: (out: Out, decision: ScheduleDecision.ScheduleDecision) => Effect.Effect<Env2, never, X>
|
|
1068
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1069
|
+
<Env, In, Out, Env2, X>(
|
|
1070
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1071
|
+
f: (out: Out, decision: ScheduleDecision.ScheduleDecision) => Effect.Effect<Env2, never, X>
|
|
1072
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1073
|
+
>(2, (self, f) =>
|
|
1074
|
+
makeWithState(
|
|
1075
|
+
self.initial,
|
|
1076
|
+
(now, input, state) =>
|
|
1077
|
+
core.flatMap(
|
|
1078
|
+
self.step(now, input, state),
|
|
1079
|
+
([state, out, decision]) => core.as(f(out, decision), [state, out, decision] as const)
|
|
1080
|
+
)
|
|
1081
|
+
))
|
|
1082
|
+
|
|
1083
|
+
/** @internal */
|
|
1084
|
+
export const passthrough = <Env, Input, Output>(
|
|
1085
|
+
self: Schedule.Schedule<Env, Input, Output>
|
|
1086
|
+
): Schedule.Schedule<Env, Input, Input> =>
|
|
1087
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
1088
|
+
pipe(
|
|
1089
|
+
self.step(now, input, state),
|
|
1090
|
+
core.map(([state, _, decision]) => [state, input, decision] as const)
|
|
1091
|
+
))
|
|
1092
|
+
|
|
1093
|
+
/** @internal */
|
|
1094
|
+
export const provideContext = dual<
|
|
1095
|
+
<Env>(
|
|
1096
|
+
context: Context.Context<Env>
|
|
1097
|
+
) => <In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<never, In, Out>,
|
|
1098
|
+
<Env, In, Out>(
|
|
1099
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1100
|
+
context: Context.Context<Env>
|
|
1101
|
+
) => Schedule.Schedule<never, In, Out>
|
|
1102
|
+
>(2, (self, context) =>
|
|
1103
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
1104
|
+
core.provideContext(
|
|
1105
|
+
self.step(now, input, state),
|
|
1106
|
+
context
|
|
1107
|
+
)))
|
|
1108
|
+
|
|
1109
|
+
/** @internal */
|
|
1110
|
+
export const provideService = dual<
|
|
1111
|
+
<T extends Context.Tag<any, any>>(
|
|
1112
|
+
tag: T,
|
|
1113
|
+
service: Context.Tag.Service<T>
|
|
1114
|
+
) => <R, In, Out>(
|
|
1115
|
+
self: Schedule.Schedule<R, In, Out>
|
|
1116
|
+
) => Schedule.Schedule<Exclude<R, Context.Tag.Identifier<T>>, In, Out>,
|
|
1117
|
+
<R, In, Out, T extends Context.Tag<any, any>>(
|
|
1118
|
+
self: Schedule.Schedule<R, In, Out>,
|
|
1119
|
+
tag: T,
|
|
1120
|
+
service: Context.Tag.Service<T>
|
|
1121
|
+
) => Schedule.Schedule<Exclude<R, Context.Tag.Identifier<T>>, In, Out>
|
|
1122
|
+
>(3, <R, In, Out, T extends Context.Tag<any, any>>(
|
|
1123
|
+
self: Schedule.Schedule<R, In, Out>,
|
|
1124
|
+
tag: T,
|
|
1125
|
+
service: Context.Tag.Service<T>
|
|
1126
|
+
): Schedule.Schedule<Exclude<R, Context.Tag.Identifier<T>>, In, Out> =>
|
|
1127
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
1128
|
+
core.contextWithEffect<
|
|
1129
|
+
Exclude<R, Context.Tag.Identifier<T>>,
|
|
1130
|
+
Exclude<R, Context.Tag.Identifier<T>>,
|
|
1131
|
+
never,
|
|
1132
|
+
readonly [any, Out, ScheduleDecision.ScheduleDecision]
|
|
1133
|
+
>((env) =>
|
|
1134
|
+
core.provideContext(
|
|
1135
|
+
// @ts-expect-error
|
|
1136
|
+
self.step(now, input, state),
|
|
1137
|
+
Context.add(env, tag, service)
|
|
1138
|
+
)
|
|
1139
|
+
)))
|
|
1140
|
+
|
|
1141
|
+
/** @internal */
|
|
1142
|
+
export const recurUntil = <A>(f: Predicate<A>): Schedule.Schedule<never, A, A> => untilInput(identity<A>(), f)
|
|
1143
|
+
|
|
1144
|
+
/** @internal */
|
|
1145
|
+
export const recurUntilEffect = <Env, A>(
|
|
1146
|
+
f: (a: A) => Effect.Effect<Env, never, boolean>
|
|
1147
|
+
): Schedule.Schedule<Env, A, A> => untilInputEffect(identity<A>(), f)
|
|
1148
|
+
|
|
1149
|
+
/** @internal */
|
|
1150
|
+
export const recurUntilOption = <A, B>(pf: (a: A) => Option.Option<B>): Schedule.Schedule<never, A, Option.Option<B>> =>
|
|
1151
|
+
untilOutput(map(identity<A>(), pf), Option.isSome)
|
|
1152
|
+
|
|
1153
|
+
/** @internal */
|
|
1154
|
+
export const recurUpTo = (
|
|
1155
|
+
durationInput: Duration.DurationInput
|
|
1156
|
+
): Schedule.Schedule<never, unknown, Duration.Duration> => {
|
|
1157
|
+
const duration = Duration.decode(durationInput)
|
|
1158
|
+
return whileOutput(elapsed, (elapsed) => Duration.lessThan(elapsed, duration))
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/** @internal */
|
|
1162
|
+
export const recurWhile = <A>(f: Predicate<A>): Schedule.Schedule<never, A, A> => whileInput(identity<A>(), f)
|
|
1163
|
+
|
|
1164
|
+
/** @internal */
|
|
1165
|
+
export const recurWhileEffect = <Env, A>(
|
|
1166
|
+
f: (a: A) => Effect.Effect<Env, never, boolean>
|
|
1167
|
+
): Schedule.Schedule<Env, A, A> => whileInputEffect(identity<A>(), f)
|
|
1168
|
+
|
|
1169
|
+
/** @internal */
|
|
1170
|
+
export const recurs = (n: number): Schedule.Schedule<never, unknown, number> => whileOutput(forever, (out) => out < n)
|
|
1171
|
+
|
|
1172
|
+
/** @internal */
|
|
1173
|
+
export const reduce = dual<
|
|
1174
|
+
<Out, Z>(
|
|
1175
|
+
zero: Z,
|
|
1176
|
+
f: (z: Z, out: Out) => Z
|
|
1177
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Z>,
|
|
1178
|
+
<Env, In, Out, Z>(
|
|
1179
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1180
|
+
zero: Z,
|
|
1181
|
+
f: (z: Z, out: Out) => Z
|
|
1182
|
+
) => Schedule.Schedule<Env, In, Z>
|
|
1183
|
+
>(3, (self, zero, f) => reduceEffect(self, zero, (z, out) => core.sync(() => f(z, out))))
|
|
1184
|
+
|
|
1185
|
+
/** @internal */
|
|
1186
|
+
export const reduceEffect = dual<
|
|
1187
|
+
<Out, Env1, Z>(
|
|
1188
|
+
zero: Z,
|
|
1189
|
+
f: (z: Z, out: Out) => Effect.Effect<Env1, never, Z>
|
|
1190
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env1, In, Z>,
|
|
1191
|
+
<Env, In, Out, Env1, Z>(
|
|
1192
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1193
|
+
zero: Z,
|
|
1194
|
+
f: (z: Z, out: Out) => Effect.Effect<Env1, never, Z>
|
|
1195
|
+
) => Schedule.Schedule<Env | Env1, In, Z>
|
|
1196
|
+
>(3, (self, zero, f) =>
|
|
1197
|
+
makeWithState(
|
|
1198
|
+
[self.initial, zero] as const,
|
|
1199
|
+
(now, input, [s, z]) =>
|
|
1200
|
+
core.flatMap(self.step(now, input, s), ([s, out, decision]) =>
|
|
1201
|
+
ScheduleDecision.isDone(decision)
|
|
1202
|
+
? core.succeed([[s, z], z, decision as ScheduleDecision.ScheduleDecision] as const)
|
|
1203
|
+
: core.map(f(z, out), (z2) => [[s, z2], z, decision] as const))
|
|
1204
|
+
))
|
|
1205
|
+
|
|
1206
|
+
/** @internal */
|
|
1207
|
+
export const repeatForever = <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>): Schedule.Schedule<Env, In, Out> =>
|
|
1208
|
+
makeWithState(self.initial, (now, input, state) => {
|
|
1209
|
+
const step = (
|
|
1210
|
+
now: number,
|
|
1211
|
+
input: In,
|
|
1212
|
+
state: any
|
|
1213
|
+
): Effect.Effect<Env, never, readonly [any, Out, ScheduleDecision.ScheduleDecision]> =>
|
|
1214
|
+
core.flatMap(
|
|
1215
|
+
self.step(now, input, state),
|
|
1216
|
+
([state, out, decision]) =>
|
|
1217
|
+
ScheduleDecision.isDone(decision)
|
|
1218
|
+
? step(now, input, self.initial)
|
|
1219
|
+
: core.succeed([state, out, decision])
|
|
1220
|
+
)
|
|
1221
|
+
return step(now, input, state)
|
|
1222
|
+
})
|
|
1223
|
+
|
|
1224
|
+
/** @internal */
|
|
1225
|
+
export const repetitions = <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>): Schedule.Schedule<Env, In, number> =>
|
|
1226
|
+
reduce(self, 0, (n, _) => n + 1)
|
|
1227
|
+
|
|
1228
|
+
/** @internal */
|
|
1229
|
+
export const resetAfter = dual<
|
|
1230
|
+
(
|
|
1231
|
+
duration: Duration.DurationInput
|
|
1232
|
+
) => <Env, In, Out>(
|
|
1233
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
1234
|
+
) => Schedule.Schedule<Env, In, Out>,
|
|
1235
|
+
<Env, In, Out>(
|
|
1236
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1237
|
+
duration: Duration.DurationInput
|
|
1238
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
1239
|
+
>(2, (self, durationInput) => {
|
|
1240
|
+
const duration = Duration.decode(durationInput)
|
|
1241
|
+
return pipe(
|
|
1242
|
+
self,
|
|
1243
|
+
intersect(elapsed),
|
|
1244
|
+
resetWhen(([, time]) => Duration.greaterThanOrEqualTo(time, duration)),
|
|
1245
|
+
map((out) => out[0])
|
|
1246
|
+
)
|
|
1247
|
+
})
|
|
1248
|
+
|
|
1249
|
+
/** @internal */
|
|
1250
|
+
export const resetWhen = dual<
|
|
1251
|
+
<Out>(f: Predicate<Out>) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1252
|
+
<Env, In, Out>(self: Schedule.Schedule<Env, In, Out>, f: Predicate<Out>) => Schedule.Schedule<Env, In, Out>
|
|
1253
|
+
>(2, (self, f) =>
|
|
1254
|
+
makeWithState(
|
|
1255
|
+
self.initial,
|
|
1256
|
+
(now, input, state) =>
|
|
1257
|
+
core.flatMap(self.step(now, input, state), ([state, out, decision]) =>
|
|
1258
|
+
f(out)
|
|
1259
|
+
? self.step(now, input, self.initial)
|
|
1260
|
+
: core.succeed([state, out, decision] as const))
|
|
1261
|
+
))
|
|
1262
|
+
|
|
1263
|
+
/** @internal */
|
|
1264
|
+
export const run = dual<
|
|
1265
|
+
<In>(
|
|
1266
|
+
now: number,
|
|
1267
|
+
input: Iterable<In>
|
|
1268
|
+
) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Effect.Effect<Env, never, Chunk.Chunk<Out>>,
|
|
1269
|
+
<Env, In, Out>(
|
|
1270
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1271
|
+
now: number,
|
|
1272
|
+
input: Iterable<In>
|
|
1273
|
+
) => Effect.Effect<Env, never, Chunk.Chunk<Out>>
|
|
1274
|
+
>(3, (self, now, input) =>
|
|
1275
|
+
pipe(
|
|
1276
|
+
runLoop(self, now, Chunk.fromIterable(input), self.initial, Chunk.empty()),
|
|
1277
|
+
core.map((list) => Chunk.reverse(list))
|
|
1278
|
+
))
|
|
1279
|
+
|
|
1280
|
+
/** @internal */
|
|
1281
|
+
const runLoop = <Env, In, Out>(
|
|
1282
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1283
|
+
now: number,
|
|
1284
|
+
inputs: Chunk.Chunk<In>,
|
|
1285
|
+
state: any,
|
|
1286
|
+
acc: Chunk.Chunk<Out>
|
|
1287
|
+
): Effect.Effect<Env, never, Chunk.Chunk<Out>> => {
|
|
1288
|
+
if (!Chunk.isNonEmpty(inputs)) {
|
|
1289
|
+
return core.succeed(acc)
|
|
1290
|
+
}
|
|
1291
|
+
const input = Chunk.headNonEmpty(inputs)
|
|
1292
|
+
const nextInputs = Chunk.tailNonEmpty(inputs)
|
|
1293
|
+
return core.flatMap(self.step(now, input, state), ([state, out, decision]) => {
|
|
1294
|
+
if (ScheduleDecision.isDone(decision)) {
|
|
1295
|
+
return core.sync(() => pipe(acc, Chunk.prepend(out)))
|
|
1296
|
+
}
|
|
1297
|
+
return runLoop(
|
|
1298
|
+
self,
|
|
1299
|
+
Intervals.start(decision.intervals),
|
|
1300
|
+
nextInputs,
|
|
1301
|
+
state,
|
|
1302
|
+
Chunk.prepend(acc, out)
|
|
1303
|
+
)
|
|
1304
|
+
})
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
/** @internal */
|
|
1308
|
+
export const secondOfMinute = (second: number): Schedule.Schedule<never, unknown, number> =>
|
|
1309
|
+
makeWithState(
|
|
1310
|
+
[Number.NEGATIVE_INFINITY, 0] as readonly [number, number],
|
|
1311
|
+
(now, _, state) => {
|
|
1312
|
+
if (!Number.isInteger(second) || second < 0 || 59 < second) {
|
|
1313
|
+
return core.dieSync(() =>
|
|
1314
|
+
internalCause.IllegalArgumentException(
|
|
1315
|
+
`Invalid argument in: secondOfMinute(${second}). Must be in range 0...59`
|
|
1316
|
+
)
|
|
1317
|
+
)
|
|
1318
|
+
}
|
|
1319
|
+
const n = state[1]
|
|
1320
|
+
const initial = n === 0
|
|
1321
|
+
const second0 = nextSecond(now, second, initial)
|
|
1322
|
+
const start = beginningOfSecond(second0)
|
|
1323
|
+
const end = endOfSecond(second0)
|
|
1324
|
+
const interval = Interval.make(start, end)
|
|
1325
|
+
return core.succeed(
|
|
1326
|
+
[
|
|
1327
|
+
[end, n + 1],
|
|
1328
|
+
n,
|
|
1329
|
+
ScheduleDecision.continueWith(interval)
|
|
1330
|
+
] as const
|
|
1331
|
+
)
|
|
1332
|
+
}
|
|
1333
|
+
)
|
|
1334
|
+
|
|
1335
|
+
/** @internal */
|
|
1336
|
+
export const spaced = (duration: Duration.DurationInput): Schedule.Schedule<never, unknown, number> =>
|
|
1337
|
+
addDelay(forever, () => duration)
|
|
1338
|
+
|
|
1339
|
+
/** @internal */
|
|
1340
|
+
export const succeed = <A>(value: A): Schedule.Schedule<never, unknown, A> => map(forever, () => value)
|
|
1341
|
+
|
|
1342
|
+
/** @internal */
|
|
1343
|
+
export const sync = <A>(evaluate: LazyArg<A>): Schedule.Schedule<never, unknown, A> => map(forever, evaluate)
|
|
1344
|
+
|
|
1345
|
+
/** @internal */
|
|
1346
|
+
export const tapInput = dual<
|
|
1347
|
+
<Env2, In2, X>(
|
|
1348
|
+
f: (input: In2) => Effect.Effect<Env2, never, X>
|
|
1349
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In & In2, Out>,
|
|
1350
|
+
<Env, In, Out, Env2, In2, X>(
|
|
1351
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1352
|
+
f: (input: In2) => Effect.Effect<Env2, never, X>
|
|
1353
|
+
) => Schedule.Schedule<Env | Env2, In & In2, Out>
|
|
1354
|
+
>(2, (self, f) =>
|
|
1355
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
1356
|
+
core.zipRight(
|
|
1357
|
+
f(input),
|
|
1358
|
+
self.step(now, input, state)
|
|
1359
|
+
)))
|
|
1360
|
+
|
|
1361
|
+
/** @internal */
|
|
1362
|
+
export const tapOutput = dual<
|
|
1363
|
+
<Out, XO extends Out, Env2, X>(
|
|
1364
|
+
f: (out: XO) => Effect.Effect<Env2, never, X>
|
|
1365
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1366
|
+
<Env, In, Out, XO extends Out, Env2, X>(
|
|
1367
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1368
|
+
f: (out: XO) => Effect.Effect<Env2, never, X>
|
|
1369
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1370
|
+
>(2, (self, f) =>
|
|
1371
|
+
makeWithState(self.initial, (now, input, state) =>
|
|
1372
|
+
core.tap(
|
|
1373
|
+
self.step(now, input, state),
|
|
1374
|
+
([, out]) => f(out as any)
|
|
1375
|
+
)))
|
|
1376
|
+
|
|
1377
|
+
/** @internal */
|
|
1378
|
+
export const unfold = <A>(initial: A, f: (a: A) => A): Schedule.Schedule<never, unknown, A> =>
|
|
1379
|
+
makeWithState(initial, (now, _, state) =>
|
|
1380
|
+
core.sync(() =>
|
|
1381
|
+
[
|
|
1382
|
+
f(state),
|
|
1383
|
+
state,
|
|
1384
|
+
ScheduleDecision.continueWith(Interval.after(now))
|
|
1385
|
+
] as const
|
|
1386
|
+
))
|
|
1387
|
+
|
|
1388
|
+
/** @internal */
|
|
1389
|
+
export const union = dual<
|
|
1390
|
+
<Env2, In2, Out2>(
|
|
1391
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1392
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
1393
|
+
Env | Env2,
|
|
1394
|
+
In & In2,
|
|
1395
|
+
readonly [Out, Out2]
|
|
1396
|
+
>,
|
|
1397
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
1398
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1399
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1400
|
+
) => Schedule.Schedule<
|
|
1401
|
+
Env | Env2,
|
|
1402
|
+
In & In2,
|
|
1403
|
+
readonly [Out, Out2]
|
|
1404
|
+
>
|
|
1405
|
+
>(2, (self, that) => unionWith(self, that, Intervals.union))
|
|
1406
|
+
|
|
1407
|
+
/** @internal */
|
|
1408
|
+
export const unionWith = dual<
|
|
1409
|
+
<Env2, In2, Out2>(
|
|
1410
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
1411
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
1412
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<
|
|
1413
|
+
Env | Env2,
|
|
1414
|
+
In & In2,
|
|
1415
|
+
readonly [Out, Out2]
|
|
1416
|
+
>,
|
|
1417
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
1418
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1419
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
1420
|
+
f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
|
|
1421
|
+
) => Schedule.Schedule<
|
|
1422
|
+
Env | Env2,
|
|
1423
|
+
In & In2,
|
|
1424
|
+
readonly [Out, Out2]
|
|
1425
|
+
>
|
|
1426
|
+
>(3, (self, that, f) =>
|
|
1427
|
+
makeWithState([self.initial, that.initial] as const, (now, input, state) =>
|
|
1428
|
+
core.zipWith(
|
|
1429
|
+
self.step(now, input, state[0]),
|
|
1430
|
+
that.step(now, input, state[1]),
|
|
1431
|
+
([lState, l, lDecision], [rState, r, rDecision]) => {
|
|
1432
|
+
if (ScheduleDecision.isDone(lDecision) && ScheduleDecision.isDone(rDecision)) {
|
|
1433
|
+
return [[lState, rState] as const, [l, r] as const, ScheduleDecision.done] as const
|
|
1434
|
+
}
|
|
1435
|
+
if (ScheduleDecision.isDone(lDecision) && ScheduleDecision.isContinue(rDecision)) {
|
|
1436
|
+
return [
|
|
1437
|
+
[lState, rState] as const,
|
|
1438
|
+
[l, r] as const,
|
|
1439
|
+
ScheduleDecision.continue(rDecision.intervals)
|
|
1440
|
+
] as const
|
|
1441
|
+
}
|
|
1442
|
+
if (ScheduleDecision.isContinue(lDecision) && ScheduleDecision.isDone(rDecision)) {
|
|
1443
|
+
return [
|
|
1444
|
+
[lState, rState] as const,
|
|
1445
|
+
[l, r],
|
|
1446
|
+
ScheduleDecision.continue(lDecision.intervals)
|
|
1447
|
+
] as const
|
|
1448
|
+
}
|
|
1449
|
+
if (ScheduleDecision.isContinue(lDecision) && ScheduleDecision.isContinue(rDecision)) {
|
|
1450
|
+
const combined = f(lDecision.intervals, rDecision.intervals)
|
|
1451
|
+
return [
|
|
1452
|
+
[lState, rState] as const,
|
|
1453
|
+
[l, r],
|
|
1454
|
+
ScheduleDecision.continue(combined)
|
|
1455
|
+
] as const
|
|
1456
|
+
}
|
|
1457
|
+
throw new Error(
|
|
1458
|
+
"BUG: Schedule.unionWith - please report an issue at https://github.com/Effect-TS/io/issues"
|
|
1459
|
+
)
|
|
1460
|
+
}
|
|
1461
|
+
)))
|
|
1462
|
+
|
|
1463
|
+
/** @internal */
|
|
1464
|
+
export const untilInput = dual<
|
|
1465
|
+
<In>(f: Predicate<In>) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1466
|
+
<Env, In, Out>(self: Schedule.Schedule<Env, In, Out>, f: Predicate<In>) => Schedule.Schedule<Env, In, Out>
|
|
1467
|
+
>(2, (self, f) => check(self, (input, _) => !f(input)))
|
|
1468
|
+
|
|
1469
|
+
/** @internal */
|
|
1470
|
+
export const untilInputEffect = dual<
|
|
1471
|
+
<In, Env2>(
|
|
1472
|
+
f: (input: In) => Effect.Effect<Env2, never, boolean>
|
|
1473
|
+
) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1474
|
+
<Env, In, Out, Env2>(
|
|
1475
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1476
|
+
f: (input: In) => Effect.Effect<Env2, never, boolean>
|
|
1477
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1478
|
+
>(2, (self, f) => checkEffect(self, (input, _) => effect.negate(f(input))))
|
|
1479
|
+
|
|
1480
|
+
/** @internal */
|
|
1481
|
+
export const untilOutput = dual<
|
|
1482
|
+
<Out>(f: Predicate<Out>) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1483
|
+
<Env, In, Out>(self: Schedule.Schedule<Env, In, Out>, f: Predicate<Out>) => Schedule.Schedule<Env, In, Out>
|
|
1484
|
+
>(2, (self, f) => check(self, (_, out) => !f(out)))
|
|
1485
|
+
|
|
1486
|
+
/** @internal */
|
|
1487
|
+
export const untilOutputEffect = dual<
|
|
1488
|
+
<Out, Env2>(
|
|
1489
|
+
f: (out: Out) => Effect.Effect<Env2, never, boolean>
|
|
1490
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1491
|
+
<Env, In, Out, Env2>(
|
|
1492
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1493
|
+
f: (out: Out) => Effect.Effect<Env2, never, boolean>
|
|
1494
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1495
|
+
>(2, (self, f) => checkEffect(self, (_, out) => effect.negate(f(out))))
|
|
1496
|
+
|
|
1497
|
+
/** @internal */
|
|
1498
|
+
export const upTo = dual<
|
|
1499
|
+
(duration: Duration.DurationInput) => <Env, In, Out>(
|
|
1500
|
+
self: Schedule.Schedule<Env, In, Out>
|
|
1501
|
+
) => Schedule.Schedule<Env, In, Out>,
|
|
1502
|
+
<Env, In, Out>(
|
|
1503
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1504
|
+
duration: Duration.DurationInput
|
|
1505
|
+
) => Schedule.Schedule<Env, In, Out>
|
|
1506
|
+
>(2, (self, duration) => zipLeft(self, recurUpTo(duration)))
|
|
1507
|
+
|
|
1508
|
+
/** @internal */
|
|
1509
|
+
export const whileInput = dual<
|
|
1510
|
+
<In>(f: Predicate<In>) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1511
|
+
<Env, In, Out>(self: Schedule.Schedule<Env, In, Out>, f: Predicate<In>) => Schedule.Schedule<Env, In, Out>
|
|
1512
|
+
>(2, (self, f) => check(self, (input, _) => f(input)))
|
|
1513
|
+
|
|
1514
|
+
/** @internal */
|
|
1515
|
+
export const whileInputEffect = dual<
|
|
1516
|
+
<In, Env2>(
|
|
1517
|
+
f: (input: In) => Effect.Effect<Env2, never, boolean>
|
|
1518
|
+
) => <Env, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In, Out>,
|
|
1519
|
+
<Env, In, Out, Env2>(
|
|
1520
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1521
|
+
f: (input: In) => Effect.Effect<Env2, never, boolean>
|
|
1522
|
+
) => Schedule.Schedule<Env | Env2, In, Out>
|
|
1523
|
+
>(2, (self, f) => checkEffect(self, (input, _) => f(input)))
|
|
1524
|
+
|
|
1525
|
+
/** @internal */
|
|
1526
|
+
export const whileOutput = dual<
|
|
1527
|
+
<Out>(f: Predicate<Out>) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env, In, Out>,
|
|
1528
|
+
<Env, In, Out>(self: Schedule.Schedule<Env, In, Out>, f: Predicate<Out>) => Schedule.Schedule<Env, In, Out>
|
|
1529
|
+
>(2, (self, f) => check(self, (_, out) => f(out)))
|
|
1530
|
+
|
|
1531
|
+
/** @internal */
|
|
1532
|
+
export const whileOutputEffect = dual<
|
|
1533
|
+
<Out, Env1>(
|
|
1534
|
+
f: (out: Out) => Effect.Effect<Env1, never, boolean>
|
|
1535
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env1, In, Out>,
|
|
1536
|
+
<Env, In, Out, Env1>(
|
|
1537
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1538
|
+
f: (out: Out) => Effect.Effect<Env1, never, boolean>
|
|
1539
|
+
) => Schedule.Schedule<Env | Env1, In, Out>
|
|
1540
|
+
>(2, (self, f) => checkEffect(self, (_, out) => f(out)))
|
|
1541
|
+
|
|
1542
|
+
/** @internal */
|
|
1543
|
+
export const windowed = (intervalInput: Duration.DurationInput): Schedule.Schedule<never, unknown, number> => {
|
|
1544
|
+
const interval = Duration.decode(intervalInput)
|
|
1545
|
+
const millis = Duration.toMillis(interval)
|
|
1546
|
+
return makeWithState(
|
|
1547
|
+
[Option.none(), 0] as readonly [Option.Option<number>, number],
|
|
1548
|
+
(now, _, [option, n]) => {
|
|
1549
|
+
switch (option._tag) {
|
|
1550
|
+
case "None": {
|
|
1551
|
+
return core.succeed(
|
|
1552
|
+
[
|
|
1553
|
+
[Option.some(now), n + 1],
|
|
1554
|
+
n,
|
|
1555
|
+
ScheduleDecision.continueWith(Interval.after(now + millis))
|
|
1556
|
+
] as const
|
|
1557
|
+
)
|
|
1558
|
+
}
|
|
1559
|
+
case "Some": {
|
|
1560
|
+
return core.succeed(
|
|
1561
|
+
[
|
|
1562
|
+
[Option.some(option.value), n + 1],
|
|
1563
|
+
n,
|
|
1564
|
+
ScheduleDecision.continueWith(
|
|
1565
|
+
Interval.after(now + (millis - ((now - option.value) % millis)))
|
|
1566
|
+
)
|
|
1567
|
+
] as const
|
|
1568
|
+
)
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
)
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
/** @internal */
|
|
1576
|
+
export const zipLeft = dual<
|
|
1577
|
+
<Env2, In2, Out2>(
|
|
1578
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1579
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In & In2, Out>,
|
|
1580
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
1581
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1582
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1583
|
+
) => Schedule.Schedule<Env | Env2, In & In2, Out>
|
|
1584
|
+
>(2, (self, that) => map(intersect(self, that), (out) => out[0]))
|
|
1585
|
+
|
|
1586
|
+
/** @internal */
|
|
1587
|
+
export const zipRight = dual<
|
|
1588
|
+
<Env2, In2, Out2>(
|
|
1589
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1590
|
+
) => <Env, In, Out>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In & In2, Out2>,
|
|
1591
|
+
<Env, In, Out, Env2, In2, Out2>(
|
|
1592
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1593
|
+
that: Schedule.Schedule<Env2, In2, Out2>
|
|
1594
|
+
) => Schedule.Schedule<Env | Env2, In & In2, Out2>
|
|
1595
|
+
>(2, (self, that) => map(intersect(self, that), (out) => out[1]))
|
|
1596
|
+
|
|
1597
|
+
/** @internal */
|
|
1598
|
+
export const zipWith = dual<
|
|
1599
|
+
<Env2, In2, Out2, Out, Out3>(
|
|
1600
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
1601
|
+
f: (out: Out, out2: Out2) => Out3
|
|
1602
|
+
) => <Env, In>(self: Schedule.Schedule<Env, In, Out>) => Schedule.Schedule<Env | Env2, In & In2, Out3>,
|
|
1603
|
+
<Env, In, Out, Env2, In2, Out2, Out3>(
|
|
1604
|
+
self: Schedule.Schedule<Env, In, Out>,
|
|
1605
|
+
that: Schedule.Schedule<Env2, In2, Out2>,
|
|
1606
|
+
f: (out: Out, out2: Out2) => Out3
|
|
1607
|
+
) => Schedule.Schedule<Env | Env2, In & In2, Out3>
|
|
1608
|
+
>(3, (self, that, f) => map(intersect(self, that), ([out, out2]) => f(out, out2)))
|
|
1609
|
+
|
|
1610
|
+
// -----------------------------------------------------------------------------
|
|
1611
|
+
// Seconds
|
|
1612
|
+
// -----------------------------------------------------------------------------
|
|
1613
|
+
|
|
1614
|
+
/** @internal */
|
|
1615
|
+
export const beginningOfSecond = (now: number): number => {
|
|
1616
|
+
const date = new Date(now)
|
|
1617
|
+
return new Date(
|
|
1618
|
+
date.getFullYear(),
|
|
1619
|
+
date.getMonth(),
|
|
1620
|
+
date.getDate(),
|
|
1621
|
+
date.getHours(),
|
|
1622
|
+
date.getMinutes(),
|
|
1623
|
+
date.getSeconds(),
|
|
1624
|
+
0
|
|
1625
|
+
).getTime()
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
/** @internal */
|
|
1629
|
+
export const endOfSecond = (now: number): number => {
|
|
1630
|
+
const date = new Date(beginningOfSecond(now))
|
|
1631
|
+
return date.setSeconds(date.getSeconds() + 1)
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/** @internal */
|
|
1635
|
+
export const nextSecond = (now: number, second: number, initial: boolean): number => {
|
|
1636
|
+
const date = new Date(now)
|
|
1637
|
+
if (date.getSeconds() === second && initial) {
|
|
1638
|
+
return now
|
|
1639
|
+
}
|
|
1640
|
+
if (date.getSeconds() < second) {
|
|
1641
|
+
return date.setSeconds(second)
|
|
1642
|
+
}
|
|
1643
|
+
// Set seconds to the provided value and add one minute
|
|
1644
|
+
const newDate = new Date(date.setSeconds(second))
|
|
1645
|
+
return newDate.setTime(newDate.getTime() + 1000 * 60)
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
// -----------------------------------------------------------------------------
|
|
1649
|
+
// Minutes
|
|
1650
|
+
// -----------------------------------------------------------------------------
|
|
1651
|
+
|
|
1652
|
+
/** @internal */
|
|
1653
|
+
export const beginningOfMinute = (now: number): number => {
|
|
1654
|
+
const date = new Date(now)
|
|
1655
|
+
return new Date(
|
|
1656
|
+
date.getFullYear(),
|
|
1657
|
+
date.getMonth(),
|
|
1658
|
+
date.getDate(),
|
|
1659
|
+
date.getHours(),
|
|
1660
|
+
date.getMinutes(),
|
|
1661
|
+
0,
|
|
1662
|
+
0
|
|
1663
|
+
).getTime()
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/** @internal */
|
|
1667
|
+
export const endOfMinute = (now: number): number => {
|
|
1668
|
+
const date = new Date(beginningOfMinute(now))
|
|
1669
|
+
return date.setMinutes(date.getMinutes() + 1)
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
/** @internal */
|
|
1673
|
+
export const nextMinute = (now: number, minute: number, initial: boolean): number => {
|
|
1674
|
+
const date = new Date(now)
|
|
1675
|
+
if (date.getMinutes() === minute && initial) {
|
|
1676
|
+
return now
|
|
1677
|
+
}
|
|
1678
|
+
if (date.getMinutes() < minute) {
|
|
1679
|
+
return date.setMinutes(minute)
|
|
1680
|
+
}
|
|
1681
|
+
// Set minutes to the provided value and add one hour
|
|
1682
|
+
const newDate = new Date(date.setMinutes(minute))
|
|
1683
|
+
return newDate.setTime(newDate.getTime() + 1000 * 60 * 60)
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// -----------------------------------------------------------------------------
|
|
1687
|
+
// Hours
|
|
1688
|
+
// -----------------------------------------------------------------------------
|
|
1689
|
+
|
|
1690
|
+
/** @internal */
|
|
1691
|
+
export const beginningOfHour = (now: number): number => {
|
|
1692
|
+
const date = new Date(now)
|
|
1693
|
+
return new Date(
|
|
1694
|
+
date.getFullYear(),
|
|
1695
|
+
date.getMonth(),
|
|
1696
|
+
date.getDate(),
|
|
1697
|
+
date.getHours(),
|
|
1698
|
+
0,
|
|
1699
|
+
0,
|
|
1700
|
+
0
|
|
1701
|
+
).getTime()
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
/** @internal */
|
|
1705
|
+
export const endOfHour = (now: number): number => {
|
|
1706
|
+
const date = new Date(beginningOfHour(now))
|
|
1707
|
+
return date.setHours(date.getHours() + 1)
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/** @internal */
|
|
1711
|
+
export const nextHour = (now: number, hour: number, initial: boolean): number => {
|
|
1712
|
+
const date = new Date(now)
|
|
1713
|
+
if (date.getHours() === hour && initial) {
|
|
1714
|
+
return now
|
|
1715
|
+
}
|
|
1716
|
+
if (date.getHours() < hour) {
|
|
1717
|
+
return date.setHours(hour)
|
|
1718
|
+
}
|
|
1719
|
+
// Set hours to the provided value and add one day
|
|
1720
|
+
const newDate = new Date(date.setHours(hour))
|
|
1721
|
+
return newDate.setTime(newDate.getTime() + 1000 * 60 * 60 * 24)
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
// -----------------------------------------------------------------------------
|
|
1725
|
+
// Days
|
|
1726
|
+
// -----------------------------------------------------------------------------
|
|
1727
|
+
|
|
1728
|
+
/** @internal */
|
|
1729
|
+
export const beginningOfDay = (now: number): number => {
|
|
1730
|
+
const date = new Date(now)
|
|
1731
|
+
return new Date(
|
|
1732
|
+
date.getFullYear(),
|
|
1733
|
+
date.getMonth(),
|
|
1734
|
+
date.getDate(),
|
|
1735
|
+
0,
|
|
1736
|
+
0,
|
|
1737
|
+
0,
|
|
1738
|
+
0
|
|
1739
|
+
).getTime()
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
/** @internal */
|
|
1743
|
+
export const endOfDay = (now: number): number => {
|
|
1744
|
+
const date = new Date(beginningOfDay(now))
|
|
1745
|
+
return date.setDate(date.getDate() + 1)
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
/** @internal */
|
|
1749
|
+
export const nextDay = (now: number, dayOfWeek: number, initial: boolean): number => {
|
|
1750
|
+
const date = new Date(now)
|
|
1751
|
+
if (date.getDay() === dayOfWeek && initial) {
|
|
1752
|
+
return now
|
|
1753
|
+
}
|
|
1754
|
+
const nextDayOfWeek = (7 + dayOfWeek - date.getDay()) % 7
|
|
1755
|
+
return date.setDate(date.getDate() + (nextDayOfWeek === 0 ? 7 : nextDayOfWeek))
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/** @internal */
|
|
1759
|
+
export const nextDayOfMonth = (now: number, day: number, initial: boolean): number => {
|
|
1760
|
+
const date = new Date(now)
|
|
1761
|
+
if (date.getDate() === day && initial) {
|
|
1762
|
+
return now
|
|
1763
|
+
}
|
|
1764
|
+
if (date.getDate() < day) {
|
|
1765
|
+
return date.setDate(day)
|
|
1766
|
+
}
|
|
1767
|
+
return findNextMonth(now, day, 1)
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
/** @internal */
|
|
1771
|
+
export const findNextMonth = (now: number, day: number, months: number): number => {
|
|
1772
|
+
const d = new Date(now)
|
|
1773
|
+
const tmp1 = new Date(d.setDate(day))
|
|
1774
|
+
const tmp2 = new Date(tmp1.setMonth(tmp1.getMonth() + months))
|
|
1775
|
+
if (tmp2.getDate() === day) {
|
|
1776
|
+
const d2 = new Date(now)
|
|
1777
|
+
const tmp3 = new Date(d2.setDate(day))
|
|
1778
|
+
return tmp3.setMonth(tmp3.getMonth() + months)
|
|
1779
|
+
}
|
|
1780
|
+
return findNextMonth(now, day, months + 1)
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// circular with Effect
|
|
1784
|
+
|
|
1785
|
+
/** @internal */
|
|
1786
|
+
export const repeat_Effect = dual<
|
|
1787
|
+
<R1, A extends A0, A0, B>(
|
|
1788
|
+
schedule: Schedule.Schedule<R1, A, B>
|
|
1789
|
+
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, B>,
|
|
1790
|
+
<R, E, A extends A0, A0, R1, B>(
|
|
1791
|
+
self: Effect.Effect<R, E, A>,
|
|
1792
|
+
schedule: Schedule.Schedule<R1, A0, B>
|
|
1793
|
+
) => Effect.Effect<R | R1, E, B>
|
|
1794
|
+
>(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => core.fail(e)))
|
|
1795
|
+
|
|
1796
|
+
/** @internal */
|
|
1797
|
+
export const repeatOrElse_Effect = dual<
|
|
1798
|
+
<R2, A extends A0, A0, B, E, R3, E2>(
|
|
1799
|
+
schedule: Schedule.Schedule<R2, A, B>,
|
|
1800
|
+
orElse: (error: E, option: Option.Option<B>) => Effect.Effect<R3, E2, B>
|
|
1801
|
+
) => <R>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2 | R3, E2, B>,
|
|
1802
|
+
<R, E, A extends A0, A0, R2, B, R3, E2>(
|
|
1803
|
+
self: Effect.Effect<R, E, A>,
|
|
1804
|
+
schedule: Schedule.Schedule<R2, A0, B>,
|
|
1805
|
+
orElse: (error: E, option: Option.Option<B>) => Effect.Effect<R3, E2, B>
|
|
1806
|
+
) => Effect.Effect<R | R2 | R3, E2, B>
|
|
1807
|
+
>(3, (self, schedule, orElse) =>
|
|
1808
|
+
core.flatMap(driver(schedule), (driver) =>
|
|
1809
|
+
core.matchEffect(self, {
|
|
1810
|
+
onFailure: (error) => orElse(error, Option.none()),
|
|
1811
|
+
onSuccess: (value) => repeatOrElseEffectLoop(self, driver, orElse, value)
|
|
1812
|
+
})))
|
|
1813
|
+
|
|
1814
|
+
/** @internal */
|
|
1815
|
+
const repeatOrElseEffectLoop = <R, E, A extends A0, A0, R1, B, R2, E2, C>(
|
|
1816
|
+
self: Effect.Effect<R, E, A>,
|
|
1817
|
+
driver: Schedule.ScheduleDriver<R1, A0, B>,
|
|
1818
|
+
orElse: (error: E, option: Option.Option<B>) => Effect.Effect<R2, E2, C>,
|
|
1819
|
+
value: A
|
|
1820
|
+
): Effect.Effect<R | R1 | R2, E2, B | C> => {
|
|
1821
|
+
return core.matchEffect(driver.next(value), {
|
|
1822
|
+
onFailure: () => core.orDie(driver.last()),
|
|
1823
|
+
onSuccess: (b) =>
|
|
1824
|
+
core.matchEffect(self, {
|
|
1825
|
+
onFailure: (error) => orElse(error, Option.some(b)),
|
|
1826
|
+
onSuccess: (value) => repeatOrElseEffectLoop(self, driver, orElse, value)
|
|
1827
|
+
})
|
|
1828
|
+
})
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
/** @internal */
|
|
1832
|
+
export const repeatUntil_Effect = dual<
|
|
1833
|
+
{
|
|
1834
|
+
<A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, B>
|
|
1835
|
+
<A>(f: Predicate<A>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
1836
|
+
},
|
|
1837
|
+
{
|
|
1838
|
+
<R, E, A, B extends A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, B>
|
|
1839
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, A>
|
|
1840
|
+
}
|
|
1841
|
+
>(
|
|
1842
|
+
2,
|
|
1843
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) =>
|
|
1844
|
+
repeatUntilEffect_Effect(self, (a) => core.sync(() => f(a)))
|
|
1845
|
+
)
|
|
1846
|
+
|
|
1847
|
+
/** @internal */
|
|
1848
|
+
export const repeatUntilEffect_Effect: {
|
|
1849
|
+
<A, R2, E2>(
|
|
1850
|
+
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1851
|
+
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>
|
|
1852
|
+
<R, E, A, R2, E2>(
|
|
1853
|
+
self: Effect.Effect<R, E, A>,
|
|
1854
|
+
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1855
|
+
): Effect.Effect<R | R2, E | E2, A>
|
|
1856
|
+
} = dual<
|
|
1857
|
+
<A, R2, E2>(
|
|
1858
|
+
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1859
|
+
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>,
|
|
1860
|
+
<R, E, A, R2, E2>(
|
|
1861
|
+
self: Effect.Effect<R, E, A>,
|
|
1862
|
+
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1863
|
+
) => Effect.Effect<R | R2, E | E2, A>
|
|
1864
|
+
>(2, (self, f) =>
|
|
1865
|
+
core.flatMap(self, (a) =>
|
|
1866
|
+
core.flatMap(f(a), (result) =>
|
|
1867
|
+
result ?
|
|
1868
|
+
core.succeed(a) :
|
|
1869
|
+
core.flatMap(
|
|
1870
|
+
core.yieldNow(),
|
|
1871
|
+
() => repeatUntilEffect_Effect(self, f)
|
|
1872
|
+
))))
|
|
1873
|
+
|
|
1874
|
+
/** @internal */
|
|
1875
|
+
export const repeatWhile_Effect = dual<
|
|
1876
|
+
<A>(f: Predicate<A>) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
1877
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) => Effect.Effect<R, E, A>
|
|
1878
|
+
>(2, (self, f) => repeatWhileEffect_Effect(self, (a) => core.sync(() => f(a))))
|
|
1879
|
+
|
|
1880
|
+
/** @internal */
|
|
1881
|
+
export const repeatWhileEffect_Effect = dual<
|
|
1882
|
+
<R1, A, E2>(
|
|
1883
|
+
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1884
|
+
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
1885
|
+
<R, E, R1, A, E2>(
|
|
1886
|
+
self: Effect.Effect<R, E, A>,
|
|
1887
|
+
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1888
|
+
) => Effect.Effect<R | R1, E | E2, A>
|
|
1889
|
+
>(2, (self, f) => repeatUntilEffect_Effect(self, (a) => effect.negate(f(a))))
|
|
1890
|
+
|
|
1891
|
+
/** @internal */
|
|
1892
|
+
export const retry_Effect = dual<
|
|
1893
|
+
<R1, E extends E0, E0, B>(
|
|
1894
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1895
|
+
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, A>,
|
|
1896
|
+
<R, E extends E0, E0, A, R1, B>(
|
|
1897
|
+
self: Effect.Effect<R, E, A>,
|
|
1898
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1899
|
+
) => Effect.Effect<R | R1, E, A>
|
|
1900
|
+
>(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => core.fail(e)))
|
|
1901
|
+
|
|
1902
|
+
/** @internal */
|
|
1903
|
+
export const retryN_Effect = dual<
|
|
1904
|
+
(n: number) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
1905
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, n: number) => Effect.Effect<R, E, A>
|
|
1906
|
+
>(2, (self, n) => retryN_EffectLoop(self, n))
|
|
1907
|
+
|
|
1908
|
+
/** @internal */
|
|
1909
|
+
const retryN_EffectLoop = <R, E, A>(
|
|
1910
|
+
self: Effect.Effect<R, E, A>,
|
|
1911
|
+
n: number
|
|
1912
|
+
): Effect.Effect<R, E, A> => {
|
|
1913
|
+
return core.catchAll(self, (e) =>
|
|
1914
|
+
n < 0 ?
|
|
1915
|
+
core.fail(e) :
|
|
1916
|
+
core.flatMap(core.yieldNow(), () => retryN_EffectLoop(self, n - 1)))
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
/** @internal */
|
|
1920
|
+
export const retryOrElse_Effect = dual<
|
|
1921
|
+
<R1, E extends E3, A1, R2, E2, A2, E3>(
|
|
1922
|
+
policy: Schedule.Schedule<R1, E3, A1>,
|
|
1923
|
+
orElse: (e: E, out: A1) => Effect.Effect<R2, E2, A2>
|
|
1924
|
+
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1 | R2, E | E2, A | A2>,
|
|
1925
|
+
<R, E extends E3, A, R1, A1, R2, E2, A2, E3>(
|
|
1926
|
+
self: Effect.Effect<R, E, A>,
|
|
1927
|
+
policy: Schedule.Schedule<R1, E3, A1>,
|
|
1928
|
+
orElse: (e: E, out: A1) => Effect.Effect<R2, E2, A2>
|
|
1929
|
+
) => Effect.Effect<R | R1 | R2, E | E2, A | A2>
|
|
1930
|
+
>(3, (self, policy, orElse) =>
|
|
1931
|
+
core.flatMap(
|
|
1932
|
+
driver(policy),
|
|
1933
|
+
(driver) => retryOrElse_EffectLoop(self, driver, orElse)
|
|
1934
|
+
))
|
|
1935
|
+
|
|
1936
|
+
/** @internal */
|
|
1937
|
+
const retryOrElse_EffectLoop = <R, E, A, R1, A1, R2, E2, A2>(
|
|
1938
|
+
self: Effect.Effect<R, E, A>,
|
|
1939
|
+
driver: Schedule.ScheduleDriver<R1, E, A1>,
|
|
1940
|
+
orElse: (e: E, out: A1) => Effect.Effect<R2, E2, A2>
|
|
1941
|
+
): Effect.Effect<R | R1 | R2, E | E2, A | A2> => {
|
|
1942
|
+
return core.catchAll(
|
|
1943
|
+
self,
|
|
1944
|
+
(e) =>
|
|
1945
|
+
core.matchEffect(driver.next(e), {
|
|
1946
|
+
onFailure: () =>
|
|
1947
|
+
pipe(
|
|
1948
|
+
driver.last(),
|
|
1949
|
+
core.orDie,
|
|
1950
|
+
core.flatMap((out) => orElse(e, out))
|
|
1951
|
+
),
|
|
1952
|
+
onSuccess: () => retryOrElse_EffectLoop(self, driver, orElse)
|
|
1953
|
+
})
|
|
1954
|
+
)
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
/** @internal */
|
|
1958
|
+
export const retryUntil_Effect = dual<
|
|
1959
|
+
{
|
|
1960
|
+
<E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E2, A>
|
|
1961
|
+
<E>(f: Predicate<E>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
1962
|
+
},
|
|
1963
|
+
{
|
|
1964
|
+
<R, E, A, E2 extends E>(self: Effect.Effect<R, E, A>, f: Refinement<E, E2>): Effect.Effect<R, E2, A>
|
|
1965
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>): Effect.Effect<R, E, A>
|
|
1966
|
+
}
|
|
1967
|
+
>(2, <R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) =>
|
|
1968
|
+
retryUntilEffect_Effect(
|
|
1969
|
+
self,
|
|
1970
|
+
(e) => core.sync(() => f(e))
|
|
1971
|
+
))
|
|
1972
|
+
|
|
1973
|
+
/** @internal */
|
|
1974
|
+
export const retryUntilEffect_Effect: {
|
|
1975
|
+
<R1, E, E2>(
|
|
1976
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
1977
|
+
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R1 | R, E | E2, A>
|
|
1978
|
+
<R, E, A, R1, E2>(
|
|
1979
|
+
self: Effect.Effect<R, E, A>,
|
|
1980
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
1981
|
+
): Effect.Effect<R | R1, E | E2, A>
|
|
1982
|
+
} = dual<
|
|
1983
|
+
<R1, E, E2>(
|
|
1984
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
1985
|
+
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
1986
|
+
<R, E, A, R1, E2>(
|
|
1987
|
+
self: Effect.Effect<R, E, A>,
|
|
1988
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
1989
|
+
) => Effect.Effect<R | R1, E | E2, A>
|
|
1990
|
+
>(2, (self, f) =>
|
|
1991
|
+
core.catchAll(self, (e) =>
|
|
1992
|
+
core.flatMap(f(e), (b) =>
|
|
1993
|
+
b ?
|
|
1994
|
+
core.fail(e) :
|
|
1995
|
+
core.flatMap(
|
|
1996
|
+
core.yieldNow(),
|
|
1997
|
+
() => retryUntilEffect_Effect(self, f)
|
|
1998
|
+
))))
|
|
1999
|
+
|
|
2000
|
+
/** @internal */
|
|
2001
|
+
export const retryWhile_Effect = dual<
|
|
2002
|
+
<E>(f: Predicate<E>) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
2003
|
+
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) => Effect.Effect<R, E, A>
|
|
2004
|
+
>(2, (self, f) => retryWhileEffect_Effect(self, (e) => core.sync(() => f(e))))
|
|
2005
|
+
|
|
2006
|
+
/** @internal */
|
|
2007
|
+
export const retryWhileEffect_Effect = dual<
|
|
2008
|
+
<R1, E, E2>(
|
|
2009
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2010
|
+
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
2011
|
+
<R, E, A, R1, E2>(
|
|
2012
|
+
self: Effect.Effect<R, E, A>,
|
|
2013
|
+
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2014
|
+
) => Effect.Effect<R | R1, E | E2, A>
|
|
2015
|
+
>(2, (self, f) => retryUntilEffect_Effect(self, (e) => effect.negate(f(e))))
|
|
2016
|
+
|
|
2017
|
+
/** @internal */
|
|
2018
|
+
export const schedule_Effect = dual<
|
|
2019
|
+
<R2, Out>(
|
|
2020
|
+
schedule: Schedule.Schedule<R2, unknown, Out>
|
|
2021
|
+
) => <R, E, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E, Out>,
|
|
2022
|
+
<R, E, A, R2, Out>(
|
|
2023
|
+
self: Effect.Effect<R, E, A>,
|
|
2024
|
+
schedule: Schedule.Schedule<R2, unknown, Out>
|
|
2025
|
+
) => Effect.Effect<R | R2, E, Out>
|
|
2026
|
+
>(2, <R, E, A, R2, Out>(
|
|
2027
|
+
self: Effect.Effect<R, E, A>,
|
|
2028
|
+
schedule: Schedule.Schedule<R2, unknown, Out>
|
|
2029
|
+
) => scheduleFrom_Effect(self, void 0, schedule))
|
|
2030
|
+
|
|
2031
|
+
/** @internal */
|
|
2032
|
+
export const scheduleFrom_Effect = dual<
|
|
2033
|
+
<R2, In, Out>(
|
|
2034
|
+
initial: In,
|
|
2035
|
+
schedule: Schedule.Schedule<R2, In, Out>
|
|
2036
|
+
) => <R, E>(self: Effect.Effect<R, E, In>) => Effect.Effect<R | R2, E, Out>,
|
|
2037
|
+
<R, E, In, R2, Out>(
|
|
2038
|
+
self: Effect.Effect<R, E, In>,
|
|
2039
|
+
initial: In,
|
|
2040
|
+
schedule: Schedule.Schedule<R2, In, Out>
|
|
2041
|
+
) => Effect.Effect<R | R2, E, Out>
|
|
2042
|
+
>(3, (self, initial, schedule) =>
|
|
2043
|
+
core.flatMap(
|
|
2044
|
+
driver(schedule),
|
|
2045
|
+
(driver) => scheduleFrom_EffectLoop(self, initial, driver)
|
|
2046
|
+
))
|
|
2047
|
+
|
|
2048
|
+
/** @internal */
|
|
2049
|
+
const scheduleFrom_EffectLoop = <R, E, In, R2, Out>(
|
|
2050
|
+
self: Effect.Effect<R, E, In>,
|
|
2051
|
+
initial: In,
|
|
2052
|
+
driver: Schedule.ScheduleDriver<R2, In, Out>
|
|
2053
|
+
): Effect.Effect<R | R2, E, Out> =>
|
|
2054
|
+
core.matchEffect(driver.next(initial), {
|
|
2055
|
+
onFailure: () => core.orDie(driver.last()),
|
|
2056
|
+
onSuccess: () => core.flatMap(self, (a) => scheduleFrom_EffectLoop(self, a, driver))
|
|
2057
|
+
})
|
|
2058
|
+
|
|
2059
|
+
/** @internal */
|
|
2060
|
+
export const count: Schedule.Schedule<never, unknown, number> = unfold(0, (n) => n + 1)
|
|
2061
|
+
|
|
2062
|
+
/** @internal */
|
|
2063
|
+
export const elapsed: Schedule.Schedule<never, unknown, Duration.Duration> = makeWithState(
|
|
2064
|
+
Option.none() as Option.Option<number>,
|
|
2065
|
+
(now, _, state) => {
|
|
2066
|
+
switch (state._tag) {
|
|
2067
|
+
case "None": {
|
|
2068
|
+
return core.succeed(
|
|
2069
|
+
[
|
|
2070
|
+
Option.some(now),
|
|
2071
|
+
Duration.zero,
|
|
2072
|
+
ScheduleDecision.continueWith(Interval.after(now))
|
|
2073
|
+
] as const
|
|
2074
|
+
)
|
|
2075
|
+
}
|
|
2076
|
+
case "Some": {
|
|
2077
|
+
return core.succeed(
|
|
2078
|
+
[
|
|
2079
|
+
Option.some(state.value),
|
|
2080
|
+
Duration.millis(now - state.value),
|
|
2081
|
+
ScheduleDecision.continueWith(Interval.after(now))
|
|
2082
|
+
] as const
|
|
2083
|
+
)
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
)
|
|
2088
|
+
|
|
2089
|
+
/** @internal */
|
|
2090
|
+
export const forever: Schedule.Schedule<never, unknown, number> = unfold(0, (n) => n + 1)
|
|
2091
|
+
|
|
2092
|
+
/** @internal */
|
|
2093
|
+
export const once: Schedule.Schedule<never, unknown, void> = asUnit(recurs(1))
|
|
2094
|
+
|
|
2095
|
+
/** @internal */
|
|
2096
|
+
export const stop: Schedule.Schedule<never, unknown, void> = asUnit(recurs(0))
|