@clayroach/effect 3.19.14-source-capture.8 → 3.19.14-source-trace.2

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.
Files changed (452) hide show
  1. package/SourceLocation/package.json +6 -0
  2. package/dist/cjs/Effect.js +2 -28
  3. package/dist/cjs/Effect.js.map +1 -1
  4. package/dist/cjs/FiberRef.js +12 -1
  5. package/dist/cjs/FiberRef.js.map +1 -1
  6. package/dist/cjs/Layer.js +2 -24
  7. package/dist/cjs/Layer.js.map +1 -1
  8. package/dist/cjs/RuntimeFlags.js +1 -29
  9. package/dist/cjs/RuntimeFlags.js.map +1 -1
  10. package/dist/cjs/SourceLocation.js +60 -0
  11. package/dist/cjs/SourceLocation.js.map +1 -0
  12. package/dist/cjs/Tracer.js +1 -15
  13. package/dist/cjs/Tracer.js.map +1 -1
  14. package/dist/cjs/Utils.js +1 -1
  15. package/dist/cjs/Utils.js.map +1 -1
  16. package/dist/cjs/index.js +3 -1
  17. package/dist/cjs/index.js.map +1 -1
  18. package/dist/cjs/internal/clock.js +1 -1
  19. package/dist/cjs/internal/clock.js.map +1 -1
  20. package/dist/cjs/internal/core.js +17 -50
  21. package/dist/cjs/internal/core.js.map +1 -1
  22. package/dist/cjs/internal/effect/circular.js +18 -30
  23. package/dist/cjs/internal/effect/circular.js.map +1 -1
  24. package/dist/cjs/internal/fiberRuntime.js +16 -65
  25. package/dist/cjs/internal/fiberRuntime.js.map +1 -1
  26. package/dist/cjs/internal/layer/circular.js +1 -5
  27. package/dist/cjs/internal/layer/circular.js.map +1 -1
  28. package/dist/cjs/internal/layer.js +1 -3
  29. package/dist/cjs/internal/layer.js.map +1 -1
  30. package/dist/cjs/internal/logger.js +25 -2
  31. package/dist/cjs/internal/logger.js.map +1 -1
  32. package/dist/cjs/internal/runtimeFlags.js +2 -11
  33. package/dist/cjs/internal/runtimeFlags.js.map +1 -1
  34. package/dist/cjs/internal/tracer.js +1 -114
  35. package/dist/cjs/internal/tracer.js.map +1 -1
  36. package/dist/dts/Config.d.ts +2 -2
  37. package/dist/dts/Config.d.ts.map +1 -1
  38. package/dist/dts/Effect.d.ts +8 -29
  39. package/dist/dts/Effect.d.ts.map +1 -1
  40. package/dist/dts/FiberRef.d.ts +12 -0
  41. package/dist/dts/FiberRef.d.ts.map +1 -1
  42. package/dist/dts/Layer.d.ts +0 -22
  43. package/dist/dts/Layer.d.ts.map +1 -1
  44. package/dist/dts/RuntimeFlags.d.ts +0 -28
  45. package/dist/dts/RuntimeFlags.d.ts.map +1 -1
  46. package/dist/dts/SourceLocation.d.ts +88 -0
  47. package/dist/dts/SourceLocation.d.ts.map +1 -0
  48. package/dist/dts/Tracer.d.ts +0 -15
  49. package/dist/dts/Tracer.d.ts.map +1 -1
  50. package/dist/dts/index.d.ts +6 -0
  51. package/dist/dts/index.d.ts.map +1 -1
  52. package/dist/dts/internal/core.d.ts.map +1 -1
  53. package/dist/dts/internal/layer.d.ts.map +1 -1
  54. package/dist/dts/internal/runtimeFlags.d.ts.map +1 -1
  55. package/dist/esm/Effect.js +0 -26
  56. package/dist/esm/Effect.js.map +1 -1
  57. package/dist/esm/FiberRef.js +11 -0
  58. package/dist/esm/FiberRef.js.map +1 -1
  59. package/dist/esm/Layer.js +0 -22
  60. package/dist/esm/Layer.js.map +1 -1
  61. package/dist/esm/RuntimeFlags.js +0 -28
  62. package/dist/esm/RuntimeFlags.js.map +1 -1
  63. package/dist/esm/SourceLocation.js +51 -0
  64. package/dist/esm/SourceLocation.js.map +1 -0
  65. package/dist/esm/Tracer.js +0 -14
  66. package/dist/esm/Tracer.js.map +1 -1
  67. package/dist/esm/Utils.js +1 -1
  68. package/dist/esm/Utils.js.map +1 -1
  69. package/dist/esm/index.js +6 -0
  70. package/dist/esm/index.js.map +1 -1
  71. package/dist/esm/internal/clock.js +1 -1
  72. package/dist/esm/internal/clock.js.map +1 -1
  73. package/dist/esm/internal/core.js +12 -45
  74. package/dist/esm/internal/core.js.map +1 -1
  75. package/dist/esm/internal/effect/circular.js +18 -30
  76. package/dist/esm/internal/effect/circular.js.map +1 -1
  77. package/dist/esm/internal/fiberRuntime.js +13 -60
  78. package/dist/esm/internal/fiberRuntime.js.map +1 -1
  79. package/dist/esm/internal/layer/circular.js +0 -4
  80. package/dist/esm/internal/layer/circular.js.map +1 -1
  81. package/dist/esm/internal/layer.js +0 -2
  82. package/dist/esm/internal/layer.js.map +1 -1
  83. package/dist/esm/internal/logger.js +25 -2
  84. package/dist/esm/internal/logger.js.map +1 -1
  85. package/dist/esm/internal/runtimeFlags.js +1 -9
  86. package/dist/esm/internal/runtimeFlags.js.map +1 -1
  87. package/dist/esm/internal/tracer.js +0 -111
  88. package/dist/esm/internal/tracer.js.map +1 -1
  89. package/package.json +12 -1
  90. package/src/Arbitrary.ts +1101 -0
  91. package/src/Array.ts +3589 -0
  92. package/src/BigDecimal.ts +1349 -0
  93. package/src/BigInt.ts +643 -0
  94. package/src/Boolean.ts +287 -0
  95. package/src/Brand.ts +360 -0
  96. package/src/Cache.ts +281 -0
  97. package/src/Cause.ts +1555 -0
  98. package/src/Channel.ts +2355 -0
  99. package/src/ChildExecutorDecision.ts +146 -0
  100. package/src/Chunk.ts +1495 -0
  101. package/src/Clock.ts +111 -0
  102. package/src/Config.ts +542 -0
  103. package/src/ConfigError.ts +270 -0
  104. package/src/ConfigProvider.ts +333 -0
  105. package/src/ConfigProviderPathPatch.ts +100 -0
  106. package/src/Console.ts +226 -0
  107. package/src/Context.ts +585 -0
  108. package/src/Cron.ts +706 -0
  109. package/src/Data.ts +596 -0
  110. package/src/DateTime.ts +1686 -0
  111. package/src/DefaultServices.ts +34 -0
  112. package/src/Deferred.ts +301 -0
  113. package/src/Differ.ts +450 -0
  114. package/src/Duration.ts +1000 -0
  115. package/src/Effect.ts +14817 -0
  116. package/src/Effectable.ts +107 -0
  117. package/src/Either.ts +1040 -0
  118. package/src/Encoding.ts +195 -0
  119. package/src/Equal.ts +98 -0
  120. package/src/Equivalence.ts +235 -0
  121. package/src/ExecutionPlan.ts +308 -0
  122. package/src/ExecutionStrategy.ts +119 -0
  123. package/src/Exit.ts +467 -0
  124. package/src/FastCheck.ts +9 -0
  125. package/src/Fiber.ts +744 -0
  126. package/src/FiberHandle.ts +540 -0
  127. package/src/FiberId.ts +195 -0
  128. package/src/FiberMap.ts +656 -0
  129. package/src/FiberRef.ts +444 -0
  130. package/src/FiberRefs.ts +204 -0
  131. package/src/FiberRefsPatch.ts +105 -0
  132. package/src/FiberSet.ts +491 -0
  133. package/src/FiberStatus.ts +108 -0
  134. package/src/Function.ts +1222 -0
  135. package/src/GlobalValue.ts +53 -0
  136. package/src/Graph.ts +3732 -0
  137. package/src/GroupBy.ts +103 -0
  138. package/src/HKT.ts +45 -0
  139. package/src/Hash.ts +195 -0
  140. package/src/HashMap.ts +519 -0
  141. package/src/HashRing.ts +317 -0
  142. package/src/HashSet.ts +2346 -0
  143. package/src/Inspectable.ts +287 -0
  144. package/src/Iterable.ts +1119 -0
  145. package/src/JSONSchema.ts +1044 -0
  146. package/src/KeyedPool.ts +167 -0
  147. package/src/Layer.ts +1228 -0
  148. package/src/LayerMap.ts +436 -0
  149. package/src/List.ts +977 -0
  150. package/src/LogLevel.ts +285 -0
  151. package/src/LogSpan.ts +25 -0
  152. package/src/Logger.ts +702 -0
  153. package/src/Mailbox.ts +268 -0
  154. package/src/ManagedRuntime.ts +180 -0
  155. package/src/Match.ts +1477 -0
  156. package/src/MergeDecision.ts +95 -0
  157. package/src/MergeState.ts +172 -0
  158. package/src/MergeStrategy.ts +107 -0
  159. package/src/Metric.ts +780 -0
  160. package/src/MetricBoundaries.ts +69 -0
  161. package/src/MetricHook.ts +151 -0
  162. package/src/MetricKey.ts +224 -0
  163. package/src/MetricKeyType.ts +262 -0
  164. package/src/MetricLabel.ts +47 -0
  165. package/src/MetricPair.ts +71 -0
  166. package/src/MetricPolling.ts +148 -0
  167. package/src/MetricRegistry.ts +48 -0
  168. package/src/MetricState.ts +257 -0
  169. package/src/Micro.ts +4405 -0
  170. package/src/ModuleVersion.ts +18 -0
  171. package/src/MutableHashMap.ts +411 -0
  172. package/src/MutableHashSet.ts +706 -0
  173. package/src/MutableList.ts +297 -0
  174. package/src/MutableQueue.ts +227 -0
  175. package/src/MutableRef.ts +202 -0
  176. package/src/NonEmptyIterable.ts +32 -0
  177. package/src/Number.ts +1071 -0
  178. package/src/Option.ts +2170 -0
  179. package/src/Order.ts +373 -0
  180. package/src/Ordering.ts +111 -0
  181. package/src/ParseResult.ts +2031 -0
  182. package/src/PartitionedSemaphore.ts +200 -0
  183. package/src/Pipeable.ts +566 -0
  184. package/src/Pool.ts +204 -0
  185. package/src/Predicate.ts +1405 -0
  186. package/src/Pretty.ts +205 -0
  187. package/src/PrimaryKey.ts +23 -0
  188. package/src/PubSub.ts +182 -0
  189. package/src/Queue.ts +644 -0
  190. package/src/Random.ts +204 -0
  191. package/src/RateLimiter.ts +138 -0
  192. package/src/RcMap.ts +141 -0
  193. package/src/RcRef.ts +122 -0
  194. package/src/Readable.ts +93 -0
  195. package/src/Record.ts +1274 -0
  196. package/src/RedBlackTree.ts +421 -0
  197. package/src/Redacted.ts +144 -0
  198. package/src/Ref.ts +180 -0
  199. package/src/RegExp.ts +38 -0
  200. package/src/Reloadable.ts +127 -0
  201. package/src/Request.ts +347 -0
  202. package/src/RequestBlock.ts +118 -0
  203. package/src/RequestResolver.ts +366 -0
  204. package/src/Resource.ts +119 -0
  205. package/src/Runtime.ts +383 -0
  206. package/src/RuntimeFlags.ts +336 -0
  207. package/src/RuntimeFlagsPatch.ts +183 -0
  208. package/src/STM.ts +2045 -0
  209. package/src/Schedule.ts +2219 -0
  210. package/src/ScheduleDecision.ts +62 -0
  211. package/src/ScheduleInterval.ts +151 -0
  212. package/src/ScheduleIntervals.ts +122 -0
  213. package/src/Scheduler.ts +353 -0
  214. package/src/Schema.ts +10914 -0
  215. package/src/SchemaAST.ts +3043 -0
  216. package/src/Scope.ts +204 -0
  217. package/src/ScopedCache.ts +151 -0
  218. package/src/ScopedRef.ts +117 -0
  219. package/src/Secret.ts +88 -0
  220. package/src/SingleProducerAsyncInput.ts +67 -0
  221. package/src/Sink.ts +1461 -0
  222. package/src/SortedMap.ts +287 -0
  223. package/src/SortedSet.ts +390 -0
  224. package/src/SourceLocation.ts +108 -0
  225. package/src/Stream.ts +6468 -0
  226. package/src/StreamEmit.ts +136 -0
  227. package/src/StreamHaltStrategy.ts +123 -0
  228. package/src/Streamable.ts +45 -0
  229. package/src/String.ts +778 -0
  230. package/src/Struct.ts +243 -0
  231. package/src/Subscribable.ts +100 -0
  232. package/src/SubscriptionRef.ts +298 -0
  233. package/src/Supervisor.ts +240 -0
  234. package/src/Symbol.ts +29 -0
  235. package/src/SynchronizedRef.ts +270 -0
  236. package/src/TArray.ts +495 -0
  237. package/src/TDeferred.ts +100 -0
  238. package/src/TMap.ts +515 -0
  239. package/src/TPriorityQueue.ts +223 -0
  240. package/src/TPubSub.ts +200 -0
  241. package/src/TQueue.ts +432 -0
  242. package/src/TRandom.ts +129 -0
  243. package/src/TReentrantLock.ts +224 -0
  244. package/src/TRef.ts +178 -0
  245. package/src/TSemaphore.ts +129 -0
  246. package/src/TSet.ts +365 -0
  247. package/src/TSubscriptionRef.ts +192 -0
  248. package/src/Take.ts +258 -0
  249. package/src/TestAnnotation.ts +158 -0
  250. package/src/TestAnnotationMap.ts +119 -0
  251. package/src/TestAnnotations.ts +117 -0
  252. package/src/TestClock.ts +556 -0
  253. package/src/TestConfig.ts +47 -0
  254. package/src/TestContext.ts +36 -0
  255. package/src/TestLive.ts +53 -0
  256. package/src/TestServices.ts +390 -0
  257. package/src/TestSized.ts +55 -0
  258. package/src/Tracer.ts +182 -0
  259. package/src/Trie.ts +840 -0
  260. package/src/Tuple.ts +305 -0
  261. package/src/Types.ts +353 -0
  262. package/src/Unify.ts +113 -0
  263. package/src/UpstreamPullRequest.ts +117 -0
  264. package/src/UpstreamPullStrategy.ts +121 -0
  265. package/src/Utils.ts +809 -0
  266. package/src/index.ts +1568 -0
  267. package/src/internal/array.ts +8 -0
  268. package/src/internal/blockedRequests.ts +520 -0
  269. package/src/internal/cache.ts +733 -0
  270. package/src/internal/cause.ts +1050 -0
  271. package/src/internal/channel/channelExecutor.ts +1200 -0
  272. package/src/internal/channel/channelState.ts +134 -0
  273. package/src/internal/channel/childExecutorDecision.ts +96 -0
  274. package/src/internal/channel/continuation.ts +200 -0
  275. package/src/internal/channel/mergeDecision.ts +113 -0
  276. package/src/internal/channel/mergeState.ts +120 -0
  277. package/src/internal/channel/mergeStrategy.ts +72 -0
  278. package/src/internal/channel/singleProducerAsyncInput.ts +259 -0
  279. package/src/internal/channel/subexecutor.ts +229 -0
  280. package/src/internal/channel/upstreamPullRequest.ts +84 -0
  281. package/src/internal/channel/upstreamPullStrategy.ts +87 -0
  282. package/src/internal/channel.ts +2603 -0
  283. package/src/internal/clock.ts +95 -0
  284. package/src/internal/completedRequestMap.ts +9 -0
  285. package/src/internal/concurrency.ts +54 -0
  286. package/src/internal/config.ts +716 -0
  287. package/src/internal/configError.ts +304 -0
  288. package/src/internal/configProvider/pathPatch.ts +97 -0
  289. package/src/internal/configProvider.ts +799 -0
  290. package/src/internal/console.ts +153 -0
  291. package/src/internal/context.ts +337 -0
  292. package/src/internal/core-effect.ts +2293 -0
  293. package/src/internal/core-stream.ts +998 -0
  294. package/src/internal/core.ts +3189 -0
  295. package/src/internal/data.ts +36 -0
  296. package/src/internal/dataSource.ts +327 -0
  297. package/src/internal/dateTime.ts +1277 -0
  298. package/src/internal/defaultServices/console.ts +100 -0
  299. package/src/internal/defaultServices.ts +163 -0
  300. package/src/internal/deferred.ts +46 -0
  301. package/src/internal/differ/chunkPatch.ts +211 -0
  302. package/src/internal/differ/contextPatch.ts +232 -0
  303. package/src/internal/differ/hashMapPatch.ts +220 -0
  304. package/src/internal/differ/hashSetPatch.ts +176 -0
  305. package/src/internal/differ/orPatch.ts +311 -0
  306. package/src/internal/differ/readonlyArrayPatch.ts +210 -0
  307. package/src/internal/differ.ts +200 -0
  308. package/src/internal/doNotation.ts +80 -0
  309. package/src/internal/effect/circular.ts +895 -0
  310. package/src/internal/effectable.ts +131 -0
  311. package/src/internal/either.ts +110 -0
  312. package/src/internal/encoding/base64.ts +286 -0
  313. package/src/internal/encoding/base64Url.ts +29 -0
  314. package/src/internal/encoding/common.ts +51 -0
  315. package/src/internal/encoding/hex.ts +315 -0
  316. package/src/internal/errors.ts +7 -0
  317. package/src/internal/executionPlan.ts +114 -0
  318. package/src/internal/executionStrategy.ts +74 -0
  319. package/src/internal/fiber.ts +388 -0
  320. package/src/internal/fiberId.ts +267 -0
  321. package/src/internal/fiberMessage.ts +82 -0
  322. package/src/internal/fiberRefs/patch.ts +144 -0
  323. package/src/internal/fiberRefs.ts +297 -0
  324. package/src/internal/fiberRuntime.ts +3842 -0
  325. package/src/internal/fiberScope.ts +71 -0
  326. package/src/internal/fiberStatus.ts +119 -0
  327. package/src/internal/groupBy.ts +530 -0
  328. package/src/internal/hashMap/array.ts +49 -0
  329. package/src/internal/hashMap/bitwise.ts +32 -0
  330. package/src/internal/hashMap/config.ts +14 -0
  331. package/src/internal/hashMap/keySet.ts +8 -0
  332. package/src/internal/hashMap/node.ts +391 -0
  333. package/src/internal/hashMap.ts +586 -0
  334. package/src/internal/hashSet.ts +323 -0
  335. package/src/internal/keyedPool.ts +244 -0
  336. package/src/internal/layer/circular.ts +214 -0
  337. package/src/internal/layer.ts +1483 -0
  338. package/src/internal/logSpan.ts +20 -0
  339. package/src/internal/logger-circular.ts +24 -0
  340. package/src/internal/logger.ts +522 -0
  341. package/src/internal/mailbox.ts +561 -0
  342. package/src/internal/managedRuntime/circular.ts +6 -0
  343. package/src/internal/managedRuntime.ts +134 -0
  344. package/src/internal/matcher.ts +652 -0
  345. package/src/internal/metric/boundaries.ts +75 -0
  346. package/src/internal/metric/hook.ts +483 -0
  347. package/src/internal/metric/key.ts +167 -0
  348. package/src/internal/metric/keyType.ts +238 -0
  349. package/src/internal/metric/label.ts +41 -0
  350. package/src/internal/metric/pair.ts +48 -0
  351. package/src/internal/metric/polling.ts +149 -0
  352. package/src/internal/metric/registry.ts +187 -0
  353. package/src/internal/metric/state.ts +290 -0
  354. package/src/internal/metric.ts +577 -0
  355. package/src/internal/opCodes/cause.ts +35 -0
  356. package/src/internal/opCodes/channel.ts +83 -0
  357. package/src/internal/opCodes/channelChildExecutorDecision.ts +17 -0
  358. package/src/internal/opCodes/channelMergeDecision.ts +11 -0
  359. package/src/internal/opCodes/channelMergeState.ts +17 -0
  360. package/src/internal/opCodes/channelMergeStrategy.ts +11 -0
  361. package/src/internal/opCodes/channelState.ts +23 -0
  362. package/src/internal/opCodes/channelUpstreamPullRequest.ts +11 -0
  363. package/src/internal/opCodes/channelUpstreamPullStrategy.ts +11 -0
  364. package/src/internal/opCodes/config.ts +65 -0
  365. package/src/internal/opCodes/configError.ts +35 -0
  366. package/src/internal/opCodes/continuation.ts +11 -0
  367. package/src/internal/opCodes/deferred.ts +11 -0
  368. package/src/internal/opCodes/effect.ts +89 -0
  369. package/src/internal/opCodes/layer.ts +59 -0
  370. package/src/internal/opCodes/streamHaltStrategy.ts +23 -0
  371. package/src/internal/option.ts +80 -0
  372. package/src/internal/pool.ts +432 -0
  373. package/src/internal/pubsub.ts +1762 -0
  374. package/src/internal/query.ts +204 -0
  375. package/src/internal/queue.ts +766 -0
  376. package/src/internal/random.ts +161 -0
  377. package/src/internal/rateLimiter.ts +93 -0
  378. package/src/internal/rcMap.ts +285 -0
  379. package/src/internal/rcRef.ts +192 -0
  380. package/src/internal/redBlackTree/iterator.ts +200 -0
  381. package/src/internal/redBlackTree/node.ts +68 -0
  382. package/src/internal/redBlackTree.ts +1245 -0
  383. package/src/internal/redacted.ts +73 -0
  384. package/src/internal/ref.ts +171 -0
  385. package/src/internal/reloadable.ts +140 -0
  386. package/src/internal/request.ts +177 -0
  387. package/src/internal/resource.ts +76 -0
  388. package/src/internal/ringBuffer.ts +68 -0
  389. package/src/internal/runtime.ts +558 -0
  390. package/src/internal/runtimeFlags.ts +178 -0
  391. package/src/internal/runtimeFlagsPatch.ts +103 -0
  392. package/src/internal/schedule/decision.ts +47 -0
  393. package/src/internal/schedule/interval.ts +101 -0
  394. package/src/internal/schedule/intervals.ts +180 -0
  395. package/src/internal/schedule.ts +2199 -0
  396. package/src/internal/schema/errors.ts +191 -0
  397. package/src/internal/schema/schemaId.ts +106 -0
  398. package/src/internal/schema/util.ts +50 -0
  399. package/src/internal/scopedCache.ts +644 -0
  400. package/src/internal/scopedRef.ts +118 -0
  401. package/src/internal/secret.ts +89 -0
  402. package/src/internal/singleShotGen.ts +35 -0
  403. package/src/internal/sink.ts +2120 -0
  404. package/src/internal/stack.ts +10 -0
  405. package/src/internal/stm/core.ts +817 -0
  406. package/src/internal/stm/entry.ts +59 -0
  407. package/src/internal/stm/journal.ts +123 -0
  408. package/src/internal/stm/opCodes/stm.ts +71 -0
  409. package/src/internal/stm/opCodes/stmState.ts +17 -0
  410. package/src/internal/stm/opCodes/strategy.ts +17 -0
  411. package/src/internal/stm/opCodes/tExit.ts +29 -0
  412. package/src/internal/stm/opCodes/tryCommit.ts +11 -0
  413. package/src/internal/stm/stm.ts +1453 -0
  414. package/src/internal/stm/stmState.ts +136 -0
  415. package/src/internal/stm/tArray.ts +550 -0
  416. package/src/internal/stm/tDeferred.ts +81 -0
  417. package/src/internal/stm/tExit.ts +190 -0
  418. package/src/internal/stm/tMap.ts +824 -0
  419. package/src/internal/stm/tPriorityQueue.ts +267 -0
  420. package/src/internal/stm/tPubSub.ts +551 -0
  421. package/src/internal/stm/tQueue.ts +393 -0
  422. package/src/internal/stm/tRandom.ts +140 -0
  423. package/src/internal/stm/tReentrantLock.ts +352 -0
  424. package/src/internal/stm/tRef.ts +195 -0
  425. package/src/internal/stm/tSemaphore.ts +113 -0
  426. package/src/internal/stm/tSet.ts +259 -0
  427. package/src/internal/stm/tSubscriptionRef.ts +286 -0
  428. package/src/internal/stm/tryCommit.ts +34 -0
  429. package/src/internal/stm/txnId.ts +14 -0
  430. package/src/internal/stm/versioned.ts +4 -0
  431. package/src/internal/stream/debounceState.ts +57 -0
  432. package/src/internal/stream/emit.ts +123 -0
  433. package/src/internal/stream/haltStrategy.ts +94 -0
  434. package/src/internal/stream/handoff.ts +187 -0
  435. package/src/internal/stream/handoffSignal.ts +59 -0
  436. package/src/internal/stream/pull.ts +34 -0
  437. package/src/internal/stream/sinkEndReason.ts +30 -0
  438. package/src/internal/stream/zipAllState.ts +88 -0
  439. package/src/internal/stream/zipChunksState.ts +56 -0
  440. package/src/internal/stream.ts +8801 -0
  441. package/src/internal/string-utils.ts +107 -0
  442. package/src/internal/subscriptionRef.ts +138 -0
  443. package/src/internal/supervisor/patch.ts +190 -0
  444. package/src/internal/supervisor.ts +303 -0
  445. package/src/internal/synchronizedRef.ts +114 -0
  446. package/src/internal/take.ts +199 -0
  447. package/src/internal/testing/sleep.ts +27 -0
  448. package/src/internal/testing/suspendedWarningData.ts +85 -0
  449. package/src/internal/testing/warningData.ts +94 -0
  450. package/src/internal/tracer.ts +150 -0
  451. package/src/internal/trie.ts +722 -0
  452. package/src/internal/version.ts +7 -0
