effect 4.0.0-beta.4 → 4.0.0-beta.6

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 (310) hide show
  1. package/dist/Cause.d.ts +1 -1
  2. package/dist/Cause.d.ts.map +1 -1
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +6 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Config.d.ts +1 -1
  7. package/dist/Data.d.ts +3 -2
  8. package/dist/Data.d.ts.map +1 -1
  9. package/dist/Data.js +9 -8
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +0 -226
  12. package/dist/Effect.d.ts.map +1 -1
  13. package/dist/Effect.js +0 -118
  14. package/dist/Effect.js.map +1 -1
  15. package/dist/Encoding.d.ts +194 -0
  16. package/dist/Encoding.d.ts.map +1 -0
  17. package/dist/Encoding.js +352 -0
  18. package/dist/Encoding.js.map +1 -0
  19. package/dist/Equal.js.map +1 -1
  20. package/dist/FileSystem.d.ts +1 -1
  21. package/dist/FileSystem.d.ts.map +1 -1
  22. package/dist/FileSystem.js +5 -5
  23. package/dist/FileSystem.js.map +1 -1
  24. package/dist/Filter.d.ts +30 -1
  25. package/dist/Filter.d.ts.map +1 -1
  26. package/dist/Filter.js +15 -0
  27. package/dist/Filter.js.map +1 -1
  28. package/dist/Formatter.js +1 -1
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Graph.d.ts.map +1 -1
  31. package/dist/Graph.js +2 -2
  32. package/dist/Graph.js.map +1 -1
  33. package/dist/Latch.d.ts +109 -0
  34. package/dist/Latch.d.ts.map +1 -0
  35. package/dist/Latch.js +72 -0
  36. package/dist/Latch.js.map +1 -0
  37. package/dist/Pipeable.d.ts +17 -0
  38. package/dist/Pipeable.d.ts.map +1 -1
  39. package/dist/Pipeable.js +19 -1
  40. package/dist/Pipeable.js.map +1 -1
  41. package/dist/PlatformError.d.ts +8 -7
  42. package/dist/PlatformError.d.ts.map +1 -1
  43. package/dist/PlatformError.js +2 -2
  44. package/dist/PlatformError.js.map +1 -1
  45. package/dist/Pool.d.ts +5 -3
  46. package/dist/Pool.d.ts.map +1 -1
  47. package/dist/Pool.js +6 -4
  48. package/dist/Pool.js.map +1 -1
  49. package/dist/PubSub.d.ts +3 -2
  50. package/dist/PubSub.d.ts.map +1 -1
  51. package/dist/PubSub.js +3 -2
  52. package/dist/PubSub.js.map +1 -1
  53. package/dist/Request.d.ts +1 -1
  54. package/dist/Request.d.ts.map +1 -1
  55. package/dist/Request.js +2 -1
  56. package/dist/Request.js.map +1 -1
  57. package/dist/RequestResolver.d.ts +0 -20
  58. package/dist/RequestResolver.d.ts.map +1 -1
  59. package/dist/RequestResolver.js +0 -20
  60. package/dist/RequestResolver.js.map +1 -1
  61. package/dist/Schedule.d.ts +2 -2
  62. package/dist/Schedule.d.ts.map +1 -1
  63. package/dist/Schedule.js +30 -16
  64. package/dist/Schedule.js.map +1 -1
  65. package/dist/Schema.d.ts +192 -42
  66. package/dist/Schema.d.ts.map +1 -1
  67. package/dist/Schema.js +385 -71
  68. package/dist/Schema.js.map +1 -1
  69. package/dist/SchemaGetter.d.ts +2 -2
  70. package/dist/SchemaGetter.d.ts.map +1 -1
  71. package/dist/SchemaGetter.js +12 -14
  72. package/dist/SchemaGetter.js.map +1 -1
  73. package/dist/SchemaRepresentation.d.ts +44 -43
  74. package/dist/SchemaRepresentation.d.ts.map +1 -1
  75. package/dist/SchemaRepresentation.js +5 -2
  76. package/dist/SchemaRepresentation.js.map +1 -1
  77. package/dist/SchemaTransformation.d.ts +37 -0
  78. package/dist/SchemaTransformation.d.ts.map +1 -1
  79. package/dist/SchemaTransformation.js +80 -0
  80. package/dist/SchemaTransformation.js.map +1 -1
  81. package/dist/Semaphore.d.ts +211 -0
  82. package/dist/Semaphore.d.ts.map +1 -0
  83. package/dist/{PartitionedSemaphore.js → Semaphore.js} +97 -13
  84. package/dist/Semaphore.js.map +1 -0
  85. package/dist/Stream.d.ts.map +1 -1
  86. package/dist/Stream.js +9 -8
  87. package/dist/Stream.js.map +1 -1
  88. package/dist/Struct.d.ts +16 -0
  89. package/dist/Struct.d.ts.map +1 -1
  90. package/dist/Struct.js +22 -0
  91. package/dist/Struct.js.map +1 -1
  92. package/dist/SubscriptionRef.d.ts +2 -1
  93. package/dist/SubscriptionRef.d.ts.map +1 -1
  94. package/dist/SubscriptionRef.js +2 -1
  95. package/dist/SubscriptionRef.js.map +1 -1
  96. package/dist/SynchronizedRef.d.ts +2 -1
  97. package/dist/SynchronizedRef.d.ts.map +1 -1
  98. package/dist/SynchronizedRef.js +2 -1
  99. package/dist/SynchronizedRef.js.map +1 -1
  100. package/dist/Types.d.ts +14 -6
  101. package/dist/Types.d.ts.map +1 -1
  102. package/dist/index.d.ts +14 -5
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +14 -5
  105. package/dist/index.js.map +1 -1
  106. package/dist/internal/core.js +11 -3
  107. package/dist/internal/core.js.map +1 -1
  108. package/dist/internal/effect.js.map +1 -1
  109. package/dist/internal/rcRef.js +2 -1
  110. package/dist/internal/rcRef.js.map +1 -1
  111. package/dist/testing/TestClock.d.ts +3 -2
  112. package/dist/testing/TestClock.d.ts.map +1 -1
  113. package/dist/testing/TestClock.js +5 -3
  114. package/dist/testing/TestClock.js.map +1 -1
  115. package/dist/unstable/ai/AiError.d.ts +39 -39
  116. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  117. package/dist/unstable/ai/Chat.js +2 -1
  118. package/dist/unstable/ai/Chat.js.map +1 -1
  119. package/dist/unstable/ai/McpSchema.d.ts +51 -51
  120. package/dist/unstable/ai/Prompt.d.ts +20 -20
  121. package/dist/unstable/ai/Response.d.ts +25 -25
  122. package/dist/unstable/cli/CliError.d.ts +5 -5
  123. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  124. package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -1
  125. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  126. package/dist/unstable/cluster/Entity.d.ts +2 -1
  127. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  128. package/dist/unstable/cluster/Entity.js.map +1 -1
  129. package/dist/unstable/cluster/Envelope.d.ts +1 -1
  130. package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
  131. package/dist/unstable/cluster/Message.d.ts +5 -5
  132. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  133. package/dist/unstable/cluster/MessageStorage.js +2 -1
  134. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  135. package/dist/unstable/cluster/Reply.d.ts +3 -3
  136. package/dist/unstable/cluster/Runner.d.ts +1 -1
  137. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  138. package/dist/unstable/cluster/Runners.js +4 -3
  139. package/dist/unstable/cluster/Runners.js.map +1 -1
  140. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  141. package/dist/unstable/cluster/Sharding.js +7 -5
  142. package/dist/unstable/cluster/Sharding.js.map +1 -1
  143. package/dist/unstable/cluster/internal/entityManager.js +4 -3
  144. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  145. package/dist/unstable/cluster/internal/entityReaper.js +2 -1
  146. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  147. package/dist/unstable/cluster/internal/resourceRef.js +2 -1
  148. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  149. package/dist/unstable/devtools/DevToolsSchema.d.ts +36 -36
  150. package/dist/unstable/encoding/Sse.d.ts +1 -1
  151. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  152. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  153. package/dist/unstable/eventlog/EventLog.js +2 -1
  154. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  155. package/dist/unstable/eventlog/EventLogRemote.d.ts +5 -5
  156. package/dist/unstable/http/Cookies.d.ts +1 -1
  157. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  158. package/dist/unstable/http/HttpEffect.js +18 -26
  159. package/dist/unstable/http/HttpEffect.js.map +1 -1
  160. package/dist/unstable/http/Multipart.d.ts +2 -2
  161. package/dist/unstable/http/UrlParams.d.ts +1 -1
  162. package/dist/unstable/httpapi/HttpApiBuilder.js +2 -2
  163. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  164. package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
  165. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  166. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  167. package/dist/unstable/persistence/KeyValueStore.js +6 -6
  168. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  169. package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
  170. package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
  171. package/dist/unstable/persistence/PersistedCache.js +2 -1
  172. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  173. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  174. package/dist/unstable/persistence/PersistedQueue.js +6 -5
  175. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  176. package/dist/unstable/process/ChildProcessSpawner.d.ts +6 -0
  177. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  178. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  179. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  180. package/dist/unstable/reactivity/Atom.js +12 -9
  181. package/dist/unstable/reactivity/Atom.js.map +1 -1
  182. package/dist/unstable/reactivity/Hydration.d.ts +39 -0
  183. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
  184. package/dist/unstable/reactivity/Hydration.js +76 -0
  185. package/dist/unstable/reactivity/Hydration.js.map +1 -0
  186. package/dist/unstable/reactivity/index.d.ts +4 -0
  187. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  188. package/dist/unstable/reactivity/index.js +4 -0
  189. package/dist/unstable/reactivity/index.js.map +1 -1
  190. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  191. package/dist/unstable/rpc/RpcClient.js +3 -2
  192. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  193. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  194. package/dist/unstable/rpc/RpcServer.js +5 -3
  195. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  196. package/dist/unstable/rpc/Utils.d.ts.map +1 -1
  197. package/dist/unstable/rpc/Utils.js +2 -1
  198. package/dist/unstable/rpc/Utils.js.map +1 -1
  199. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  200. package/dist/unstable/socket/Socket.js +3 -2
  201. package/dist/unstable/socket/Socket.js.map +1 -1
  202. package/dist/unstable/sql/Statement.js +0 -1
  203. package/dist/unstable/sql/Statement.js.map +1 -1
  204. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  205. package/dist/unstable/workers/Worker.js +2 -1
  206. package/dist/unstable/workers/Worker.js.map +1 -1
  207. package/dist/unstable/workflow/DurableDeferred.js +2 -2
  208. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  209. package/dist/unstable/workflow/Workflow.d.ts +1 -1
  210. package/dist/unstable/workflow/WorkflowEngine.d.ts +2 -1
  211. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  212. package/dist/unstable/workflow/WorkflowEngine.js +2 -1
  213. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  214. package/package.json +1 -2
  215. package/src/Cause.ts +1 -1
  216. package/src/Channel.ts +6 -4
  217. package/src/Data.ts +10 -9
  218. package/src/Effect.ts +0 -246
  219. package/src/Encoding.ts +879 -0
  220. package/src/Equal.ts +2 -2
  221. package/src/FileSystem.ts +7 -8
  222. package/src/Filter.ts +48 -1
  223. package/src/Formatter.ts +1 -1
  224. package/src/Graph.ts +8 -5
  225. package/src/Latch.ts +112 -0
  226. package/src/Pipeable.ts +32 -1
  227. package/src/PlatformError.ts +5 -5
  228. package/src/Pool.ts +9 -7
  229. package/src/PubSub.ts +10 -9
  230. package/src/Request.ts +3 -2
  231. package/src/RequestResolver.ts +0 -20
  232. package/src/Schedule.ts +217 -115
  233. package/src/Schema.ts +567 -105
  234. package/src/SchemaGetter.ts +12 -14
  235. package/src/SchemaRepresentation.ts +5 -2
  236. package/src/SchemaTransformation.ts +104 -0
  237. package/src/Semaphore.ts +356 -0
  238. package/src/Stream.ts +9 -8
  239. package/src/Struct.ts +26 -0
  240. package/src/SubscriptionRef.ts +3 -2
  241. package/src/SynchronizedRef.ts +3 -2
  242. package/src/Types.ts +12 -2
  243. package/src/index.ts +17 -6
  244. package/src/internal/core.ts +10 -2
  245. package/src/internal/effect.ts +3 -2
  246. package/src/internal/rcRef.ts +2 -1
  247. package/src/testing/TestClock.ts +8 -6
  248. package/src/unstable/ai/AiError.ts +1 -1
  249. package/src/unstable/ai/Chat.ts +2 -1
  250. package/src/unstable/ai/Prompt.ts +20 -20
  251. package/src/unstable/ai/Response.ts +22 -22
  252. package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -2
  253. package/src/unstable/cluster/Entity.ts +2 -1
  254. package/src/unstable/cluster/Envelope.ts +1 -1
  255. package/src/unstable/cluster/MessageStorage.ts +2 -1
  256. package/src/unstable/cluster/Runners.ts +6 -5
  257. package/src/unstable/cluster/Sharding.ts +8 -6
  258. package/src/unstable/cluster/internal/entityManager.ts +6 -5
  259. package/src/unstable/cluster/internal/entityReaper.ts +2 -1
  260. package/src/unstable/cluster/internal/resourceRef.ts +2 -1
  261. package/src/unstable/eventlog/EventLog.ts +2 -1
  262. package/src/unstable/http/HttpEffect.ts +17 -25
  263. package/src/unstable/http/Multipart.ts +2 -2
  264. package/src/unstable/http/UrlParams.ts +1 -1
  265. package/src/unstable/httpapi/HttpApiBuilder.ts +2 -2
  266. package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
  267. package/src/unstable/persistence/KeyValueStore.ts +6 -6
  268. package/src/unstable/persistence/PersistedCache.ts +20 -9
  269. package/src/unstable/persistence/PersistedQueue.ts +7 -6
  270. package/src/unstable/process/ChildProcessSpawner.ts +6 -0
  271. package/src/unstable/reactivity/Atom.ts +7 -5
  272. package/src/unstable/reactivity/Hydration.ts +112 -0
  273. package/src/unstable/reactivity/index.ts +5 -0
  274. package/src/unstable/rpc/RpcClient.ts +4 -3
  275. package/src/unstable/rpc/RpcServer.ts +6 -4
  276. package/src/unstable/rpc/Utils.ts +2 -1
  277. package/src/unstable/socket/Socket.ts +3 -2
  278. package/src/unstable/sql/Statement.ts +0 -1
  279. package/src/unstable/workers/Worker.ts +2 -1
  280. package/src/unstable/workflow/DurableDeferred.ts +2 -2
  281. package/src/unstable/workflow/WorkflowEngine.ts +3 -2
  282. package/dist/PartitionedSemaphore.d.ts +0 -52
  283. package/dist/PartitionedSemaphore.d.ts.map +0 -1
  284. package/dist/PartitionedSemaphore.js.map +0 -1
  285. package/dist/encoding/Base64.d.ts +0 -67
  286. package/dist/encoding/Base64.d.ts.map +0 -1
  287. package/dist/encoding/Base64.js +0 -146
  288. package/dist/encoding/Base64.js.map +0 -1
  289. package/dist/encoding/Base64Url.d.ts +0 -60
  290. package/dist/encoding/Base64Url.d.ts.map +0 -1
  291. package/dist/encoding/Base64Url.js +0 -89
  292. package/dist/encoding/Base64Url.js.map +0 -1
  293. package/dist/encoding/EncodingError.d.ts +0 -31
  294. package/dist/encoding/EncodingError.d.ts.map +0 -1
  295. package/dist/encoding/EncodingError.js +0 -22
  296. package/dist/encoding/EncodingError.js.map +0 -1
  297. package/dist/encoding/Hex.d.ts +0 -61
  298. package/dist/encoding/Hex.d.ts.map +0 -1
  299. package/dist/encoding/Hex.js +0 -115
  300. package/dist/encoding/Hex.js.map +0 -1
  301. package/dist/encoding/index.d.ts +0 -26
  302. package/dist/encoding/index.d.ts.map +0 -1
  303. package/dist/encoding/index.js +0 -27
  304. package/dist/encoding/index.js.map +0 -1
  305. package/src/PartitionedSemaphore.ts +0 -182
  306. package/src/encoding/Base64.ts +0 -366
  307. package/src/encoding/Base64Url.ts +0 -104
  308. package/src/encoding/EncodingError.ts +0 -35
  309. package/src/encoding/Hex.ts +0 -390
  310. package/src/encoding/index.ts +0 -31