@@ -0,0 +1,2219 @@
1
+ /**
2
+ * @since 2.0.0
3
+ */
4
+ import type * as Cause from "./Cause.js"
5
+ import type * as Chunk from "./Chunk.js"
6
+ import type * as Context from "./Context.js"
7
+ import type * as Cron from "./Cron.js"
8
+ import type * as DateTime from "./DateTime.js"
9
+ import type * as Duration from "./Duration.js"
10
+ import type * as Effect from "./Effect.js"
11
+ import type * as Either from "./Either.js"
12
+ import type { LazyArg } from "./Function.js"
13
+ import * as internal from "./internal/schedule.js"
14
+ import type * as Option from "./Option.js"
15
+ import type { Pipeable } from "./Pipeable.js"
16
+ import type { Predicate } from "./Predicate.js"
17
+ import type * as Ref from "./Ref.js"
18
+ import type * as ScheduleDecision from "./ScheduleDecision.js"
19
+ import type * as Intervals from "./ScheduleIntervals.js"
20
+ import type * as Types from "./Types.js"
21
+
22
+ /**
23
+ * @since 2.0.0
24
+ * @category Symbols
25
+ */
26
+ export const ScheduleTypeId: unique symbol = internal.ScheduleTypeId
27
+
28
+ /**
29
+ * @since 2.0.0
30
+ * @category Symbols
31
+ */
32
+ export type ScheduleTypeId = typeof ScheduleTypeId
33
+
34
+ /**
35
+ * @since 2.0.0
36
+ * @category Symbols
37
+ */
38
+ export const ScheduleDriverTypeId: unique symbol = internal.ScheduleDriverTypeId
39
+
40
+ /**
41
+ * @since 2.0.0
42
+ * @category Symbols
43
+ */
44
+ export type ScheduleDriverTypeId = typeof ScheduleDriverTypeId
45
+
46
+ /**
47
+ * A `Schedule<Out, In, R>` defines a recurring schedule, which consumes values
48
+ * of type `In`, and which returns values of type `Out`.
49
+ *
50
+ * The `Schedule` type is structured as follows:
51
+ *
52
+ * ```ts skip-type-checking
53
+ * // ┌─── The type of output produced by the schedule
54
+ * // │ ┌─── The type of input consumed by the schedule
55
+ * // │ │ ┌─── Additional requirements for the schedule
56
+ * // ▼ ▼ ▼
57
+ * Schedule<Out, In, Requirements>
58
+ * ```
59
+ *
60
+ * A schedule operates by consuming values of type `In` (such as errors in the
61
+ * case of `Effect.retry`, or values in the case of `Effect.repeat`) and
62
+ * producing values of type `Out`. It determines when to halt or continue the
63
+ * execution based on input values and its internal state.
64
+ *
65
+ * The inclusion of a `Requirements` parameter allows the schedule to leverage
66
+ * additional services or resources as needed.
67
+ *
68
+ * Schedules are defined as a possibly infinite set of intervals spread out over
69
+ * time. Each interval defines a window in which recurrence is possible.
70
+ *
71
+ * When schedules are used to repeat or retry effects, the starting boundary of
72
+ * each interval produced by a schedule is used as the moment when the effect
73
+ * will be executed again.
74
+ *
75
+ * Schedules can be composed in different ways:
76
+ *
77
+ * - Union: Combines two schedules and recurs if either schedule wants to
78
+ * continue, using the shorter delay.
79
+ * - Intersection: Combines two schedules and recurs only if both schedules want
80
+ * to continue, using the longer delay.
81
+ * - Sequencing: Combines two schedules by running the first one fully, then
82
+ * switching to the second.
83
+ *
84
+ * In addition, schedule inputs and outputs can be transformed, filtered (to
85
+ * terminate a schedule early in response to some input or output), and so
86
+ * forth.
87
+ *
88
+ * A variety of other operators exist for transforming and combining schedules,
89
+ * and the companion object for `Schedule` contains all common types of
90
+ * schedules, both for performing retrying, as well as performing repetition.
91
+ *
92
+ * @category Model
93
+ * @since 2.0.0
94
+ */
95
+ export interface Schedule<out Out, in In = unknown, out R = never> extends Schedule.Variance<Out, In, R>, Pipeable {
96
+ /**
97
+ * Initial State
98
+ */
99
+ readonly initial: any
100
+ /**
101
+ * Schedule Step
102
+ */
103
+ step(
104
+ now: number,
105
+ input: In,
106
+ state: any
107
+ ): Effect.Effect<readonly [any, Out, ScheduleDecision.ScheduleDecision], never, R>
108
+ }
109
+
110
+ /**
111
+ * @since 2.0.0
112
+ */
113
+ export declare namespace Schedule {
114
+ /**
115
+ * @since 2.0.0
116
+ * @category Models
117
+ */
118
+ export interface Variance<out Out, in In, out R> {
119
+ readonly [ScheduleTypeId]: {
120
+ readonly _Out: Types.Covariant<Out>
121
+ readonly _In: Types.Contravariant<In>
122
+ readonly _R: Types.Covariant<R>
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @since 2.0.0
128
+ */
129
+ export interface DriverVariance<out Out, in In, out R> {
130
+ readonly [ScheduleDriverTypeId]: {
131
+ readonly _Out: Types.Covariant<Out>
132
+ readonly _In: Types.Contravariant<In>
133
+ readonly _R: Types.Covariant<R>
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @since 2.0.0
140
+ * @category Models
141
+ */
142
+ export interface ScheduleDriver<out Out, in In = unknown, out R = never> extends Schedule.DriverVariance<Out, In, R> {
143
+ readonly state: Effect.Effect<unknown>
144
+ readonly iterationMeta: Ref.Ref<IterationMetadata>
145
+ readonly last: Effect.Effect<Out, Cause.NoSuchElementException>
146
+ readonly reset: Effect.Effect<void>
147
+ next(input: In): Effect.Effect<Out, Option.Option<never>, R>
148
+ }
149
+
150
+ /**
151
+ * Creates a new schedule with a custom state and step function.
152
+ *
153
+ * **Details**
154
+ *
155
+ * This function constructs a `Schedule` by defining its initial state and a
156
+ * step function, which determines how the schedule progresses over time. The
157
+ * step function is called on each iteration with the current time, an input
158
+ * value, and the schedule's current state. It returns the next state, an output
159
+ * value, and a decision on whether the schedule should continue or stop.
160
+ *
161
+ * This function is useful for creating custom scheduling logic that goes beyond
162
+ * predefined schedules like fixed intervals or exponential backoff. It allows
163
+ * full control over how the schedule behaves at each step.
164
+ *
165
+ * @since 2.0.0
166
+ * @category Constructors
167
+ */
168
+ export const makeWithState: <S, In, Out, R = never>(
169
+ initial: S,
170
+ step: (
171
+ now: number,
172
+ input: In,
173
+ state: S
174
+ ) => Effect.Effect<readonly [S, Out, ScheduleDecision.ScheduleDecision], never, R>
175
+ ) => Schedule<Out, In, R> = internal.makeWithState
176
+
177
+ /**
178
+ * Checks whether a given value is a `Schedule`.
179
+ *
180
+ * @since 2.0.0
181
+ * @category Guards
182
+ */
183
+ export const isSchedule: (u: unknown) => u is Schedule<unknown, never, unknown> = internal.isSchedule
184
+
185
+ /**
186
+ * Adds a delay to every interval in a schedule.
187
+ *
188
+ * **Details**
189
+ *
190
+ * This function modifies a given schedule by applying an additional delay to
191
+ * every interval it defines. The delay is determined by the provided function,
192
+ * which takes the schedule's output and returns a delay duration.
193
+ *
194
+ * @see {@link addDelayEffect} If you need to compute the delay using an effectful function.
195
+ *
196
+ * @since 2.0.0
197
+ * @category Timing & Delay
198
+ */
199
+ export const addDelay: {
200
+ <Out>(f: (out: Out) => Duration.DurationInput): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
201
+ <Out, In, R>(self: Schedule<Out, In, R>, f: (out: Out) => Duration.DurationInput): Schedule<Out, In, R>
202
+ } = internal.addDelay
203
+
204
+ /**
205
+ * Adds an effectfully computed delay to every interval in a schedule.
206
+ *
207
+ * **Details**
208
+ *
209
+ * This function modifies a given schedule by applying an additional delay to
210
+ * each interval, where the delay is determined by an effectful function. The
211
+ * function takes the schedule’s output and returns an effect that produces a
212
+ * delay duration.
213
+ *
214
+ * @see {@link addDelay} If you need to compute the delay using a pure function.
215
+ *
216
+ * @since 2.0.0
217
+ * @category Timing & Delay
218
+ */
219
+ export const addDelayEffect: {
220
+ <Out, R2>(
221
+ f: (out: Out) => Effect.Effect<Duration.DurationInput, never, R2>
222
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
223
+ <Out, In, R, R2>(
224
+ self: Schedule<Out, In, R>,
225
+ f: (out: Out) => Effect.Effect<Duration.DurationInput, never, R2>
226
+ ): Schedule<Out, In, R | R2>
227
+ } = internal.addDelayEffect
228
+
229
+ /**
230
+ * Runs two schedules sequentially, merging their outputs.
231
+ *
232
+ * **Details**
233
+ *
234
+ * This function executes two schedules one after the other. The first schedule
235
+ * runs to completion, and then the second schedule begins execution. Unlike
236
+ * {@link andThenEither}, this function merges the outputs instead of wrapping
237
+ * them in `Either`, allowing both schedules to contribute their results
238
+ * directly.
239
+ *
240
+ * This is useful when a workflow consists of two phases where the second phase
241
+ * should start only after the first one has fully completed.
242
+ *
243
+ * @see {@link andThenEither} If you need to keep track of which schedule
244
+ * produced each result.
245
+ *
246
+ * @since 2.0.0
247
+ * @category Sequential Composition
248
+ */
249
+ export const andThen: {
250
+ <Out2, In2, R2>(
251
+ that: Schedule<Out2, In2, R2>
252
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2 | Out, In & In2, R2 | R>
253
+ <Out, In, R, Out2, In2, R2>(
254
+ self: Schedule<Out, In, R>,
255
+ that: Schedule<Out2, In2, R2>
256
+ ): Schedule<Out | Out2, In & In2, R | R2>
257
+ } = internal.andThen
258
+
259
+ /**
260
+ * Runs two schedules sequentially, collecting results in an `Either`.
261
+ *
262
+ * **Details**
263
+ *
264
+ * This function combines two schedules in sequence. The first schedule runs to
265
+ * completion, and then the second schedule starts and runs to completion as
266
+ * well. The outputs of both schedules are collected into an `Either` structure:
267
+ * - `Either.Left` contains the output of the second schedule.
268
+ * - `Either.Right` contains the output of the first schedule.
269
+ *
270
+ * This is useful when you need to switch from one schedule to another after the
271
+ * first one finishes, while still keeping track of which schedule produced each
272
+ * result.
273
+ *
274
+ * @see {@link andThen} If you need to merge the outputs of both schedules.
275
+ *
276
+ * @since 2.0.0
277
+ * @category Sequential Composition
278
+ */
279
+ export const andThenEither: {
280
+ <Out2, In2, R2>(
281
+ that: Schedule<Out2, In2, R2>
282
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Either.Either<Out2, Out>, In & In2, R2 | R>
283
+ <Out, In, R, Out2, In2, R2>(
284
+ self: Schedule<Out, In, R>,
285
+ that: Schedule<Out2, In2, R2>
286
+ ): Schedule<Either.Either<Out2, Out>, In & In2, R | R2>
287
+ } = internal.andThenEither
288
+
289
+ /**
290
+ * Transforms a schedule to always produce a constant output.
291
+ *
292
+ * **Details**
293
+ *
294
+ * This function modifies a given schedule so that instead of returning its
295
+ * computed outputs, it always returns a constant value.
296
+ *
297
+ * This is useful when you need a schedule for timing but don’t care about its
298
+ * actual output, or when you want to standardize results across different
299
+ * scheduling strategies.
300
+ *
301
+ * @since 2.0.0
302
+ * @category Mapping
303
+ */
304
+ export const as: {
305
+ <Out2>(out: Out2): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R>
306
+ <Out, In, R, Out2>(self: Schedule<Out, In, R>, out: Out2): Schedule<Out2, In, R>
307
+ } = internal.as
308
+
309
+ /**
310
+ * Transforms a schedule to always return `void` instead of its output.
311
+ *
312
+ * **Details**
313
+ *
314
+ * This function modifies a given schedule so that it no longer returns
315
+ * meaningful output—each execution produces `void`. This is useful when the
316
+ * schedule is used only for timing purposes and the actual output of the
317
+ * schedule is irrelevant.
318
+ *
319
+ * The schedule still determines when executions should occur, but the results
320
+ * are discarded.
321
+ *
322
+ * @since 2.0.0
323
+ * @category Mapping
324
+ */
325
+ export const asVoid: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<void, In, R> = internal.asVoid
326
+
327
+ // TODO(4.0): rename to `zip`?
328
+ /**
329
+ * Combines two schedules, preserving both their inputs and outputs.
330
+ *
331
+ * **Details**
332
+ *
333
+ * This function merges two schedules so that both their input types and output
334
+ * types are retained. When executed, the resulting schedule will take inputs
335
+ * from both original schedules and produce a tuple containing both outputs.
336
+ *
337
+ * It recurs if either schedule wants to continue, using the shorter delay.
338
+ *
339
+ * This is useful when you want to track multiple schedules simultaneously,
340
+ * ensuring that both receive the same inputs and produce combined results.
341
+ *
342
+ * @since 2.0.0
343
+ * @category Zipping
344
+ */
345
+ export const bothInOut: {
346
+ <Out2, In2, R2>(
347
+ that: Schedule<Out2, In2, R2>
348
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], readonly [In, In2], R2 | R>
349
+ <Out, In, R, Out2, In2, R2>(
350
+ self: Schedule<Out, In, R>,
351
+ that: Schedule<Out2, In2, R2>
352
+ ): Schedule<[Out, Out2], readonly [In, In2], R | R2>
353
+ } = internal.bothInOut
354
+
355
+ /**
356
+ * Filters schedule executions based on a custom condition.
357
+ *
358
+ * **Details**
359
+ *
360
+ * This function modifies a schedule by applying a custom test function to each
361
+ * input-output pair. The test function determines whether the schedule should
362
+ * continue or stop. If the function returns `true`, the schedule proceeds as
363
+ * usual; if it returns `false`, the schedule terminates.
364
+ *
365
+ * This is useful for conditional retries, custom stop conditions, or
366
+ * dynamically controlling execution based on observed inputs and outputs.
367
+ *
368
+ * @see {@link checkEffect} If you need to use an effectful test function.
369
+ *
370
+ * @since 2.0.0
371
+ * @category Recurrence Conditions
372
+ */
373
+ export const check: {
374
+ <In, Out>(test: (input: In, output: Out) => boolean): <R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
375
+ <Out, In, R>(self: Schedule<Out, In, R>, test: (input: In, output: Out) => boolean): Schedule<Out, In, R>
376
+ } = internal.check
377
+
378
+ /**
379
+ * Conditionally filters schedule executions using an effectful function.
380
+ *
381
+ * **Details**
382
+ *
383
+ * This function modifies a schedule by applying a custom effectful test
384
+ * function to each input-output pair. The test function determines whether the
385
+ * schedule should continue (`true`) or stop (`false`).
386
+ *
387
+ * This is useful when the decision to continue depends on external factors such
388
+ * as database lookups, API calls, or other asynchronous computations.
389
+ *
390
+ * @see {@link check} If you need to use a pure test function.
391
+ *
392
+ * @since 2.0.0
393
+ * @category Recurrence Conditions
394
+ */
395
+ export const checkEffect: {
396
+ <In, Out, R2>(
397
+ test: (input: In, output: Out) => Effect.Effect<boolean, never, R2>
398
+ ): <R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
399
+ <Out, In, R, R2>(
400
+ self: Schedule<Out, In, R>,
401
+ test: (input: In, output: Out) => Effect.Effect<boolean, never, R2>
402
+ ): Schedule<Out, In, R | R2>
403
+ } = internal.checkEffect
404
+
405
+ /**
406
+ * A schedule that collects all inputs into a `Chunk`.
407
+ *
408
+ * **Details**
409
+ *
410
+ * This function creates a schedule that never terminates and continuously
411
+ * collects every input it receives into a `Chunk`. Each time the schedule runs,
412
+ * it appends the new input to the collected list.
413
+ *
414
+ * This is useful when you need to track all received inputs over time, such as
415
+ * logging user actions, recording retry attempts, or accumulating data for
416
+ * later processing.
417
+ *
418
+ * @see {@link collectAllOutputs} If you need to collect outputs instead of
419
+ * inputs.
420
+ *
421
+ * @since 2.0.0
422
+ * @category Collecting
423
+ */
424
+ export const collectAllInputs: <A>() => Schedule<Chunk.Chunk<A>, A> = internal.collectAllInputs
425
+
426
+ /**
427
+ * Collects all outputs of a schedule into a `Chunk`.
428
+ *
429
+ * **Details**
430
+ *
431
+ * This function modifies a given schedule so that instead of returning
432
+ * individual outputs, it accumulates them into a `Chunk`. The schedule
433
+ * continues to run, appending each output to the collected list.
434
+ *
435
+ * This is useful when you need to track all results over time, such as logging
436
+ * outputs, aggregating data, or keeping a history of previous values.
437
+ *
438
+ * @see {@link collectAllInputs} If you need to collect inputs instead of
439
+ * outputs.
440
+ *
441
+ * @since 2.0.0
442
+ * @category Collecting
443
+ */
444
+ export const collectAllOutputs: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Chunk.Chunk<Out>, In, R> =
445
+ internal.collectAllOutputs
446
+
447
+ /**
448
+ * Collects all inputs into a `Chunk` until a condition fails.
449
+ *
450
+ * **Details**
451
+ *
452
+ * This function creates a schedule that continuously collects inputs into a
453
+ * `Chunk` until the given predicate function `f` evaluates to `false`. Once the
454
+ * condition fails, the schedule stops.
455
+ *
456
+ * @since 2.0.0
457
+ * @category Collecting
458
+ */
459
+ export const collectUntil: <A>(f: Predicate<A>) => Schedule<Chunk.Chunk<A>, A> = internal.collectUntil
460
+
461
+ /**
462
+ * Collects all inputs into a `Chunk` until an effectful condition fails.
463
+ *
464
+ * **Details**
465
+ *
466
+ * This function creates a schedule that continuously collects inputs into a
467
+ * `Chunk` until the given effectful predicate `f` returns `false`. The
468
+ * predicate runs as an effect, meaning it can involve asynchronous computations
469
+ * like API calls, database lookups, or randomness.
470
+ *
471
+ * @since 2.0.0
472
+ * @category Collecting
473
+ */
474
+ export const collectUntilEffect: <A, R>(
475
+ f: (a: A) => Effect.Effect<boolean, never, R>
476
+ ) => Schedule<Chunk.Chunk<A>, A, R> = internal.collectUntilEffect
477
+
478
+ /**
479
+ * Collects all inputs into a `Chunk` while a condition holds.
480
+ *
481
+ * **Details**
482
+ *
483
+ * This function creates a schedule that continuously collects inputs into a
484
+ * `Chunk` while the given predicate function `f` evaluates to `true`. As soon
485
+ * as the condition fails, the schedule stops.
486
+ *
487
+ * @since 2.0.0
488
+ * @category Collecting
489
+ */
490
+ export const collectWhile: <A>(f: Predicate<A>) => Schedule<Chunk.Chunk<A>, A> = internal.collectWhile
491
+
492
+ /**
493
+ * Collects all inputs into a `Chunk` while an effectful condition holds.
494
+ *
495
+ * **Details**
496
+ *
497
+ * This function creates a schedule that continuously collects inputs into a
498
+ * `Chunk` while the given effectful predicate `f` returns `true`. The predicate
499
+ * returns an effect, meaning it can depend on external state, such as database
500
+ * queries, API responses, or real-time user conditions.
501
+ *
502
+ * As soon as the effectful condition returns `false`, the schedule stops. This
503
+ * is useful for dynamically controlled data collection, where stopping depends
504
+ * on an external or asynchronous factor.
505
+ *
506
+ * @since 2.0.0
507
+ * @category Collecting
508
+ */
509
+ export const collectWhileEffect: <A, R>(
510
+ f: (a: A) => Effect.Effect<boolean, never, R>
511
+ ) => Schedule<Chunk.Chunk<A>, A, R> = internal.collectWhileEffect
512
+
513
+ /**
514
+ * Chains two schedules, passing the output of the first as the input to the
515
+ * second, while selecting the shorter delay between them.
516
+ *
517
+ * **Details**
518
+ *
519
+ * This function composes two schedules so that the output of the first schedule
520
+ * becomes the input of the second schedule. The first schedule executes first,
521
+ * and once it produces a result, the second schedule receives that result and
522
+ * continues execution based on it.
523
+ *
524
+ * This is useful for building complex scheduling workflows where one schedule's
525
+ * behavior determines how the next schedule behaves.
526
+ *
527
+ * @since 2.0.0
528
+ * @category Composition
529
+ */
530
+ export const compose: {
531
+ <Out2, Out, R2>(that: Schedule<Out2, Out, R2>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R2 | R>
532
+ <Out, In, R, Out2, R2>(self: Schedule<Out, In, R>, that: Schedule<Out2, Out, R2>): Schedule<Out2, In, R | R2>
533
+ } = internal.compose
534
+
535
+ /**
536
+ * Transforms the input type of a schedule.
537
+ *
538
+ * **Details**
539
+ *
540
+ * This function modifies a given schedule by applying a transformation function
541
+ * to its inputs. Instead of directly receiving values of type `In`, the
542
+ * schedule will now accept values of type `In2`, which are converted to `In`
543
+ * using the provided mapping function `f`.
544
+ *
545
+ * This is useful when you have a schedule that expects a specific input type
546
+ * but you need to adapt it to work with a different type.
547
+ *
548
+ * @see {@link mapInputEffect} If you need to use an effectful transformation function.
549
+ *
550
+ * @since 2.0.0
551
+ * @category Mapping
552
+ */
553
+ export const mapInput: {
554
+ <In, In2>(f: (in2: In2) => In): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In2, R>
555
+ <Out, In, R, In2>(self: Schedule<Out, In, R>, f: (in2: In2) => In): Schedule<Out, In2, R>
556
+ } = internal.mapInput
557
+
558
+ /**
559
+ * Transforms the input type of a schedule using an effectful function.
560
+ *
561
+ * **Details**
562
+ *
563
+ * This function modifies a schedule by applying an effectful transformation to
564
+ * its inputs. Instead of directly receiving values of type `In`, the schedule
565
+ * will now accept values of type `In2`, which are converted to `In` via an
566
+ * effectful function `f`.
567
+ *
568
+ * This is useful when the input transformation involves external dependencies,
569
+ * such as API calls, database lookups, or other asynchronous computations.
570
+ *
571
+ * @see {@link mapInput} If you need to use a pure transformation function.
572
+ *
573
+ * @since 2.0.0
574
+ * @category Mapping
575
+ */
576
+ export const mapInputEffect: {
577
+ <In2, In, R2>(
578
+ f: (in2: In2) => Effect.Effect<In, never, R2>
579
+ ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In2, R2 | R>
580
+ <Out, In, R, In2, R2>(
581
+ self: Schedule<Out, In, R>,
582
+ f: (in2: In2) => Effect.Effect<In, never, R2>
583
+ ): Schedule<Out, In2, R | R2>
584
+ } = internal.mapInputEffect
585
+
586
+ /**
587
+ * Transforms the required context of a schedule.
588
+ *
589
+ * **Details**
590
+ *
591
+ * This function modifies a schedule by mapping its required context (`R`) into
592
+ * a new context (`R0`) using the provided function `f`.
593
+ *
594
+ * This is useful when you need to adapt a schedule to work with a different
595
+ * dependency environment without changing its core logic.
596
+ *
597
+ * @since 2.0.0
598
+ * @category Mapping
599
+ */
600
+ export const mapInputContext: {
601
+ <R0, R>(
602
+ f: (env0: Context.Context<R0>) => Context.Context<R>
603
+ ): <Out, In>(self: Schedule<Out, In, R>) => Schedule<Out, In, R0>
604
+ <Out, In, R, R0>(
605
+ self: Schedule<Out, In, R>,
606
+ f: (env0: Context.Context<R0>) => Context.Context<R>
607
+ ): Schedule<Out, In, R0>
608
+ } = internal.mapInputContext
609
+
610
+ /**
611
+ * A schedule that recurs indefinitely, counting the number of recurrences.
612
+ *
613
+ * **Details**
614
+ *
615
+ * This schedule never stops and simply counts how many times it has executed.
616
+ * Each recurrence increases the count, starting from `0`.
617
+ *
618
+ * This is useful when tracking the number of attempts in retry policies,
619
+ * measuring execution loops, or implementing infinite polling scenarios.
620
+ *
621
+ * @since 2.0.0
622
+ * @category Constructors
623
+ */
624
+ export const count: Schedule<number> = internal.count
625
+
626
+ /**
627
+ * Creates a schedule that recurs based on a cron expression.
628
+ *
629
+ * **Details**
630
+ *
631
+ * This schedule automatically executes at intervals defined by a cron
632
+ * expression. It triggers at the beginning of each matched interval and
633
+ * produces timestamps representing the start and end of the cron window.
634
+ *
635
+ * The cron `expression` is validated lazily, meaning errors may only be
636
+ * detected when the schedule is executed.
637
+ *
638
+ * @since 2.0.0
639
+ * @category Cron
640
+ */
641
+ export const cron: {
642
+ (cron: Cron.Cron): Schedule<[number, number]>
643
+ (expression: string, tz?: DateTime.TimeZone | string): Schedule<[number, number]>
644
+ } = internal.cron
645
+
646
+ /**
647
+ * Cron-like schedule that recurs at a specific second of each minute.
648
+ *
649
+ * **Details**
650
+ *
651
+ * This schedule triggers at the specified `second` of each minute,
652
+ * starting at zero nanoseconds. It produces a count of executions
653
+ * (0, 1, 2, ...). The `second` parameter is validated lazily, meaning
654
+ * invalid values will only be caught at runtime.
655
+ *
656
+ * @since 2.0.0
657
+ * @category Cron
658
+ */
659
+ export const secondOfMinute: (second: number) => Schedule<number> = internal.secondOfMinute
660
+
661
+ /**
662
+ * Creates a schedule that recurs every specified minute of each hour.
663
+ *
664
+ * **Details**
665
+ *
666
+ * This schedule triggers once per hour at the specified `minute`, starting
667
+ * exactly at `minute:00` (zero seconds). The schedule produces a count of
668
+ * executions (`0, 1, 2, ...`), representing how many times it has run.
669
+ *
670
+ * The `minute` parameter must be between `0` and `59`. It is validated lazily,
671
+ * meaning an invalid value will cause errors only when the schedule is
672
+ * executed.
673
+ *
674
+ * @since 2.0.0
675
+ * @category Cron
676
+ */
677
+ export const minuteOfHour: (minute: number) => Schedule<number> = internal.minuteOfHour
678
+
679
+ /**
680
+ * Creates a schedule that recurs at a specific hour of each day.
681
+ *
682
+ * **Details**
683
+ *
684
+ * This schedule triggers once per day at the specified `hour`, starting at zero
685
+ * minutes of that hour. The schedule produces a count of executions (`0, 1, 2,
686
+ * ...`), indicating how many times it has been triggered.
687
+ *
688
+ * The `hour` parameter must be between `0` (midnight) and `23` (11 PM). It is
689
+ * validated lazily, meaning an invalid value will cause errors only when the
690
+ * schedule is executed.
691
+ *
692
+ * This is useful for scheduling daily recurring tasks at a fixed time, such as
693
+ * running batch jobs or refreshing data.
694
+ *
695
+ * @since 2.0.0
696
+ * @category Cron
697
+ */
698
+ export const hourOfDay: (hour: number) => Schedule<number> = internal.hourOfDay
699
+
700
+ /**
701
+ * Creates a schedule that recurs on a specific day of the month.
702
+ *
703
+ * **Details**
704
+ *
705
+ * This schedule triggers at midnight on the specified day of each month. It
706
+ * will not execute in months that have fewer days than the given day. For
707
+ * example, if the schedule is set to run on the 31st, it will not execute in
708
+ * months with only 30 days.
709
+ *
710
+ * The schedule produces a count of executions, starting at 0 and incrementing
711
+ * with each recurrence.
712
+ *
713
+ * The `day` parameter is validated lazily, meaning errors may only be detected
714
+ * when the schedule is executed.
715
+ *
716
+ * @since 2.0.0
717
+ * @category Cron
718
+ */
719
+ export const dayOfMonth: (day: number) => Schedule<number> = internal.dayOfMonth
720
+
721
+ /**
722
+ * Creates a schedule that recurs on a specific day of the week.
723
+ *
724
+ * **Details**
725
+ *
726
+ * This schedule triggers at midnight on the specified day of the week. The
727
+ * `day` parameter follows the standard convention where `Monday = 1` and
728
+ * `Sunday = 7`. The schedule produces a count of executions, starting at 0 and
729
+ * incrementing with each recurrence.
730
+ *
731
+ * The `day` parameter is validated lazily, meaning errors may only be detected
732
+ * when the schedule is executed.
733
+ *
734
+ * @since 2.0.0
735
+ * @category Cron
736
+ */
737
+ export const dayOfWeek: (day: number) => Schedule<number> = internal.dayOfWeek
738
+
739
+ /**
740
+ * Modifies a schedule by adding a computed delay before each execution.
741
+ *
742
+ * **Details**
743
+ *
744
+ * This function adjusts an existing schedule by applying a transformation to
745
+ * its delays. Instead of using the default interval, each delay is modified
746
+ * using the provided function `f`, which takes the current delay and returns a
747
+ * new delay.
748
+ *
749
+ * This is useful for dynamically adjusting wait times between executions, such
750
+ * as introducing jitter, exponential backoff, or custom delay logic.
751
+ *
752
+ * @see {@link delayedEffect} If you need to compute the delay using an effectful function.
753
+ *
754
+ * @since 2.0.0
755
+ * @category Timing & Delay
756
+ */
757
+ export const delayed: {
758
+ (
759
+ f: (duration: Duration.Duration) => Duration.DurationInput
760
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
761
+ <Out, In, R>(
762
+ self: Schedule<Out, In, R>,
763
+ f: (duration: Duration.Duration) => Duration.DurationInput
764
+ ): Schedule<Out, In, R>
765
+ } = internal.delayed
766
+
767
+ /**
768
+ * Modifies a schedule by adding an effectfully computed delay before each
769
+ * execution.
770
+ *
771
+ * **Details**
772
+ *
773
+ * This function adjusts an existing schedule by introducing a delay that is
774
+ * computed via an effect. Instead of using a fixed delay, each interval is
775
+ * dynamically adjusted based on an effectful function `f`, which takes the
776
+ * current delay and returns a new delay wrapped in an `Effect`.
777
+ *
778
+ * This is useful for adaptive scheduling where delays depend on external
779
+ * factors, such as API calls, database queries, or dynamic system conditions.
780
+ *
781
+ * @see {@link delayed} If you need to compute the delay using a pure function.
782
+ *
783
+ * @since 2.0.0
784
+ * @category Timing & Delay
785
+ */
786
+ export const delayedEffect: {
787
+ <R2>(
788
+ f: (duration: Duration.Duration) => Effect.Effect<Duration.DurationInput, never, R2>
789
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
790
+ <Out, In, R, R2>(
791
+ self: Schedule<Out, In, R>,
792
+ f: (duration: Duration.Duration) => Effect.Effect<Duration.DurationInput, never, R2>
793
+ ): Schedule<Out, In, R | R2>
794
+ } = internal.delayedEffect
795
+
796
+ /**
797
+ * Uses the delays produced by a schedule to further delay its intervals.
798
+ *
799
+ * **Details**
800
+ *
801
+ * This function modifies a schedule by using its own output delays to control
802
+ * its execution timing. Instead of executing immediately at each interval, the
803
+ * schedule will be delayed by the duration it produces.
804
+ *
805
+ * @since 2.0.0
806
+ * @category Timing & Delay
807
+ */
808
+ export const delayedSchedule: <In, R>(
809
+ schedule: Schedule<Duration.Duration, In, R>
810
+ ) => Schedule<Duration.Duration, In, R> = internal.delayedSchedule
811
+
812
+ /**
813
+ * Transforms a schedule to output the delay between each occurrence.
814
+ *
815
+ * **Details**
816
+ *
817
+ * This function modifies an existing schedule so that instead of producing its
818
+ * original output, it now returns the delay between each scheduled execution.
819
+ *
820
+ * @since 2.0.0
821
+ * @category Monitoring
822
+ */
823
+ export const delays: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Duration.Duration, In, R> = internal.delays
824
+
825
+ /**
826
+ * Transforms both the input and output of a schedule.
827
+ *
828
+ * **Details**
829
+ *
830
+ * This function modifies an existing schedule by applying a transformation to
831
+ * both its input values and its output values. The provided transformation
832
+ * functions `onInput` and `onOutput` allow you to map the schedule to work with
833
+ * a different input type while modifying its outputs as well.
834
+ *
835
+ * @see {@link mapBothEffect} If you need to use effectful transformation functions.
836
+ *
837
+ * @since 2.0.0
838
+ * @category Mapping
839
+ */
840
+ export const mapBoth: {
841
+ <In2, In, Out, Out2>(
842
+ options: { readonly onInput: (in2: In2) => In; readonly onOutput: (out: Out) => Out2 }
843
+ ): <R>(self: Schedule<Out, In, R>) => Schedule<Out2, In2, R>
844
+ <Out, In, R, In2, Out2>(
845
+ self: Schedule<Out, In, R>,
846
+ options: { readonly onInput: (in2: In2) => In; readonly onOutput: (out: Out) => Out2 }
847
+ ): Schedule<Out2, In2, R>
848
+ } = internal.mapBoth
849
+
850
+ /**
851
+ * Transforms both the input and output of a schedule using effectful
852
+ * computations.
853
+ *
854
+ * **Details**
855
+ *
856
+ * This function modifies an existing schedule by applying effectful
857
+ * transformations to both its input values and its output values. The provided
858
+ * effectful functions `onInput` and `onOutput` allow you to transform inputs
859
+ * and outputs using computations that may involve additional logic, resource
860
+ * access, or side effects.
861
+ *
862
+ * @see {@link mapBoth} If you need to use pure transformation functions.
863
+ *
864
+ * @since 2.0.0
865
+ * @category Mapping
866
+ */
867
+ export const mapBothEffect: {
868
+ <In2, In, R2, Out, R3, Out2>(
869
+ options: {
870
+ readonly onInput: (input: In2) => Effect.Effect<In, never, R2>
871
+ readonly onOutput: (out: Out) => Effect.Effect<Out2, never, R3>
872
+ }
873
+ ): <R>(self: Schedule<Out, In, R>) => Schedule<Out2, In2, R2 | R3 | R>
874
+ <Out, In, R, In2, R2, Out2, R3>(
875
+ self: Schedule<Out, In, R>,
876
+ options: {
877
+ readonly onInput: (input: In2) => Effect.Effect<In, never, R2>
878
+ readonly onOutput: (out: Out) => Effect.Effect<Out2, never, R3>
879
+ }
880
+ ): Schedule<Out2, In2, R | R2 | R3>
881
+ } = internal.mapBothEffect
882
+
883
+ /**
884
+ * Creates a driver to manually control the execution of a schedule.
885
+ *
886
+ * **Details**
887
+ *
888
+ * This function returns a `ScheduleDriver`, which allows stepping through a
889
+ * schedule manually while handling delays and sleeping appropriately. A driver
890
+ * is useful when you need fine-grained control over how a schedule progresses,
891
+ * rather than relying on automatic execution.
892
+ *
893
+ * The returned driver exposes methods for retrieving the current state,
894
+ * executing the next step, and resetting the schedule when needed.
895
+ *
896
+ * @since 2.0.0
897
+ * @category getter
898
+ */
899
+ export const driver: <Out, In, R>(
900
+ self: Schedule<Out, In, R>
901
+ ) => Effect.Effect<ScheduleDriver<Out, In, R>> = internal.driver
902
+
903
+ // TODO(4.0): remove?
904
+ /**
905
+ * Alias of {@link fromDelay}.
906
+ *
907
+ * @since 2.0.0
908
+ * @category Constructors
909
+ */
910
+ export const duration: (duration: Duration.DurationInput) => Schedule<Duration.Duration> = internal.duration
911
+
912
+ // TODO(4.0): remove?
913
+ /**
914
+ * Alias of {@link union}.
915
+ *
916
+ * @since 2.0.0
917
+ * @category Alternatives
918
+ */
919
+ export const either: {
920
+ <Out2, In2, R2>(
921
+ that: Schedule<Out2, In2, R2>
922
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
923
+ <Out, In, R, Out2, In2, R2>(
924
+ self: Schedule<Out, In, R>,
925
+ that: Schedule<Out2, In2, R2>
926
+ ): Schedule<[Out, Out2], In & In2, R | R2>
927
+ } = internal.either
928
+
929
+ // TODO(4.0): remove?
930
+ /**
931
+ * Alias of {@link unionWith}.
932
+ *
933
+ * @since 2.0.0
934
+ * @category Alternatives
935
+ */
936
+ export const eitherWith: {
937
+ <Out2, In2, R2>(
938
+ that: Schedule<Out2, In2, R2>,
939
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
940
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
941
+ <Out, In, R, Out2, In2, R2>(
942
+ self: Schedule<Out, In, R>,
943
+ that: Schedule<Out2, In2, R2>,
944
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
945
+ ): Schedule<[Out, Out2], In & In2, R | R2>
946
+ } = internal.eitherWith
947
+
948
+ /**
949
+ * Creates a schedule that tracks the total elapsed duration since it started.
950
+ *
951
+ * **Details**
952
+ *
953
+ * This schedule executes continuously and returns the total time that has
954
+ * passed since the first execution. The duration keeps increasing with each
955
+ * step, providing a way to measure elapsed time.
956
+ *
957
+ * This is useful for tracking execution time, monitoring delays, or
958
+ * implementing logic based on how long a process has been running.
959
+ *
960
+ * @since 2.0.0
961
+ * @category Constructors
962
+ */
963
+ export const elapsed: Schedule<Duration.Duration> = internal.elapsed
964
+
965
+ /**
966
+ * Attaches a finalizer to a schedule that runs when the schedule completes.
967
+ *
968
+ * **Details**
969
+ *
970
+ * This function returns a new schedule that executes a given finalizer when the
971
+ * schedule reaches completion. Unlike `Effect.ensuring`, this method does not
972
+ * guarantee the finalizer will run in all cases. If the schedule never
973
+ * initializes or is not driven to completion, the finalizer may not execute.
974
+ * However, if the schedule decides not to continue, the finalizer will be
975
+ * invoked.
976
+ *
977
+ * This is useful for cleaning up resources, logging, or executing other side
978
+ * effects when a schedule completes.
979
+ *
980
+ * @since 2.0.0
981
+ * @category Finalization
982
+ */
983
+ export const ensuring: {
984
+ <X>(finalizer: Effect.Effect<X, never, never>): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
985
+ <Out, In, R, X>(self: Schedule<Out, In, R>, finalizer: Effect.Effect<X, never, never>): Schedule<Out, In, R>
986
+ } = internal.ensuring
987
+
988
+ /**
989
+ * Creates a schedule that recurs indefinitely with exponentially increasing
990
+ * delays.
991
+ *
992
+ * **Details**
993
+ *
994
+ * This schedule starts with an initial delay of `base` and increases the delay
995
+ * exponentially on each repetition using the formula `base * factor^n`, where
996
+ * `n` is the number of times the schedule has executed so far. If no `factor`
997
+ * is provided, it defaults to `2`, causing the delay to double after each
998
+ * execution.
999
+ *
1000
+ * @since 2.0.0
1001
+ * @category Constructors
1002
+ */
1003
+ export const exponential: (
1004
+ base: Duration.DurationInput,
1005
+ factor?: number
1006
+ ) => Schedule<Duration.Duration> = internal.exponential
1007
+
1008
+ /**
1009
+ * Creates a schedule that recurs indefinitely with Fibonacci-based increasing
1010
+ * delays.
1011
+ *
1012
+ * **Details**
1013
+ *
1014
+ * This schedule starts with an initial delay of `one` and increases subsequent
1015
+ * delays by summing the two previous delays, following the Fibonacci sequence.
1016
+ * The delay pattern follows: `one, one, one + one, (one + one) + one, ...`,
1017
+ * resulting in `1s, 1s, 2s, 3s, 5s, 8s, 13s, ...` if `one = 1s`.
1018
+ *
1019
+ * This is useful for progressive backoff strategies, where delays grow
1020
+ * naturally over time without increasing as aggressively as an exponential
1021
+ * schedule.
1022
+ *
1023
+ * @since 2.0.0
1024
+ * @category Constructors
1025
+ */
1026
+ export const fibonacci: (one: Duration.DurationInput) => Schedule<Duration.Duration> = internal.fibonacci
1027
+
1028
+ /**
1029
+ * Creates a schedule that recurs at a fixed interval.
1030
+ *
1031
+ * **Details**
1032
+ *
1033
+ * This schedule executes at regular, evenly spaced intervals, returning the
1034
+ * number of times it has run so far. If the action being executed takes longer
1035
+ * than the interval, the next execution will happen immediately to prevent
1036
+ * "pile-ups," ensuring that the schedule remains consistent without overlapping
1037
+ * executions.
1038
+ *
1039
+ * ```text
1040
+ * |-----interval-----|-----interval-----|-----interval-----|
1041
+ * |---------action--------||action|-----|action|-----------|
1042
+ * ```
1043
+ *
1044
+ * @see {@link spaced} If you need to run from the end of the last execution.
1045
+ *
1046
+ * @since 2.0.0
1047
+ * @category Constructors
1048
+ */
1049
+ export const fixed: (interval: Duration.DurationInput) => Schedule<number> = internal.fixed
1050
+
1051
+ /**
1052
+ * Creates a schedule that recurs indefinitely, producing a count of
1053
+ * repetitions.
1054
+ *
1055
+ * **Details**
1056
+ *
1057
+ * This schedule runs indefinitely, returning an increasing count of executions
1058
+ * (`0, 1, 2, 3, ...`). Each step increments the count by one, allowing tracking
1059
+ * of how many times it has executed.
1060
+ *
1061
+ * @since 2.0.0
1062
+ * @category Constructors
1063
+ */
1064
+ export const forever: Schedule<number> = internal.forever
1065
+
1066
+ /**
1067
+ * Creates a schedule that recurs once after a specified duration.
1068
+ *
1069
+ * **Details**
1070
+ *
1071
+ * This schedule executes a single time after waiting for the given duration.
1072
+ * Once it has executed, it does not repeat.
1073
+ *
1074
+ * @see {@link fromDelays} If you need to create a schedule with multiple delays.
1075
+ *
1076
+ * @since 2.0.0
1077
+ * @category Constructors
1078
+ */
1079
+ export const fromDelay: (delay: Duration.DurationInput) => Schedule<Duration.Duration> = internal.fromDelay
1080
+
1081
+ /**
1082
+ * Creates a schedule that recurs once for each specified duration, applying the
1083
+ * given delays sequentially.
1084
+ *
1085
+ * **Details**
1086
+ *
1087
+ * This schedule executes multiple times, each time waiting for the
1088
+ * corresponding duration from the provided list of delays. The first execution
1089
+ * waits for `delay`, the next for the second value in `delays`, and so on. Once
1090
+ * all delays have been used, the schedule stops executing.
1091
+ *
1092
+ * This is useful for defining a custom delay sequence that does not follow a
1093
+ * fixed pattern like exponential or Fibonacci backoff.
1094
+ *
1095
+ * @since 2.0.0
1096
+ * @category Constructors
1097
+ */
1098
+ export const fromDelays: (
1099
+ delay: Duration.DurationInput,
1100
+ ...delays: Array<Duration.DurationInput>
1101
+ ) => Schedule<Duration.Duration> = internal.fromDelays
1102
+
1103
+ /**
1104
+ * Creates a schedule that always recurs, transforming input values using the
1105
+ * specified function.
1106
+ *
1107
+ * **Details**
1108
+ *
1109
+ * This schedule continuously executes and applies the given function `f` to
1110
+ * each input value, producing a transformed output. The schedule itself does
1111
+ * not control delays or stopping conditions; it simply transforms the input
1112
+ * values as they are processed.
1113
+ *
1114
+ * This is useful when defining schedules that map inputs to outputs, allowing
1115
+ * dynamic transformations of incoming data.
1116
+ *
1117
+ * @since 2.0.0
1118
+ * @category Constructors
1119
+ */
1120
+ export const fromFunction: <A, B>(f: (a: A) => B) => Schedule<B, A> = internal.fromFunction
1121
+
1122
+ /**
1123
+ * Creates a schedule that always recurs, passing inputs directly as outputs.
1124
+ *
1125
+ * **Details**
1126
+ *
1127
+ * This schedule runs indefinitely, returning each input value as its output
1128
+ * without modification. It effectively acts as a pass-through that simply
1129
+ * echoes its input values at each step.
1130
+ *
1131
+ * @since 2.0.0
1132
+ * @category Constructors
1133
+ */
1134
+ export const identity: <A>() => Schedule<A, A> = internal.identity
1135
+
1136
+ /**
1137
+ * Transforms a schedule to pass through its inputs as outputs.
1138
+ *
1139
+ * **Details**
1140
+ *
1141
+ * This function modifies an existing schedule so that it returns its input
1142
+ * values instead of its original output values. The schedule's timing remains
1143
+ * unchanged, but its outputs are replaced with whatever inputs it receives.
1144
+ *
1145
+ * @since 2.0.0
1146
+ */
1147
+ export const passthrough: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<In, In, R> = internal.passthrough
1148
+
1149
+ /**
1150
+ * Combines two schedules, continuing only if both schedules want to continue,
1151
+ * using the longer delay.
1152
+ *
1153
+ * **Details**
1154
+ *
1155
+ * This function takes two schedules and creates a new schedule that only
1156
+ * continues execution if both schedules allow it. The interval between
1157
+ * recurrences is determined by the longer delay between the two schedules.
1158
+ *
1159
+ * The output of the resulting schedule is a tuple containing the outputs of
1160
+ * both schedules. The input type is the intersection of both schedules' input
1161
+ * types.
1162
+ *
1163
+ * This is useful when coordinating multiple scheduling conditions where
1164
+ * execution should proceed only when both schedules permit it.
1165
+ *
1166
+ * @see {@link intersectWith} If you need to use a custom merge function.
1167
+ *
1168
+ * @since 2.0.0
1169
+ * @category Composition
1170
+ */
1171
+ export const intersect: {
1172
+ <Out2, In2, R2>(
1173
+ that: Schedule<Out2, In2, R2>
1174
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
1175
+ <Out, In, R, Out2, In2, R2>(
1176
+ self: Schedule<Out, In, R>,
1177
+ that: Schedule<Out2, In2, R2>
1178
+ ): Schedule<[Out, Out2], In & In2, R | R2>
1179
+ } = internal.intersect
1180
+
1181
+ /**
1182
+ * Combines two schedules, continuing only if both want to continue, merging
1183
+ * intervals using a custom function.
1184
+ *
1185
+ * **Details**
1186
+ *
1187
+ * This function takes two schedules and creates a new schedule that only
1188
+ * continues execution if both schedules allow it. Instead of automatically
1189
+ * using the longer delay (like {@link intersect}), this function applies a
1190
+ * user-provided merge function `f` to determine the next interval between
1191
+ * executions.
1192
+ *
1193
+ * The output of the resulting schedule is a tuple containing the outputs of
1194
+ * both schedules, and the input type is the intersection of both schedules'
1195
+ * input types.
1196
+ *
1197
+ * @since 2.0.0
1198
+ * @category Composition
1199
+ */
1200
+ export const intersectWith: {
1201
+ <Out2, In2, R2>(
1202
+ that: Schedule<Out2, In2, R2>,
1203
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
1204
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
1205
+ <Out, In, R, Out2, In2, R2>(
1206
+ self: Schedule<Out, In, R>,
1207
+ that: Schedule<Out2, In2, R2>,
1208
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
1209
+ ): Schedule<[Out, Out2], In & In2, R | R2>
1210
+ } = internal.intersectWith
1211
+
1212
+ /**
1213
+ * Returns a new schedule that randomly adjusts the interval size within a
1214
+ * range.
1215
+ *
1216
+ * **Details**
1217
+ *
1218
+ * This function modifies a schedule so that its delay between executions is
1219
+ * randomly varied within a range. By default, the delay is adjusted between
1220
+ * `80%` (`0.8 * interval`) and `120%` (`1.2 * interval`) of the original
1221
+ * interval size.
1222
+ *
1223
+ * This is useful for adding randomness to repeated executions, reducing
1224
+ * contention in distributed systems, and avoiding synchronized execution
1225
+ * patterns that can cause bottlenecks.
1226
+ *
1227
+ * @see {@link jitteredWith} If you need to specify custom min/max values.
1228
+ *
1229
+ * @since 2.0.0
1230
+ * @category Timing & Delay
1231
+ */
1232
+ export const jittered: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R> = internal.jittered
1233
+
1234
+ /**
1235
+ * Returns a new schedule that randomly adjusts the interval size within a
1236
+ * user-defined range.
1237
+ *
1238
+ * **Details**
1239
+ *
1240
+ * This function modifies a schedule so that its delay between executions is
1241
+ * randomly varied within a specified range. Instead of using the default `0.8 -
1242
+ * 1.2` range like {@link jittered}, this function allows customizing the `min`
1243
+ * and `max` multipliers.
1244
+ *
1245
+ * The delay for each step will be adjusted within `min * original_interval` and
1246
+ * `max * original_interval`. If `min` and `max` are not provided, the defaults
1247
+ * are `0.8` and `1.2`, respectively.
1248
+ *
1249
+ * This is useful for introducing randomness into scheduling behavior while
1250
+ * having precise control over the jitter range.
1251
+ *
1252
+ * @since 2.0.0
1253
+ * @category Timing & Delay
1254
+ */
1255
+ export const jitteredWith: {
1256
+ (
1257
+ options: { min?: number | undefined; max?: number | undefined }
1258
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1259
+ <Out, In, R>(
1260
+ self: Schedule<Out, In, R>,
1261
+ options: { min?: number | undefined; max?: number | undefined }
1262
+ ): Schedule<Out, In, R>
1263
+ } = internal.jitteredWith
1264
+
1265
+ /**
1266
+ * Creates a schedule that recurs indefinitely, increasing the delay linearly.
1267
+ *
1268
+ * **Details**
1269
+ *
1270
+ * This schedule starts with an initial delay of `base` and increases the delay
1271
+ * on each recurrence in a linear fashion, following the formula:
1272
+ *
1273
+ * `delay = base * n`
1274
+ *
1275
+ * where `n` is the number of times the schedule has executed so far. This
1276
+ * results in increasing intervals between executions.
1277
+ *
1278
+ * This is useful for implementing linear backoff strategies where the wait time
1279
+ * between retries increases at a steady rate.
1280
+ *
1281
+ * @since 2.0.0
1282
+ * @category Constructors
1283
+ */
1284
+ export const linear: (base: Duration.DurationInput) => Schedule<Duration.Duration> = internal.linear
1285
+
1286
+ /**
1287
+ * Returns a new schedule that transforms its output using the specified
1288
+ * function.
1289
+ *
1290
+ * **Details**
1291
+ *
1292
+ * This function modifies an existing schedule so that its outputs are
1293
+ * transformed by the provided function `f`. The timing and recurrence behavior
1294
+ * of the schedule remain unchanged, but the values it produces are mapped to
1295
+ * new values.
1296
+ *
1297
+ * This is useful when composing schedules where you need to adjust the output
1298
+ * format or apply additional processing.
1299
+ *
1300
+ * @see {@link mapEffect} If you need to use an effectful transformation
1301
+ * function.
1302
+ *
1303
+ * @since 2.0.0
1304
+ * @category Mapping
1305
+ */
1306
+ export const map: {
1307
+ <Out, Out2>(f: (out: Out) => Out2): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R>
1308
+ <Out, In, R, Out2>(self: Schedule<Out, In, R>, f: (out: Out) => Out2): Schedule<Out2, In, R>
1309
+ } = internal.map
1310
+
1311
+ /**
1312
+ * Returns a new schedule that applies an effectful transformation to its
1313
+ * output.
1314
+ *
1315
+ * **Details**
1316
+ *
1317
+ * This function modifies an existing schedule by applying an effectful function
1318
+ * `f` to its output values. The timing and recurrence behavior of the schedule
1319
+ * remain unchanged, but each output is mapped to a new value within an
1320
+ * `Effect`.
1321
+ *
1322
+ * This is useful when you need to perform side effects or asynchronous
1323
+ * transformations before passing the output forward.
1324
+ *
1325
+ * @see {@link map} If you need to use a pure transformation function.
1326
+ *
1327
+ * @since 2.0.0
1328
+ * @category Mapping
1329
+ */
1330
+ export const mapEffect: {
1331
+ <Out, Out2, R2>(
1332
+ f: (out: Out) => Effect.Effect<Out2, never, R2>
1333
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In, R2 | R>
1334
+ <Out, In, R, Out2, R2>(
1335
+ self: Schedule<Out, In, R>,
1336
+ f: (out: Out) => Effect.Effect<Out2, never, R2>
1337
+ ): Schedule<Out2, In, R | R2>
1338
+ } = internal.mapEffect
1339
+
1340
+ /**
1341
+ * Returns a new schedule that modifies the delay between executions using a
1342
+ * custom function.
1343
+ *
1344
+ * **Details**
1345
+ *
1346
+ * This function transforms an existing schedule by applying `f` to modify the
1347
+ * delay before each execution. The function receives both the schedule's output
1348
+ * (`out`) and the originally computed delay (`duration`), and returns a new
1349
+ * adjusted delay.
1350
+ *
1351
+ * @see {@link modifyDelayEffect} If you need to use an effectful function.
1352
+ *
1353
+ * @since 2.0.0
1354
+ * @category Timing & Delay
1355
+ */
1356
+ export const modifyDelay: {
1357
+ <Out>(
1358
+ f: (out: Out, duration: Duration.Duration) => Duration.DurationInput
1359
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1360
+ <Out, In, R>(
1361
+ self: Schedule<Out, In, R>,
1362
+ f: (out: Out, duration: Duration.Duration) => Duration.DurationInput
1363
+ ): Schedule<Out, In, R>
1364
+ } = internal.modifyDelay
1365
+
1366
+ /**
1367
+ * Returns a new schedule that modifies the delay before execution using an
1368
+ * effectful function.
1369
+ *
1370
+ * **Details**
1371
+ *
1372
+ * This function takes an existing schedule and applies an effectful function
1373
+ * `f` to dynamically adjust the delay before each execution. The function
1374
+ * receives both the schedule's output (`out`) and the originally computed delay
1375
+ * (`duration`), returning a new adjusted delay wrapped in an `Effect`.
1376
+ *
1377
+ * @see {@link modifyDelay} If you need to use a pure function.
1378
+ *
1379
+ * @since 2.0.0
1380
+ * @category Timing & Delay
1381
+ */
1382
+ export const modifyDelayEffect: {
1383
+ <Out, R2>(
1384
+ f: (out: Out, duration: Duration.Duration) => Effect.Effect<Duration.DurationInput, never, R2>
1385
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
1386
+ <Out, In, R, R2>(
1387
+ self: Schedule<Out, In, R>,
1388
+ f: (out: Out, duration: Duration.Duration) => Effect.Effect<Duration.DurationInput, never, R2>
1389
+ ): Schedule<Out, In, R | R2>
1390
+ } = internal.modifyDelayEffect
1391
+
1392
+ /**
1393
+ * Returns a new schedule that executes an effect every time the schedule makes
1394
+ * a decision.
1395
+ *
1396
+ * **Details**
1397
+ *
1398
+ * This function enhances an existing schedule by running an effectful function
1399
+ * `f` whenever a scheduling decision is made. The function receives the current
1400
+ * schedule output (`out`) and the decision (`ScheduleDecision`), allowing
1401
+ * additional logic to be executed, such as logging, monitoring, or side
1402
+ * effects.
1403
+ *
1404
+ * @since 2.0.0
1405
+ */
1406
+ export const onDecision: {
1407
+ <Out, X, R2>(
1408
+ f: (out: Out, decision: ScheduleDecision.ScheduleDecision) => Effect.Effect<X, never, R2>
1409
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
1410
+ <Out, In, R, X, R2>(
1411
+ self: Schedule<Out, In, R>,
1412
+ f: (out: Out, decision: ScheduleDecision.ScheduleDecision) => Effect.Effect<X, never, R2>
1413
+ ): Schedule<Out, In, R | R2>
1414
+ } = internal.onDecision
1415
+
1416
+ /**
1417
+ * A schedule that executes only once and then stops.
1418
+ *
1419
+ * **Details**
1420
+ *
1421
+ * This schedule triggers a single execution and then terminates. It does not
1422
+ * repeat or apply any additional logic.
1423
+ *
1424
+ * @since 2.0.0
1425
+ * @category Constructors
1426
+ */
1427
+ export const once: Schedule<void> = internal.once
1428
+
1429
+ /**
1430
+ * Returns a new schedule with a provided context, eliminating the need for
1431
+ * external dependencies.
1432
+ *
1433
+ * **Details**
1434
+ *
1435
+ * This function supplies a required `context` to a schedule, allowing it to run
1436
+ * without requiring external dependencies. After calling this function, the
1437
+ * schedule can be used freely without needing to pass a context at execution
1438
+ * time.
1439
+ *
1440
+ * This is useful when working with schedules that rely on contextual
1441
+ * information, such as logging services, database connections, or configuration
1442
+ * settings.
1443
+ *
1444
+ * @since 2.0.0
1445
+ * @category Context
1446
+ */
1447
+ export const provideContext: {
1448
+ <R>(context: Context.Context<R>): <Out, In>(self: Schedule<Out, In, R>) => Schedule<Out, In, never>
1449
+ <Out, In, R>(self: Schedule<Out, In, R>, context: Context.Context<R>): Schedule<Out, In, never>
1450
+ } = internal.provideContext
1451
+
1452
+ /**
1453
+ * Returns a new schedule with a single required service provided, eliminating
1454
+ * the need for external dependencies.
1455
+ *
1456
+ * **Details**
1457
+ *
1458
+ * This function supplies a single service dependency to a schedule, allowing it
1459
+ * to run without requiring that service externally. If a schedule depends on
1460
+ * multiple services, consider using `provideContext` instead.
1461
+ *
1462
+ * This is useful when working with schedules that require a specific service,
1463
+ * such as logging, metrics, or configuration retrieval.
1464
+ *
1465
+ * @since 2.0.0
1466
+ * @category Context
1467
+ */
1468
+ export const provideService: {
1469
+ <I, S>(
1470
+ tag: Context.Tag<I, S>,
1471
+ service: Types.NoInfer<S>
1472
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, Exclude<R, I>>
1473
+ <Out, In, R, I, S>(
1474
+ self: Schedule<Out, In, R>,
1475
+ tag: Context.Tag<I, S>,
1476
+ service: Types.NoInfer<S>
1477
+ ): Schedule<Out, In, Exclude<R, I>>
1478
+ } = internal.provideService
1479
+
1480
+ /**
1481
+ * A schedule that recurs until the given predicate evaluates to true.
1482
+ *
1483
+ * **Details**
1484
+ *
1485
+ * This schedule will continue executing as long as the provided predicate `f`
1486
+ * returns `false` for the input value. Once `f` evaluates to `true`, the
1487
+ * schedule stops recurring.
1488
+ *
1489
+ * This is useful for defining schedules that should stop when a certain
1490
+ * condition is met, such as detecting a success state, reaching a threshold, or
1491
+ * avoiding unnecessary retries.
1492
+ *
1493
+ * @see {@link recurUntilEffect} If you need to use an effectful predicate.
1494
+ *
1495
+ * @since 2.0.0
1496
+ * @category Recurrence Conditions
1497
+ */
1498
+ export const recurUntil: <A>(f: Predicate<A>) => Schedule<A, A> = internal.recurUntil
1499
+
1500
+ /**
1501
+ * A schedule that recurs until the given effectful predicate evaluates to true.
1502
+ *
1503
+ * **Details**
1504
+ *
1505
+ * This schedule continues executing as long as the provided effectful predicate
1506
+ * `f` returns `false`. Once `f` evaluates to `true`, the schedule stops
1507
+ * recurring. Unlike {@link recurUntil}, this function allows the stopping
1508
+ * condition to be computed asynchronously or based on external dependencies.
1509
+ *
1510
+ * This is useful when the stopping condition depends on an effectful
1511
+ * computation, such as checking a database, making an API call, or retrieving
1512
+ * system state dynamically.
1513
+ *
1514
+ * @see {@link recurUntil} If you need to use a pure predicate.
1515
+ *
1516
+ * @since 2.0.0
1517
+ * @category Recurrence Conditions
1518
+ */
1519
+ export const recurUntilEffect: <A, R>(f: (a: A) => Effect.Effect<boolean, never, R>) => Schedule<A, A, R> =
1520
+ internal.recurUntilEffect
1521
+
1522
+ /**
1523
+ * A schedule that recurs until the input value matches a partial function, then
1524
+ * maps the value.
1525
+ *
1526
+ * **Details**
1527
+ *
1528
+ * This schedule continues executing until the provided partial function `pf`
1529
+ * returns `Some(value)`. At that point, it stops and maps the resulting value
1530
+ * to an `Option<B>`. If `pf` returns `None`, the schedule continues.
1531
+ *
1532
+ * This is useful when defining schedules that should stop once a certain
1533
+ * condition is met and transform the final value before completion.
1534
+ *
1535
+ * @since 2.0.0
1536
+ * @category Recurrence Conditions
1537
+ */
1538
+ export const recurUntilOption: <A, B>(pf: (a: A) => Option.Option<B>) => Schedule<Option.Option<B>, A> =
1539
+ internal.recurUntilOption
1540
+
1541
+ /**
1542
+ * A schedule that recurs until the specified duration has elapsed.
1543
+ *
1544
+ * **Details**
1545
+ *
1546
+ * This schedule continues executing for the given `duration`, after which it
1547
+ * stops. The schedule outputs the elapsed time on each recurrence.
1548
+ *
1549
+ * This is useful for limiting the duration of retries, enforcing time-based
1550
+ * constraints, or ensuring that an operation does not run indefinitely.
1551
+ *
1552
+ * @since 2.0.0
1553
+ * @category Recurrence Conditions
1554
+ */
1555
+ export const recurUpTo: (duration: Duration.DurationInput) => Schedule<Duration.Duration> = internal.recurUpTo
1556
+
1557
+ /**
1558
+ * A schedule that recurs as long as the given predicate evaluates to true.
1559
+ *
1560
+ * **Details*
1561
+ *
1562
+ * This schedule continues executing as long as the provided predicate `f`
1563
+ * returns `true` for the input value. Once `f` evaluates to `false`, the
1564
+ * schedule stops recurring.
1565
+ *
1566
+ * @see {@link recurWhileEffect} If you need to use an effectful predicate.
1567
+ *
1568
+ * @since 2.0.0
1569
+ * @category Recurrence Conditions
1570
+ */
1571
+ export const recurWhile: <A>(f: Predicate<A>) => Schedule<A, A> = internal.recurWhile
1572
+
1573
+ /**
1574
+ * A schedule that recurs as long as the given effectful predicate evaluates to
1575
+ * true.
1576
+ *
1577
+ * **Details**
1578
+ *
1579
+ * This schedule continues executing as long as the provided effectful predicate
1580
+ * `f` returns `true`. Once `f` evaluates to `false`, the schedule stops
1581
+ * recurring. Unlike {@link recurWhile}, this function allows the condition to
1582
+ * be computed dynamically using an effectful computation.
1583
+ *
1584
+ * @see {@link recurWhile} If you need to use a pure predicate.
1585
+ *
1586
+ * @since 2.0.0
1587
+ * @category Recurrence Conditions
1588
+ */
1589
+ export const recurWhileEffect: <A, R>(f: (a: A) => Effect.Effect<boolean, never, R>) => Schedule<A, A, R> =
1590
+ internal.recurWhileEffect
1591
+
1592
+ /**
1593
+ * A schedule that recurs a fixed number of times before terminating.
1594
+ *
1595
+ * **Details**
1596
+ *
1597
+ * This schedule will continue executing until it has been stepped `n` times,
1598
+ * after which it will stop. The output of the schedule is the current count of
1599
+ * recurrences.
1600
+ *
1601
+ * @category Constructors
1602
+ * @since 2.0.0
1603
+ */
1604
+ export const recurs: (n: number) => Schedule<number> = internal.recurs
1605
+
1606
+ /**
1607
+ * Returns a new schedule that folds over the outputs of this one.
1608
+ *
1609
+ * **Details**
1610
+ *
1611
+ * This schedule transforms the output by accumulating values over time using a
1612
+ * reducer function `f`. It starts with an initial value `zero` and updates it
1613
+ * each time the schedule produces an output.
1614
+ *
1615
+ * This is useful for tracking statistics, aggregating results, or summarizing
1616
+ * data across multiple executions.
1617
+ *
1618
+ * @see {@link reduceEffect} If you need to use an effectful reducer function.
1619
+ *
1620
+ * @since 2.0.0
1621
+ * @category Reducing
1622
+ */
1623
+ export const reduce: {
1624
+ <Out, Z>(zero: Z, f: (z: Z, out: Out) => Z): <In, R>(self: Schedule<Out, In, R>) => Schedule<Z, In, R>
1625
+ <Out, In, R, Z>(self: Schedule<Out, In, R>, zero: Z, f: (z: Z, out: Out) => Z): Schedule<Z, In, R>
1626
+ } = internal.reduce
1627
+
1628
+ /**
1629
+ * Returns a new schedule that effectfully folds over the outputs of this one.
1630
+ *
1631
+ * **Details**
1632
+ *
1633
+ * This schedule accumulates outputs over time using an effectful reducer
1634
+ * function `f`. It starts with an initial value `zero` and updates it
1635
+ * asynchronously or based on external dependencies.
1636
+ *
1637
+ * This is useful for asynchronous state tracking, logging, external metrics
1638
+ * aggregation, or any scenario where accumulation needs to involve an effectful
1639
+ * computation.
1640
+ *
1641
+ * @see {@link reduce} If you need to use a pure reducer function.
1642
+ *
1643
+ * @since 2.0.0
1644
+ * @category Reducing
1645
+ */
1646
+ export const reduceEffect: {
1647
+ <Z, Out, R2>(
1648
+ zero: Z,
1649
+ f: (z: Z, out: Out) => Effect.Effect<Z, never, R2>
1650
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Z, In, R2 | R>
1651
+ <Out, In, R, Z, R2>(
1652
+ self: Schedule<Out, In, R>,
1653
+ zero: Z,
1654
+ f: (z: Z, out: Out) => Effect.Effect<Z, never, R2>
1655
+ ): Schedule<Z, In, R | R2>
1656
+ } = internal.reduceEffect
1657
+
1658
+ // TODO(4.0): remove?
1659
+ /**
1660
+ * Alias of {@link forever}.
1661
+ *
1662
+ * @since 2.0.0
1663
+ * @category Constructors
1664
+ */
1665
+ export const repeatForever: Schedule<number> = internal.forever
1666
+
1667
+ /**
1668
+ * Returns a new schedule that outputs the number of repetitions of this one.
1669
+ *
1670
+ * **Details**
1671
+ *
1672
+ * This schedule tracks how many times the given schedule has executed and
1673
+ * outputs the count instead of the original values. The first execution starts
1674
+ * at `0`, and the count increases with each recurrence.
1675
+ *
1676
+ * @since 2.0.0
1677
+ * @category Monitoring
1678
+ */
1679
+ export const repetitions: <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<number, In, R> = internal.repetitions
1680
+
1681
+ /**
1682
+ * Returns a new schedule that automatically resets to its initial state after a
1683
+ * period of inactivity defined by `duration`.
1684
+ *
1685
+ * **Details**
1686
+ *
1687
+ * This function modifies a schedule so that if no inputs are received for the
1688
+ * specified `duration`, the schedule resets as if it were new.
1689
+ *
1690
+ * @see {@link resetWhen} If you need to reset based on output values.
1691
+ *
1692
+ * @since 2.0.0
1693
+ * @category State Management
1694
+ */
1695
+ export const resetAfter: {
1696
+ (duration: Duration.DurationInput): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1697
+ <Out, In, R>(self: Schedule<Out, In, R>, duration: Duration.DurationInput): Schedule<Out, In, R>
1698
+ } = internal.resetAfter
1699
+
1700
+ /**
1701
+ * Resets the schedule when the specified predicate on the schedule output
1702
+ * evaluates to `true`.
1703
+ *
1704
+ * **Details**
1705
+ *
1706
+ * This function modifies a schedule so that it resets to its initial state
1707
+ * whenever the provided predicate `f` returns `true` for an output value.
1708
+ *
1709
+ * @see {@link resetAfter} If you need to reset based on inactivity.
1710
+ *
1711
+ * @since 2.0.0
1712
+ * @category State Management
1713
+ */
1714
+ export const resetWhen: {
1715
+ <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1716
+ <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>
1717
+ } = internal.resetWhen
1718
+
1719
+ /**
1720
+ * Runs a schedule using the provided inputs and collects all outputs.
1721
+ *
1722
+ * **Details**
1723
+ *
1724
+ * This function executes a given schedule with a sequence of input values and
1725
+ * accumulates all outputs into a `Chunk`. The schedule starts execution at the
1726
+ * specified `now` timestamp and proceeds according to its defined behavior.
1727
+ *
1728
+ * This is useful for batch processing, simulating execution, or testing
1729
+ * schedules with predefined input sequences.
1730
+ *
1731
+ * @since 2.0.0
1732
+ * @category Execution
1733
+ */
1734
+ export const run: {
1735
+ <In>(
1736
+ now: number,
1737
+ input: Iterable<In>
1738
+ ): <Out, R>(self: Schedule<Out, In, R>) => Effect.Effect<Chunk.Chunk<Out>, never, R>
1739
+ <Out, In, R>(self: Schedule<Out, In, R>, now: number, input: Iterable<In>): Effect.Effect<Chunk.Chunk<Out>, never, R>
1740
+ } = internal.run
1741
+
1742
+ /**
1743
+ * Returns a schedule that recurs continuously, with each repetition
1744
+ * spaced by the specified `duration` from the last run.
1745
+ *
1746
+ * **Details**
1747
+ *
1748
+ * This schedule ensures that executions occur at a fixed interval,
1749
+ * maintaining a consistent delay between repetitions. The delay starts
1750
+ * from the end of the last execution, not from the schedule start time.
1751
+ *
1752
+ * @see {@link fixed} If you need to run at a fixed interval from the start.
1753
+ *
1754
+ * @since 2.0.0
1755
+ * @category Constructors
1756
+ */
1757
+ export const spaced: (duration: Duration.DurationInput) => Schedule<number> = internal.spaced
1758
+
1759
+ /**
1760
+ * A schedule that does not recur and stops immediately.
1761
+ *
1762
+ * @since 2.0.0
1763
+ * @category Constructors
1764
+ */
1765
+ export const stop: Schedule<void> = internal.stop
1766
+
1767
+ /**
1768
+ * Returns a schedule that recurs indefinitely, always producing the specified
1769
+ * constant value.
1770
+ *
1771
+ * @since 2.0.0
1772
+ * @category Constructors
1773
+ */
1774
+ export const succeed: <A>(value: A) => Schedule<A> = internal.succeed
1775
+
1776
+ /**
1777
+ * Returns a schedule that recurs indefinitely, evaluating the given function to
1778
+ * produce a constant value.
1779
+ *
1780
+ * @category Constructors
1781
+ * @since 2.0.0
1782
+ */
1783
+ export const sync: <A>(evaluate: LazyArg<A>) => Schedule<A> = internal.sync
1784
+
1785
+ /**
1786
+ * Returns a new schedule that runs the given effectful function for each input
1787
+ * before continuing execution.
1788
+ *
1789
+ * **Details**
1790
+ *
1791
+ * This function allows side effects to be performed on each input processed by
1792
+ * the schedule. It does not modify the schedule’s behavior but ensures that the
1793
+ * provided function `f` runs before each step.
1794
+ *
1795
+ * @since 2.0.0
1796
+ * @category Tapping
1797
+ */
1798
+ export const tapInput: {
1799
+ <In2, X, R2>(
1800
+ f: (input: In2) => Effect.Effect<X, never, R2>
1801
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In & In2, R2 | R>
1802
+ <Out, In, R, In2, X, R2>(
1803
+ self: Schedule<Out, In, R>,
1804
+ f: (input: In2) => Effect.Effect<X, never, R2>
1805
+ ): Schedule<Out, In & In2, R | R2>
1806
+ } = internal.tapInput
1807
+
1808
+ /**
1809
+ * Returns a new schedule that runs the given effectful function for each output
1810
+ * before continuing execution.
1811
+ *
1812
+ * **Details**
1813
+ *
1814
+ * This function allows side effects to be performed on each output produced by
1815
+ * the schedule. It does not modify the schedule’s behavior but ensures that the
1816
+ * provided function `f` runs after each step.
1817
+ *
1818
+ * @since 2.0.0
1819
+ * @category Tapping
1820
+ */
1821
+ export const tapOutput: {
1822
+ <X, R2, Out>(
1823
+ f: (out: Types.NoInfer<Out>) => Effect.Effect<X, never, R2>
1824
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
1825
+ <Out, In, R, X, R2>(
1826
+ self: Schedule<Out, In, R>,
1827
+ f: (out: Out) => Effect.Effect<X, never, R2>
1828
+ ): Schedule<Out, In, R | R2>
1829
+ } = internal.tapOutput
1830
+
1831
+ /**
1832
+ * Creates a schedule that repeatedly applies a function to transform a state
1833
+ * value, producing a sequence of values.
1834
+ *
1835
+ * **Details**
1836
+ *
1837
+ * This function starts with an `initial` value and applies `f` recursively to
1838
+ * generate the next state at each step. The schedule continues indefinitely,
1839
+ * producing a stream of values by unfolding the state over time.
1840
+ *
1841
+ * @since 2.0.0
1842
+ * @category Constructors
1843
+ */
1844
+ export const unfold: <A>(initial: A, f: (a: A) => A) => Schedule<A> = internal.unfold
1845
+
1846
+ /**
1847
+ * Combines two schedules, continuing execution as long as at least one of them
1848
+ * allows it, using the shorter delay.
1849
+ *
1850
+ * **Details**
1851
+ *
1852
+ * This function combines two schedules into a single schedule that executes in
1853
+ * parallel. If either schedule allows continuation, the merged schedule
1854
+ * continues. When both schedules produce delays, the schedule selects the
1855
+ * shorter delay to determine the next step.
1856
+ *
1857
+ * The output of the new schedule is a tuple containing the outputs of both
1858
+ * schedules. The input type is the intersection of both schedules' input types.
1859
+ *
1860
+ * This is useful for scenarios where multiple scheduling conditions should be
1861
+ * considered, ensuring execution proceeds if at least one schedule permits it.
1862
+ *
1863
+ * @see {@link unionWith} If you need to use a custom merge function.
1864
+ *
1865
+ * @since 2.0.0
1866
+ * @category Composition
1867
+ */
1868
+ export const union: {
1869
+ <Out2, In2, R2>(
1870
+ that: Schedule<Out2, In2, R2>
1871
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
1872
+ <Out, In, R, Out2, In2, R2>(
1873
+ self: Schedule<Out, In, R>,
1874
+ that: Schedule<Out2, In2, R2>
1875
+ ): Schedule<[Out, Out2], In & In2, R | R2>
1876
+ } = internal.union
1877
+
1878
+ /**
1879
+ * Combines two schedules, continuing execution as long as at least one of them
1880
+ * wants to continue, merging their intervals using a custom merge function.
1881
+ *
1882
+ * **Details**
1883
+ *
1884
+ * This function allows you to combine two schedules while defining how their
1885
+ * intervals should be merged. Unlike {@link union}, which simply selects the
1886
+ * shorter delay, this function lets you specify a custom merging strategy for
1887
+ * the schedules’ intervals.
1888
+ *
1889
+ * The merged schedule continues execution as long as at least one of the input
1890
+ * schedules allows it. The next interval is determined by applying the provided
1891
+ * merge function to the intervals of both schedules.
1892
+ *
1893
+ * The output of the resulting schedule is a tuple containing the outputs of
1894
+ * both schedules. The input type is the intersection of both schedules' input
1895
+ * types.
1896
+ *
1897
+ * @see {@link union} If you need to use the shorter delay.
1898
+ *
1899
+ * @since 2.0.0
1900
+ * @category Composition
1901
+ */
1902
+ export const unionWith: {
1903
+ <Out2, In2, R2>(
1904
+ that: Schedule<Out2, In2, R2>,
1905
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
1906
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<[Out, Out2], In & In2, R2 | R>
1907
+ <Out, In, R, Out2, In2, R2>(
1908
+ self: Schedule<Out, In, R>,
1909
+ that: Schedule<Out2, In2, R2>,
1910
+ f: (x: Intervals.Intervals, y: Intervals.Intervals) => Intervals.Intervals
1911
+ ): Schedule<[Out, Out2], In & In2, R | R2>
1912
+ } = internal.unionWith
1913
+
1914
+ /**
1915
+ * Returns a new schedule that stops execution when the given predicate on the
1916
+ * input evaluates to `true`.
1917
+ *
1918
+ * **Details**
1919
+ *
1920
+ * This function modifies an existing schedule so that it continues executing
1921
+ * only while the provided predicate returns `false` for incoming inputs. Once
1922
+ * an input satisfies the condition, the schedule terminates immediately.
1923
+ *
1924
+ * @see {@link untilInputEffect} If you need to use an effectful predicate.
1925
+ *
1926
+ * @since 2.0.0
1927
+ * @category Recurrence Conditions
1928
+ */
1929
+ export const untilInput: {
1930
+ <In>(f: Predicate<In>): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1931
+ <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<In>): Schedule<Out, In, R>
1932
+ } = internal.untilInput
1933
+
1934
+ /**
1935
+ * Returns a new schedule that stops execution when the given effectful
1936
+ * predicate on the input evaluates to `true`.
1937
+ *
1938
+ * **Details**
1939
+ *
1940
+ * This function modifies an existing schedule so that it continues executing
1941
+ * only while the provided effectful predicate returns `false` for incoming
1942
+ * inputs. The predicate is an `Effect`, meaning it can involve asynchronous
1943
+ * computations or dependency-based logic.
1944
+ *
1945
+ * @see {@link untilInput} If you need to use a pure predicate.
1946
+ *
1947
+ * @since 2.0.0
1948
+ * @category Recurrence Conditions
1949
+ */
1950
+ export const untilInputEffect: {
1951
+ <In, R2>(
1952
+ f: (input: In) => Effect.Effect<boolean, never, R2>
1953
+ ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
1954
+ <Out, In, R, R2>(
1955
+ self: Schedule<Out, In, R>,
1956
+ f: (input: In) => Effect.Effect<boolean, never, R2>
1957
+ ): Schedule<Out, In, R | R2>
1958
+ } = internal.untilInputEffect
1959
+
1960
+ /**
1961
+ * Returns a new schedule that stops execution when the given predicate on the
1962
+ * output evaluates to `true`.
1963
+ *
1964
+ * **Details**
1965
+ *
1966
+ * This function modifies an existing schedule so that it only continues
1967
+ * executing while the given predicate returns false for its output values. Once
1968
+ * the predicate evaluates to `true`, execution stops.
1969
+ *
1970
+ * The output of the resulting schedule remains the same, but its duration is
1971
+ * now constrained by a stopping condition based on its own output.
1972
+ *
1973
+ * @see {@link untilOutputEffect} If you need to use an effectful predicate.
1974
+ *
1975
+ * @since 2.0.0
1976
+ * @category Recurrence Conditions
1977
+ */
1978
+ export const untilOutput: {
1979
+ <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
1980
+ <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>
1981
+ } = internal.untilOutput
1982
+
1983
+ /**
1984
+ * Returns a new schedule that stops execution when the given effectful
1985
+ * predicate on the output evaluates to `true`.
1986
+ *
1987
+ * **Details**
1988
+ *
1989
+ * This function modifies an existing schedule so that it only continues
1990
+ * executing while the provided effectful predicate returns `false` for its
1991
+ * output values. Once the predicate returns `true`, execution stops.
1992
+ *
1993
+ * @see {@link untilOutput} If you need to use a pure predicate.
1994
+ *
1995
+ * @since 2.0.0
1996
+ * @category Recurrence Conditions
1997
+ */
1998
+ export const untilOutputEffect: {
1999
+ <Out, R2>(
2000
+ f: (out: Out) => Effect.Effect<boolean, never, R2>
2001
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
2002
+ <Out, In, R, R2>(
2003
+ self: Schedule<Out, In, R>,
2004
+ f: (out: Out) => Effect.Effect<boolean, never, R2>
2005
+ ): Schedule<Out, In, R | R2>
2006
+ } = internal.untilOutputEffect
2007
+
2008
+ /**
2009
+ * Returns a new schedule that limits execution to a fixed duration.
2010
+ *
2011
+ * **Details**
2012
+ *
2013
+ * This function modifies an existing schedule to stop execution after a
2014
+ * specified duration has passed. The schedule continues as normal until the
2015
+ * duration is reached, at which point it stops automatically.
2016
+ *
2017
+ * @since 2.0.0
2018
+ * @category Recurrence Conditions
2019
+ */
2020
+ export const upTo: {
2021
+ (duration: Duration.DurationInput): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
2022
+ <Out, In, R>(self: Schedule<Out, In, R>, duration: Duration.DurationInput): Schedule<Out, In, R>
2023
+ } = internal.upTo
2024
+
2025
+ /**
2026
+ * Returns a new schedule that continues execution as long as the given
2027
+ * predicate on the input is true.
2028
+ *
2029
+ * **Details**
2030
+ *
2031
+ * This function modifies an existing schedule so that it only continues
2032
+ * execution while a specified predicate holds true for its input. If the
2033
+ * predicate evaluates to `false` at any step, the schedule stops.
2034
+ *
2035
+ * @see {@link whileInputEffect} If you need to use an effectful predicate.
2036
+ *
2037
+ * @since 2.0.0
2038
+ * @category Recurrence Conditions
2039
+ */
2040
+ export const whileInput: {
2041
+ <In>(f: Predicate<In>): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
2042
+ <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<In>): Schedule<Out, In, R>
2043
+ } = internal.whileInput
2044
+
2045
+ /**
2046
+ * Returns a new schedule that continues execution for as long as the given
2047
+ * effectful predicate on the input evaluates to `true`.
2048
+ *
2049
+ * **Details**
2050
+ *
2051
+ * This function modifies an existing schedule so that it only continues
2052
+ * execution while an effectful predicate holds true for its input. If the
2053
+ * predicate evaluates to `false` at any step, the schedule stops.
2054
+ *
2055
+ * @see {@link whileInput} If you need to use a pure predicate.
2056
+ *
2057
+ * @since 2.0.0
2058
+ * @category Recurrence Conditions
2059
+ */
2060
+ export const whileInputEffect: {
2061
+ <In, R2>(
2062
+ f: (input: In) => Effect.Effect<boolean, never, R2>
2063
+ ): <Out, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
2064
+ <Out, In, R, R2>(
2065
+ self: Schedule<Out, In, R>,
2066
+ f: (input: In) => Effect.Effect<boolean, never, R2>
2067
+ ): Schedule<Out, In, R | R2>
2068
+ } = internal.whileInputEffect
2069
+
2070
+ /**
2071
+ * Returns a new schedule that continues execution for as long as the given
2072
+ * predicate on the output evaluates to `true`.
2073
+ *
2074
+ * **Details**
2075
+ *
2076
+ * This function modifies an existing schedule so that it only continues
2077
+ * execution while a provided condition holds true for its output. If the
2078
+ * predicate returns `false`, the schedule stops.
2079
+ *
2080
+ * @see {@link whileOutputEffect} If you need to use an effectful predicate.
2081
+ *
2082
+ * @since 2.0.0
2083
+ * @category Recurrence Conditions
2084
+ */
2085
+ export const whileOutput: {
2086
+ <Out>(f: Predicate<Out>): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R>
2087
+ <Out, In, R>(self: Schedule<Out, In, R>, f: Predicate<Out>): Schedule<Out, In, R>
2088
+ } = internal.whileOutput
2089
+
2090
+ /**
2091
+ * Returns a new schedule that continues execution for as long as the given
2092
+ * effectful predicate on the output evaluates to `true`.
2093
+ *
2094
+ * **Details**
2095
+ *
2096
+ * This function modifies an existing schedule so that it only continues
2097
+ * execution while an effectful condition holds true for its output. If the
2098
+ * effectful predicate returns `false`, the schedule stops.
2099
+ *
2100
+ * @see {@link whileOutput} If you need to use a pure predicate.
2101
+ *
2102
+ * @since 2.0.0
2103
+ * @category Recurrence Conditions
2104
+ */
2105
+ export const whileOutputEffect: {
2106
+ <Out, R2>(
2107
+ f: (out: Out) => Effect.Effect<boolean, never, R2>
2108
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In, R2 | R>
2109
+ <Out, In, R, R2>(
2110
+ self: Schedule<Out, In, R>,
2111
+ f: (out: Out) => Effect.Effect<boolean, never, R2>
2112
+ ): Schedule<Out, In, R | R2>
2113
+ } = internal.whileOutputEffect
2114
+
2115
+ /**
2116
+ * Creates a schedule that divides time into fixed `interval`-long windows,
2117
+ * triggering execution at the start of each new window.
2118
+ *
2119
+ * **Details**
2120
+ *
2121
+ * This function produces a schedule that waits until the next time window
2122
+ * boundary before executing. Each window spans a fixed duration specified by
2123
+ * `interval`. If an action completes midway through a window, the schedule
2124
+ * waits until the next full window starts before proceeding.
2125
+ *
2126
+ * For example, `windowed(Duration.seconds(10))` would produce a schedule as
2127
+ * follows:
2128
+ *
2129
+ * ```text
2130
+ * 10s 10s 10s 10s
2131
+ * |----------|----------|----------|----------|
2132
+ * |action------|sleep---|act|-sleep|action----|
2133
+ * ```
2134
+ *
2135
+ * @since 2.0.0
2136
+ * @category Constructors
2137
+ */
2138
+ export const windowed: (interval: Duration.DurationInput) => Schedule<number> = internal.windowed
2139
+
2140
+ /**
2141
+ * The same as {@link intersect} but ignores the right output.
2142
+ *
2143
+ * @since 2.0.0
2144
+ * @category Composition
2145
+ */
2146
+ export const zipLeft: {
2147
+ <Out2, In2, R2>(
2148
+ that: Schedule<Out2, In2, R2>
2149
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out, In & In2, R2 | R>
2150
+ <Out, In, R, Out2, In2, R2>(
2151
+ self: Schedule<Out, In, R>,
2152
+ that: Schedule<Out2, In2, R2>
2153
+ ): Schedule<Out, In & In2, R | R2>
2154
+ } = internal.zipLeft
2155
+
2156
+ /**
2157
+ * The same as {@link intersect} but ignores the left output.
2158
+ *
2159
+ * @since 2.0.0
2160
+ * @category Composition
2161
+ */
2162
+ export const zipRight: {
2163
+ <Out2, In2, R2>(
2164
+ that: Schedule<Out2, In2, R2>
2165
+ ): <Out, In, R>(self: Schedule<Out, In, R>) => Schedule<Out2, In & In2, R2 | R>
2166
+ <Out, In, R, Out2, In2, R2>(
2167
+ self: Schedule<Out, In, R>,
2168
+ that: Schedule<Out2, In2, R2>
2169
+ ): Schedule<Out2, In & In2, R | R2>
2170
+ } = internal.zipRight
2171
+
2172
+ /**
2173
+ * Equivalent to {@link intersect} followed by {@link map}.
2174
+ *
2175
+ * @since 2.0.0
2176
+ * @category Composition
2177
+ */
2178
+ export const zipWith: {
2179
+ <Out2, In2, R2, Out, Out3>(
2180
+ that: Schedule<Out2, In2, R2>,
2181
+ f: (out: Out, out2: Out2) => Out3
2182
+ ): <In, R>(self: Schedule<Out, In, R>) => Schedule<Out3, In & In2, R2 | R>
2183
+ <Out, In, R, Out2, In2, R2, Out3>(
2184
+ self: Schedule<Out, In, R>,
2185
+ that: Schedule<Out2, In2, R2>,
2186
+ f: (out: Out, out2: Out2) => Out3
2187
+ ): Schedule<Out3, In & In2, R | R2>
2188
+ } = internal.zipWith
2189
+
2190
+ /**
2191
+ * @since 3.15.0
2192
+ * @category models
2193
+ */
2194
+ export interface CurrentIterationMetadata {
2195
+ readonly _: unique symbol
2196
+ }
2197
+
2198
+ /**
2199
+ * @since 3.15.0
2200
+ * @category models
2201
+ */
2202
+ export interface IterationMetadata {
2203
+ readonly input: unknown
2204
+ readonly output: unknown
2205
+ readonly recurrence: number
2206
+ readonly start: number
2207
+ readonly now: number
2208
+ readonly elapsed: Duration.Duration
2209
+ readonly elapsedSincePrevious: Duration.Duration
2210
+ }
2211
+
2212
+ /**
2213
+ * @since 3.15.0
2214
+ * @category models
2215
+ */
2216
+ export const CurrentIterationMetadata: Context.Reference<
2217
+ CurrentIterationMetadata,
2218
+ IterationMetadata
2219
+ > = internal.CurrentIterationMetadata