package/src/Schedule.ts CHANGED
@@ -36,7 +36,7 @@ import * as Duration from "./Duration.ts"
36
36
  import type { Effect } from "./Effect.ts"
37
37
  import type { LazyArg } from "./Function.ts"
38
38
  import { constant, dual, identity } from "./Function.ts"
39
-
39
+ import { isEffect } from "./internal/core.ts"
40
40
  import * as effect from "./internal/effect.ts"
41
41
  import { type Pipeable, pipeArguments } from "./Pipeable.ts"
42
42
  import { hasProperty } from "./Predicate.ts"
@@ -1140,116 +1140,211 @@ export const andThenResult: {
1140
1140
  } = dual(2, <Output, Input, Error, Env, Output2, Input2, Error2, Env2>(
1141
1141
  self: Schedule<Output, Input, Error, Env>,
1142
1142
  other: Schedule<Output2, Input2, Error2, Env2>
1143
- ): Schedule<Result.Result<Output2, Output>, Input & Input2, Error | Error2, Env | Env2> =>
1144
- fromStep(effect.map(
1145
- effect.zip(toStep(self), toStep(other)),
1146
- ([leftStep, rightStep]) => {
1147
- let currentStep: (now: number, input: Input & Input2) => Pull.Pull<
1148
- [Output | Output2, Duration.Duration],
1143
+ ): Schedule<Result.Result<Output, Output2>, Input & Input2, Error | Error2, Env | Env2> =>
1144
+ fromStep(effect.sync(() => {
1145
+ let currentSide = 0
1146
+ let currentStep:
1147
+ | undefined
1148
+ | ((now: number, input: Input & Input2) => Pull.Pull<
1149
+ [Result.Result<Output, Output2>, Duration.Duration],
1149
1150
  Error | Error2,
1150
- Output | Output2,
1151
+ Result.Result<Output, Output2>,
1151
1152
  Env | Env2
1152
- > = leftStep
1153
- let toResult: (output: Output | Output2) => Result.Result<Output2, Output> = Result.fail as any
1154
- return (now, input) =>
1155
- Pull.matchEffect(currentStep(now, input), {
1156
- onSuccess: ([output, duration]) =>
1157
- effect.succeed</**
1158
- * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1159
- * schedule to completion. Once the left schedule is complete, the right (i.e.
1160
- * `other`) schedule will be executed to completion.
1161
- *
1162
- * The output of the resulting schedule is a `Result` where outputs of the
1163
- * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1164
- * schedule are emitted as `Result.Ok<Output>`.
1165
- *
1166
- * @example
1167
- * ```ts
1168
- * import { Console, Effect, Result, Schedule } from "effect"
1169
- *
1170
- * // Track which phase of the schedule we're in
1171
- * const phaseTracker = Schedule.andThenResult(
1172
- * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1173
- * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1174
- * )
1175
- *
1176
- * const program = Effect.gen(function*() {
1177
- * yield* Effect.repeat(
1178
- * Effect.gen(function*() {
1179
- * yield* Console.log("Task executed")
1180
- * return "task-result"
1181
- * }),
1182
- * phaseTracker.pipe(
1183
- * Schedule.tapOutput((result) =>
1184
- * Result.match(result, {
1185
- * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1186
- * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1187
- * })
1188
- * )
1189
- * )
1190
- * )
1191
- * })
1192
- * ```
1193
- *
1194
- * @since 2.0.0
1195
- * @category sequencing
1196
- */
1197
- [Result.Result<Output2, Output>, Duration.Duration]>([toResult(output), duration]),
1198
- onFailure: effect.failCause,
1199
- onDone: (output) =>
1200
- effect.suspend(() => {
1201
- const pull = effect.succeed</**
1202
- * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1203
- * schedule to completion. Once the left schedule is complete, the right (i.e.
1204
- * `other`) schedule will be executed to completion.
1205
- *
1206
- * The output of the resulting schedule is a `Result` where outputs of the
1207
- * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1208
- * schedule are emitted as `Result.Ok<Output>`.
1209
- *
1210
- * @example
1211
- * ```ts
1212
- * import { Console, Effect, Result, Schedule } from "effect"
1213
- *
1214
- * // Track which phase of the schedule we're in
1215
- * const phaseTracker = Schedule.andThenResult(
1216
- * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1217
- * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1218
- * )
1219
- *
1220
- * const program = Effect.gen(function*() {
1221
- * yield* Effect.repeat(
1222
- * Effect.gen(function*() {
1223
- * yield* Console.log("Task executed")
1224
- * return "task-result"
1225
- * }),
1226
- * phaseTracker.pipe(
1227
- * Schedule.tapOutput((result) =>
1228
- * Result.match(result, {
1229
- * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1230
- * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1231
- * })
1232
- * )
1233
- * )
1234
- * )
1235
- * })
1236
- * ```
1237
- *
1238
- * @since 2.0.0
1239
- * @category sequencing
1240
- */
1241
- [Result.Result<Output2, Output>, Duration.Duration]>(
1242
- [toResult(output), Duration.zero]
1243
- )
1244
- if (currentStep === leftStep) {
1245
- currentStep = rightStep
1246
- toResult = Result.succeed as any
1247
- }
1248
- return pull
1249
- })
1250
- });
1251
- }
1252
- )))
1153
+ >)
1154
+ const left = map(self, Result.succeed)
1155
+ const right = map(other, Result.fail)
1156
+ return function recur(
1157
+ now,
1158
+ input
1159
+ ): Pull.Pull<
1160
+ [Result.Result<Output, Output2>, Duration.Duration],
1161
+ Error | Error2,
1162
+ Result.Result<Output, Output2>,
1163
+ Env | Env2
1164
+ > {
1165
+ if (currentStep) return currentStep(now, input)
1166
+ return toStep<
1167
+ /**
1168
+ * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1169
+ * schedule to completion. Once the left schedule is complete, the right (i.e.
1170
+ * `other`) schedule will be executed to completion.
1171
+ *
1172
+ * The output of the resulting schedule is a `Result` where outputs of the
1173
+ * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1174
+ * schedule are emitted as `Result.Ok<Output>`.
1175
+ *
1176
+ * @example
1177
+ * ```ts
1178
+ * import { Console, Effect, Result, Schedule } from "effect"
1179
+ *
1180
+ * // Track which phase of the schedule we're in
1181
+ * const phaseTracker = Schedule.andThenResult(
1182
+ * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1183
+ * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1184
+ * )
1185
+ *
1186
+ * const program = Effect.gen(function*() {
1187
+ * yield* Effect.repeat(
1188
+ * Effect.gen(function*() {
1189
+ * yield* Console.log("Task executed")
1190
+ * return "task-result"
1191
+ * }),
1192
+ * phaseTracker.pipe(
1193
+ * Schedule.tapOutput((result) =>
1194
+ * Result.match(result, {
1195
+ * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1196
+ * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1197
+ * })
1198
+ * )
1199
+ * )
1200
+ * )
1201
+ * })
1202
+ * ```
1203
+ *
1204
+ * @since 2.0.0
1205
+ * @category sequencing
1206
+ */
1207
+ Result.Result<Output, Output2>,
1208
+ /**
1209
+ * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1210
+ * schedule to completion. Once the left schedule is complete, the right (i.e.
1211
+ * `other`) schedule will be executed to completion.
1212
+ *
1213
+ * The output of the resulting schedule is a `Result` where outputs of the
1214
+ * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1215
+ * schedule are emitted as `Result.Ok<Output>`.
1216
+ *
1217
+ * @example
1218
+ * ```ts
1219
+ * import { Console, Effect, Result, Schedule } from "effect"
1220
+ *
1221
+ * // Track which phase of the schedule we're in
1222
+ * const phaseTracker = Schedule.andThenResult(
1223
+ * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1224
+ * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1225
+ * )
1226
+ *
1227
+ * const program = Effect.gen(function*() {
1228
+ * yield* Effect.repeat(
1229
+ * Effect.gen(function*() {
1230
+ * yield* Console.log("Task executed")
1231
+ * return "task-result"
1232
+ * }),
1233
+ * phaseTracker.pipe(
1234
+ * Schedule.tapOutput((result) =>
1235
+ * Result.match(result, {
1236
+ * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1237
+ * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1238
+ * })
1239
+ * )
1240
+ * )
1241
+ * )
1242
+ * })
1243
+ * ```
1244
+ *
1245
+ * @since 2.0.0
1246
+ * @category sequencing
1247
+ */
1248
+ Input & Input2,
1249
+ /**
1250
+ * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1251
+ * schedule to completion. Once the left schedule is complete, the right (i.e.
1252
+ * `other`) schedule will be executed to completion.
1253
+ *
1254
+ * The output of the resulting schedule is a `Result` where outputs of the
1255
+ * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1256
+ * schedule are emitted as `Result.Ok<Output>`.
1257
+ *
1258
+ * @example
1259
+ * ```ts
1260
+ * import { Console, Effect, Result, Schedule } from "effect"
1261
+ *
1262
+ * // Track which phase of the schedule we're in
1263
+ * const phaseTracker = Schedule.andThenResult(
1264
+ * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1265
+ * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1266
+ * )
1267
+ *
1268
+ * const program = Effect.gen(function*() {
1269
+ * yield* Effect.repeat(
1270
+ * Effect.gen(function*() {
1271
+ * yield* Console.log("Task executed")
1272
+ * return "task-result"
1273
+ * }),
1274
+ * phaseTracker.pipe(
1275
+ * Schedule.tapOutput((result) =>
1276
+ * Result.match(result, {
1277
+ * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1278
+ * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1279
+ * })
1280
+ * )
1281
+ * )
1282
+ * )
1283
+ * })
1284
+ * ```
1285
+ *
1286
+ * @since 2.0.0
1287
+ * @category sequencing
1288
+ */
1289
+ Error | Error2,
1290
+ /**
1291
+ * Returns a new `Schedule` that will first execute the left (i.e. `self`)
1292
+ * schedule to completion. Once the left schedule is complete, the right (i.e.
1293
+ * `other`) schedule will be executed to completion.
1294
+ *
1295
+ * The output of the resulting schedule is a `Result` where outputs of the
1296
+ * left schedule are emitted as `Result.Err<Output>` and outputs of the right
1297
+ * schedule are emitted as `Result.Ok<Output>`.
1298
+ *
1299
+ * @example
1300
+ * ```ts
1301
+ * import { Console, Effect, Result, Schedule } from "effect"
1302
+ *
1303
+ * // Track which phase of the schedule we're in
1304
+ * const phaseTracker = Schedule.andThenResult(
1305
+ * Schedule.exponential("100 millis").pipe(Schedule.take(2)),
1306
+ * Schedule.spaced("500 millis").pipe(Schedule.take(2))
1307
+ * )
1308
+ *
1309
+ * const program = Effect.gen(function*() {
1310
+ * yield* Effect.repeat(
1311
+ * Effect.gen(function*() {
1312
+ * yield* Console.log("Task executed")
1313
+ * return "task-result"
1314
+ * }),
1315
+ * phaseTracker.pipe(
1316
+ * Schedule.tapOutput((result) =>
1317
+ * Result.match(result, {
1318
+ * onFailure: (phase1Output) => Console.log(`Phase 1: ${phase1Output}`),
1319
+ * onSuccess: (phase2Output) => Console.log(`Phase 2: ${phase2Output}`)
1320
+ * })
1321
+ * )
1322
+ * )
1323
+ * )
1324
+ * })
1325
+ * ```
1326
+ *
1327
+ * @since 2.0.0
1328
+ * @category sequencing
1329
+ */
1330
+ Env | Env2
1331
+ >(currentSide === 0 ? left : right).pipe(
1332
+ effect.flatMap((step) => {
1333
+ currentSide++
1334
+ if (currentSide === 1) {
1335
+ currentStep = (now, input) =>
1336
+ Pull.catchDone(step(now, input), (_) => {
1337
+ currentStep = undefined
1338
+ return recur(now, input)
1339
+ })
1340
+ return currentStep(now, input)
1341
+ }
1342
+ currentStep = step
1343
+ return currentStep(now, input)
1344
+ })
1345
+ );
1346
+ };
1347
+ })))
1253
1348
 
1254
1349
  /**
1255
1350
  * Combines two `Schedule`s by recurring if both of the two schedules want
@@ -4050,7 +4145,7 @@ export const map: {
4050
4145
  * @since 2.0.0
4051
4146
  * @category mapping
4052
4147
  */
4053
- <Output, Output2, Error2 = never, Env2 = never>(f: (output: Output) => Effect<Output2, Error2, Env2>): <Input, Error, Env>(
4148
+ <Output, Output2, Error2 = never, Env2 = never>(f: (output: Output) => Output2 | Effect<Output2, Error2, Env2>): <Input, Error, Env>(
4054
4149
  self: Schedule<Output, Input, Error, Env>
4055
4150
  ) => Schedule<Output2, Input, Error | Error2, Env | Env2>
4056
4151
  /**
@@ -4117,17 +4212,24 @@ export const map: {
4117
4212
  */
4118
4213
  <Output, Input, Error, Env, Output2, Error2 = never, Env2 = never>(
4119
4214
  self: Schedule<Output, Input, Error, Env>,
4120
- f: (output: Output) => Effect<Output2, Error2, Env2>
4215
+ f: (output: Output) => Output2 | Effect<Output2, Error2, Env2>
4121
4216
  ): Schedule<Output2, Input, Error | Error2, Env | Env2>
4122
4217
  } = dual(2, <Output, Input, Error, Env, Output2, Error2 = never, Env2 = never>(
4123
4218
  self: Schedule<Output, Input, Error, Env>,
4124
- f: (output: Output) => Effect<Output2, Error2, Env2>
4219
+ f: (output: Output) => Output2 | Effect<Output2, Error2, Env2>
4125
4220
  ): Schedule<Output2, Input, Error | Error2, Env | Env2> => {
4126
4221
  const handle = Pull.matchEffect({
4127
- onSuccess: ([output, duration]: [Output, Duration.Duration]) =>
4128
- effect.map(f(output), (output) => [output, duration] as [Output2, Duration.Duration]),
4222
+ onSuccess: ([output, duration]: [Output, Duration.Duration]) => {
4223
+ const result = f(output)
4224
+ if (!isEffect(result)) return effect.succeed([result, duration] as [Output2, Duration.Duration])
4225
+ return effect.map(result, (output) => [output, duration] as [Output2, Duration.Duration])
4226
+ },
4129
4227
  onFailure: effect.failCause<Error>,
4130
- onDone: (output: Output) => effect.flatMap(f(output), Cause.done)
4228
+ onDone: (output: Output) => {
4229
+ const result = f(output)
4230
+ if (!isEffect(result)) return Cause.done(result as Output2)
4231
+ return effect.flatMap(result, Cause.done)
4232
+ }
4131
4233
  })
4132
4234
  return fromStep(effect.map(toStep(self), (step) => (now, input) => handle(step(now, input))))
4133
4235
  })