effect 4.0.0-beta.27 → 4.0.0-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Brand.d.ts +1 -1
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/ConfigProvider.d.ts +1 -1
- package/dist/Cron.d.ts +1 -1
- package/dist/Data.d.ts +1 -1
- package/dist/Data.d.ts.map +1 -1
- package/dist/Data.js.map +1 -1
- package/dist/Effect.d.ts +300 -184
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +99 -61
- package/dist/Effect.js.map +1 -1
- package/dist/Encoding.d.ts +1 -1
- package/dist/Exit.d.ts +24 -12
- package/dist/Exit.d.ts.map +1 -1
- package/dist/Exit.js +8 -4
- package/dist/Exit.js.map +1 -1
- package/dist/Fiber.d.ts +1 -0
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Fiber.js.map +1 -1
- package/dist/Function.d.ts +1 -9
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +2 -10
- package/dist/Function.js.map +1 -1
- package/dist/Graph.d.ts +1 -1
- package/dist/Newtype.d.ts +291 -0
- package/dist/Newtype.d.ts.map +1 -0
- package/dist/Newtype.js +161 -0
- package/dist/Newtype.js.map +1 -0
- package/dist/PlatformError.d.ts +2 -2
- package/dist/References.d.ts +6 -1
- package/dist/References.d.ts.map +1 -1
- package/dist/References.js +6 -1
- package/dist/References.js.map +1 -1
- package/dist/RequestResolver.d.ts +19 -19
- package/dist/RequestResolver.js +10 -10
- package/dist/RequestResolver.js.map +1 -1
- package/dist/Schedule.d.ts +142 -80
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +58 -32
- package/dist/Schedule.js.map +1 -1
- package/dist/Scheduler.d.ts +9 -0
- package/dist/Scheduler.d.ts.map +1 -1
- package/dist/Scheduler.js +11 -0
- package/dist/Scheduler.js.map +1 -1
- package/dist/Schema.d.ts +1 -1
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +3 -1
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +1 -1
- package/dist/SchemaAST.js.map +1 -1
- package/dist/Stdio.d.ts +6 -2
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +2 -2
- package/dist/Stdio.js.map +1 -1
- package/dist/Stream.d.ts +8 -4
- package/dist/Stream.d.ts.map +1 -1
- package/dist/Stream.js +8 -4
- package/dist/Stream.js.map +1 -1
- package/dist/Types.d.ts +1 -22
- package/dist/Types.d.ts.map +1 -1
- package/dist/index.d.ts +71 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +71 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +3 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +12 -28
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +4 -18
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +20 -1
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js +8 -0
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +65 -12
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +159 -45
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Toolkit.d.ts +1 -1
- package/dist/unstable/ai/Toolkit.d.ts.map +1 -1
- package/dist/unstable/ai/Toolkit.js +4 -11
- package/dist/unstable/ai/Toolkit.js.map +1 -1
- package/dist/unstable/ai/internal/codec-transformer.js +0 -5
- package/dist/unstable/ai/internal/codec-transformer.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +35 -8
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Message.d.ts +5 -5
- package/dist/unstable/cluster/Reply.d.ts +3 -3
- package/dist/unstable/encoding/Msgpack.d.ts +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +1 -1
- package/dist/unstable/http/Cookies.d.ts +45 -1
- package/dist/unstable/http/Cookies.d.ts.map +1 -1
- package/dist/unstable/http/Cookies.js +22 -0
- package/dist/unstable/http/Cookies.js.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +3 -7
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpClientError.d.ts +7 -7
- package/dist/unstable/http/HttpClientRequest.d.ts +5 -0
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +21 -17
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpEffect.d.ts +7 -0
- package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
- package/dist/unstable/http/HttpEffect.js +6 -0
- package/dist/unstable/http/HttpEffect.js.map +1 -1
- package/dist/unstable/http/HttpServerError.d.ts +6 -6
- package/dist/unstable/http/HttpServerRequest.d.ts +11 -0
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +291 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.d.ts +47 -1
- package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +227 -0
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/http/HttpStaticServer.d.ts +69 -0
- package/dist/unstable/http/HttpStaticServer.d.ts.map +1 -0
- package/dist/unstable/http/HttpStaticServer.js +353 -0
- package/dist/unstable/http/HttpStaticServer.js.map +1 -0
- package/dist/unstable/http/Multipart.d.ts +1 -1
- package/dist/unstable/http/UrlParams.d.ts +1 -1
- package/dist/unstable/http/index.d.ts +4 -0
- package/dist/unstable/http/index.d.ts.map +1 -1
- package/dist/unstable/http/index.js +4 -0
- package/dist/unstable/http/index.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +1 -0
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +7 -2
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +33 -15
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +4 -6
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +39 -9
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRegistry.js +26 -2
- package/dist/unstable/reactivity/AtomRegistry.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +8 -8
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +46 -20
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +5 -5
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +2 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.js +1 -1
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/socket/SocketServer.d.ts +3 -3
- package/dist/unstable/sql/Migrator.d.ts +1 -1
- package/dist/unstable/sql/SqlResolver.js +2 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +1 -1
- package/package.json +1 -1
- package/src/Brand.ts +1 -1
- package/src/Data.ts +1 -2
- package/src/Effect.ts +300 -184
- package/src/Exit.ts +24 -12
- package/src/Fiber.ts +1 -0
- package/src/Function.ts +2 -10
- package/src/Newtype.ts +308 -0
- package/src/References.ts +6 -1
- package/src/RequestResolver.ts +20 -20
- package/src/Schedule.ts +142 -80
- package/src/Scheduler.ts +12 -0
- package/src/Schema.ts +4 -2
- package/src/SchemaAST.ts +1 -4
- package/src/Stdio.ts +8 -4
- package/src/Stream.ts +8 -4
- package/src/Types.ts +1 -23
- package/src/index.ts +72 -3
- package/src/internal/effect.ts +3 -0
- package/src/unstable/ai/LanguageModel.ts +16 -37
- package/src/unstable/ai/McpSchema.ts +14 -0
- package/src/unstable/ai/McpServer.ts +224 -53
- package/src/unstable/ai/Toolkit.ts +5 -14
- package/src/unstable/ai/internal/codec-transformer.ts +0 -7
- package/src/unstable/cli/Prompt.ts +31 -9
- package/src/unstable/http/Cookies.ts +84 -0
- package/src/unstable/http/HttpClient.ts +5 -6
- package/src/unstable/http/HttpClientRequest.ts +21 -17
- package/src/unstable/http/HttpEffect.ts +8 -0
- package/src/unstable/http/HttpServerRequest.ts +388 -1
- package/src/unstable/http/HttpServerResponse.ts +328 -1
- package/src/unstable/http/HttpStaticServer.ts +456 -0
- package/src/unstable/http/index.ts +5 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +1 -0
- package/src/unstable/reactivity/Atom.ts +62 -35
- package/src/unstable/reactivity/AtomHttpApi.ts +45 -11
- package/src/unstable/reactivity/AtomRegistry.ts +30 -2
- package/src/unstable/reactivity/AtomRpc.ts +48 -17
- package/src/unstable/rpc/Rpc.ts +1 -3
- package/src/unstable/rpc/RpcMiddleware.ts +12 -6
- package/src/unstable/rpc/RpcServer.ts +2 -2
- package/src/unstable/rpc/Utils.ts +1 -1
- package/src/unstable/sql/SqlResolver.ts +2 -2
package/src/Schedule.ts
CHANGED
|
@@ -523,7 +523,9 @@ export const toStepWithSleep = <Output, Input, Error, Env>(
|
|
|
523
523
|
*
|
|
524
524
|
* @example
|
|
525
525
|
* ```ts
|
|
526
|
-
* import { Console, Duration, Effect, Schedule } from "effect"
|
|
526
|
+
* import { Console, Data, Duration, Effect, Schedule } from "effect"
|
|
527
|
+
*
|
|
528
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
527
529
|
*
|
|
528
530
|
* // Add random jitter to schedule delays
|
|
529
531
|
* const jitteredSchedule = Schedule.addDelay(
|
|
@@ -619,7 +621,7 @@ export const toStepWithSleep = <Output, Input, Error, Env>(
|
|
|
619
621
|
* Effect.gen(function*() {
|
|
620
622
|
* attempt++
|
|
621
623
|
* if (attempt < 5) {
|
|
622
|
-
* return yield* Effect.fail(new
|
|
624
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
623
625
|
* }
|
|
624
626
|
* return `Success on attempt ${attempt}`
|
|
625
627
|
* }),
|
|
@@ -640,7 +642,9 @@ export const addDelay: {
|
|
|
640
642
|
*
|
|
641
643
|
* @example
|
|
642
644
|
* ```ts
|
|
643
|
-
* import { Console, Duration, Effect, Schedule } from "effect"
|
|
645
|
+
* import { Console, Data, Duration, Effect, Schedule } from "effect"
|
|
646
|
+
*
|
|
647
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
644
648
|
*
|
|
645
649
|
* // Add random jitter to schedule delays
|
|
646
650
|
* const jitteredSchedule = Schedule.addDelay(
|
|
@@ -736,7 +740,7 @@ export const addDelay: {
|
|
|
736
740
|
* Effect.gen(function*() {
|
|
737
741
|
* attempt++
|
|
738
742
|
* if (attempt < 5) {
|
|
739
|
-
* return yield* Effect.fail(new
|
|
743
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
740
744
|
* }
|
|
741
745
|
* return `Success on attempt ${attempt}`
|
|
742
746
|
* }),
|
|
@@ -759,7 +763,9 @@ export const addDelay: {
|
|
|
759
763
|
*
|
|
760
764
|
* @example
|
|
761
765
|
* ```ts
|
|
762
|
-
* import { Console, Duration, Effect, Schedule } from "effect"
|
|
766
|
+
* import { Console, Data, Duration, Effect, Schedule } from "effect"
|
|
767
|
+
*
|
|
768
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
763
769
|
*
|
|
764
770
|
* // Add random jitter to schedule delays
|
|
765
771
|
* const jitteredSchedule = Schedule.addDelay(
|
|
@@ -855,7 +861,7 @@ export const addDelay: {
|
|
|
855
861
|
* Effect.gen(function*() {
|
|
856
862
|
* attempt++
|
|
857
863
|
* if (attempt < 5) {
|
|
858
|
-
* return yield* Effect.fail(new
|
|
864
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
859
865
|
* }
|
|
860
866
|
* return `Success on attempt ${attempt}`
|
|
861
867
|
* }),
|
|
@@ -890,7 +896,9 @@ export const addDelay: {
|
|
|
890
896
|
*
|
|
891
897
|
* @example
|
|
892
898
|
* ```ts
|
|
893
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
899
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
900
|
+
*
|
|
901
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
894
902
|
*
|
|
895
903
|
* // First retry 3 times quickly, then switch to slower retries
|
|
896
904
|
* const quickRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -909,7 +917,7 @@ export const addDelay: {
|
|
|
909
917
|
* attempt++
|
|
910
918
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
911
919
|
* if (attempt < 6) {
|
|
912
|
-
* return yield* Effect.fail(new
|
|
920
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Failure ${attempt}` }))
|
|
913
921
|
* }
|
|
914
922
|
* return `Success on attempt ${attempt}`
|
|
915
923
|
* }),
|
|
@@ -929,7 +937,9 @@ export const andThen: {
|
|
|
929
937
|
*
|
|
930
938
|
* @example
|
|
931
939
|
* ```ts
|
|
932
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
940
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
941
|
+
*
|
|
942
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
933
943
|
*
|
|
934
944
|
* // First retry 3 times quickly, then switch to slower retries
|
|
935
945
|
* const quickRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -948,7 +958,7 @@ export const andThen: {
|
|
|
948
958
|
* attempt++
|
|
949
959
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
950
960
|
* if (attempt < 6) {
|
|
951
|
-
* return yield* Effect.fail(new
|
|
961
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Failure ${attempt}` }))
|
|
952
962
|
* }
|
|
953
963
|
* return `Success on attempt ${attempt}`
|
|
954
964
|
* }),
|
|
@@ -970,7 +980,9 @@ export const andThen: {
|
|
|
970
980
|
*
|
|
971
981
|
* @example
|
|
972
982
|
* ```ts
|
|
973
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
983
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
984
|
+
*
|
|
985
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
974
986
|
*
|
|
975
987
|
* // First retry 3 times quickly, then switch to slower retries
|
|
976
988
|
* const quickRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -989,7 +1001,7 @@ export const andThen: {
|
|
|
989
1001
|
* attempt++
|
|
990
1002
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
991
1003
|
* if (attempt < 6) {
|
|
992
|
-
* return yield* Effect.fail(new
|
|
1004
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Failure ${attempt}` }))
|
|
993
1005
|
* }
|
|
994
1006
|
* return `Success on attempt ${attempt}`
|
|
995
1007
|
* }),
|
|
@@ -1355,7 +1367,9 @@ export const andThenResult: {
|
|
|
1355
1367
|
*
|
|
1356
1368
|
* @example
|
|
1357
1369
|
* ```ts
|
|
1358
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
1370
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
1371
|
+
*
|
|
1372
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
1359
1373
|
*
|
|
1360
1374
|
* // Both schedules must want to continue for the combined schedule to continue
|
|
1361
1375
|
* const timeLimit = Schedule.spaced("1 second").pipe(Schedule.take(5)) // max 5 times
|
|
@@ -1397,7 +1411,7 @@ export const andThenResult: {
|
|
|
1397
1411
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
1398
1412
|
*
|
|
1399
1413
|
* if (attempt < 3) {
|
|
1400
|
-
* return yield* Effect.fail(new
|
|
1414
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
1401
1415
|
* }
|
|
1402
1416
|
*
|
|
1403
1417
|
* return `Success on attempt ${attempt}`
|
|
@@ -1423,7 +1437,9 @@ export const both: {
|
|
|
1423
1437
|
*
|
|
1424
1438
|
* @example
|
|
1425
1439
|
* ```ts
|
|
1426
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
1440
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
1441
|
+
*
|
|
1442
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
1427
1443
|
*
|
|
1428
1444
|
* // Both schedules must want to continue for the combined schedule to continue
|
|
1429
1445
|
* const timeLimit = Schedule.spaced("1 second").pipe(Schedule.take(5)) // max 5 times
|
|
@@ -1465,7 +1481,7 @@ export const both: {
|
|
|
1465
1481
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
1466
1482
|
*
|
|
1467
1483
|
* if (attempt < 3) {
|
|
1468
|
-
* return yield* Effect.fail(new
|
|
1484
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
1469
1485
|
* }
|
|
1470
1486
|
*
|
|
1471
1487
|
* return `Success on attempt ${attempt}`
|
|
@@ -1493,7 +1509,9 @@ export const both: {
|
|
|
1493
1509
|
*
|
|
1494
1510
|
* @example
|
|
1495
1511
|
* ```ts
|
|
1496
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
1512
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
1513
|
+
*
|
|
1514
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
1497
1515
|
*
|
|
1498
1516
|
* // Both schedules must want to continue for the combined schedule to continue
|
|
1499
1517
|
* const timeLimit = Schedule.spaced("1 second").pipe(Schedule.take(5)) // max 5 times
|
|
@@ -1535,7 +1553,7 @@ export const both: {
|
|
|
1535
1553
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
1536
1554
|
*
|
|
1537
1555
|
* if (attempt < 3) {
|
|
1538
|
-
* return yield* Effect.fail(new
|
|
1556
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
1539
1557
|
* }
|
|
1540
1558
|
*
|
|
1541
1559
|
* return `Success on attempt ${attempt}`
|
|
@@ -1942,7 +1960,9 @@ export const bothWith: {
|
|
|
1942
1960
|
*
|
|
1943
1961
|
* @example
|
|
1944
1962
|
* ```ts
|
|
1945
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
1963
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
1964
|
+
*
|
|
1965
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
1946
1966
|
*
|
|
1947
1967
|
* // Compose a quick retry phase followed by slower retry phase
|
|
1948
1968
|
* const fastRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -1966,7 +1986,7 @@ export const bothWith: {
|
|
|
1966
1986
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
1967
1987
|
*
|
|
1968
1988
|
* if (attempt < 7) { // Needs both phases to succeed
|
|
1969
|
-
* return yield* Effect.fail(new
|
|
1989
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
1970
1990
|
* }
|
|
1971
1991
|
*
|
|
1972
1992
|
* return `Success on attempt ${attempt}`
|
|
@@ -2005,7 +2025,9 @@ export const compose: {
|
|
|
2005
2025
|
*
|
|
2006
2026
|
* @example
|
|
2007
2027
|
* ```ts
|
|
2008
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
2028
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
2029
|
+
*
|
|
2030
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
2009
2031
|
*
|
|
2010
2032
|
* // Compose a quick retry phase followed by slower retry phase
|
|
2011
2033
|
* const fastRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -2029,7 +2051,7 @@ export const compose: {
|
|
|
2029
2051
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
2030
2052
|
*
|
|
2031
2053
|
* if (attempt < 7) { // Needs both phases to succeed
|
|
2032
|
-
* return yield* Effect.fail(new
|
|
2054
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
2033
2055
|
* }
|
|
2034
2056
|
*
|
|
2035
2057
|
* return `Success on attempt ${attempt}`
|
|
@@ -2070,7 +2092,9 @@ export const compose: {
|
|
|
2070
2092
|
*
|
|
2071
2093
|
* @example
|
|
2072
2094
|
* ```ts
|
|
2073
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
2095
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
2096
|
+
*
|
|
2097
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
2074
2098
|
*
|
|
2075
2099
|
* // Compose a quick retry phase followed by slower retry phase
|
|
2076
2100
|
* const fastRetries = Schedule.exponential("100 millis").pipe(
|
|
@@ -2094,7 +2118,7 @@ export const compose: {
|
|
|
2094
2118
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
2095
2119
|
*
|
|
2096
2120
|
* if (attempt < 7) { // Needs both phases to succeed
|
|
2097
|
-
* return yield* Effect.fail(new
|
|
2121
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
2098
2122
|
* }
|
|
2099
2123
|
*
|
|
2100
2124
|
* return `Success on attempt ${attempt}`
|
|
@@ -2541,7 +2565,9 @@ export const collectWhile: {
|
|
|
2541
2565
|
*
|
|
2542
2566
|
* @example
|
|
2543
2567
|
* ```ts
|
|
2544
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
2568
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
2569
|
+
*
|
|
2570
|
+
* class ScheduledTaskError extends Data.TaggedError("ScheduledTaskError")<{ readonly message: string }> {}
|
|
2545
2571
|
*
|
|
2546
2572
|
* // Run every minute
|
|
2547
2573
|
* const everyMinute = Schedule.cron("* * * * *")
|
|
@@ -2642,7 +2668,7 @@ export const collectWhile: {
|
|
|
2642
2668
|
* yield* Console.log("Complex scheduled task...")
|
|
2643
2669
|
* // Simulate occasional failures
|
|
2644
2670
|
* if (Math.random() < 0.3) {
|
|
2645
|
-
* return yield* Effect.fail(new
|
|
2671
|
+
* return yield* Effect.fail(new ScheduledTaskError({ message: "Scheduled task failed" }))
|
|
2646
2672
|
* }
|
|
2647
2673
|
* return "success"
|
|
2648
2674
|
* }),
|
|
@@ -2665,7 +2691,9 @@ export const cron: {
|
|
|
2665
2691
|
*
|
|
2666
2692
|
* @example
|
|
2667
2693
|
* ```ts
|
|
2668
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
2694
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
2695
|
+
*
|
|
2696
|
+
* class ScheduledTaskError extends Data.TaggedError("ScheduledTaskError")<{ readonly message: string }> {}
|
|
2669
2697
|
*
|
|
2670
2698
|
* // Run every minute
|
|
2671
2699
|
* const everyMinute = Schedule.cron("* * * * *")
|
|
@@ -2766,7 +2794,7 @@ export const cron: {
|
|
|
2766
2794
|
* yield* Console.log("Complex scheduled task...")
|
|
2767
2795
|
* // Simulate occasional failures
|
|
2768
2796
|
* if (Math.random() < 0.3) {
|
|
2769
|
-
* return yield* Effect.fail(new
|
|
2797
|
+
* return yield* Effect.fail(new ScheduledTaskError({ message: "Scheduled task failed" }))
|
|
2770
2798
|
* }
|
|
2771
2799
|
* return "success"
|
|
2772
2800
|
* }),
|
|
@@ -2789,7 +2817,9 @@ export const cron: {
|
|
|
2789
2817
|
*
|
|
2790
2818
|
* @example
|
|
2791
2819
|
* ```ts
|
|
2792
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
2820
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
2821
|
+
*
|
|
2822
|
+
* class ScheduledTaskError extends Data.TaggedError("ScheduledTaskError")<{ readonly message: string }> {}
|
|
2793
2823
|
*
|
|
2794
2824
|
* // Run every minute
|
|
2795
2825
|
* const everyMinute = Schedule.cron("* * * * *")
|
|
@@ -2890,7 +2920,7 @@ export const cron: {
|
|
|
2890
2920
|
* yield* Console.log("Complex scheduled task...")
|
|
2891
2921
|
* // Simulate occasional failures
|
|
2892
2922
|
* if (Math.random() < 0.3) {
|
|
2893
|
-
* return yield* Effect.fail(new
|
|
2923
|
+
* return yield* Effect.fail(new ScheduledTaskError({ message: "Scheduled task failed" }))
|
|
2894
2924
|
* }
|
|
2895
2925
|
* return "success"
|
|
2896
2926
|
* }),
|
|
@@ -3036,7 +3066,9 @@ export const duration = (durationInput: Duration.Input): Schedule<Duration.Durat
|
|
|
3036
3066
|
*
|
|
3037
3067
|
* @example
|
|
3038
3068
|
* ```ts
|
|
3039
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3069
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3070
|
+
*
|
|
3071
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
3040
3072
|
*
|
|
3041
3073
|
* // Run a task for exactly 5 seconds, regardless of how many iterations
|
|
3042
3074
|
* const fiveSecondSchedule = Schedule.during("5 seconds")
|
|
@@ -3098,7 +3130,7 @@ export const duration = (durationInput: Duration.Input): Schedule<Duration.Durat
|
|
|
3098
3130
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
3099
3131
|
*
|
|
3100
3132
|
* if (Math.random() < 0.8) { // 80% failure rate
|
|
3101
|
-
* return yield* Effect.fail(new
|
|
3133
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
3102
3134
|
* }
|
|
3103
3135
|
*
|
|
3104
3136
|
* return `Success on attempt ${attempt}`
|
|
@@ -3128,7 +3160,9 @@ export const during = (duration: Duration.Input): Schedule<Duration.Duration> =>
|
|
|
3128
3160
|
*
|
|
3129
3161
|
* @example
|
|
3130
3162
|
* ```ts
|
|
3131
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3163
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3164
|
+
*
|
|
3165
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
3132
3166
|
*
|
|
3133
3167
|
* // Either continues as long as at least one schedule wants to continue
|
|
3134
3168
|
* const timeBasedSchedule = Schedule.spaced("2 seconds").pipe(Schedule.take(3))
|
|
@@ -3172,7 +3206,7 @@ export const during = (duration: Duration.Input): Schedule<Duration.Duration> =>
|
|
|
3172
3206
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
3173
3207
|
*
|
|
3174
3208
|
* if (attempt < 6) {
|
|
3175
|
-
* return yield* Effect.fail(new
|
|
3209
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
3176
3210
|
* }
|
|
3177
3211
|
*
|
|
3178
3212
|
* return `Success on attempt ${attempt}`
|
|
@@ -3198,7 +3232,9 @@ export const either: {
|
|
|
3198
3232
|
*
|
|
3199
3233
|
* @example
|
|
3200
3234
|
* ```ts
|
|
3201
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3235
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3236
|
+
*
|
|
3237
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
3202
3238
|
*
|
|
3203
3239
|
* // Either continues as long as at least one schedule wants to continue
|
|
3204
3240
|
* const timeBasedSchedule = Schedule.spaced("2 seconds").pipe(Schedule.take(3))
|
|
@@ -3242,7 +3278,7 @@ export const either: {
|
|
|
3242
3278
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
3243
3279
|
*
|
|
3244
3280
|
* if (attempt < 6) {
|
|
3245
|
-
* return yield* Effect.fail(new
|
|
3281
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
3246
3282
|
* }
|
|
3247
3283
|
*
|
|
3248
3284
|
* return `Success on attempt ${attempt}`
|
|
@@ -3270,7 +3306,9 @@ export const either: {
|
|
|
3270
3306
|
*
|
|
3271
3307
|
* @example
|
|
3272
3308
|
* ```ts
|
|
3273
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3309
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3310
|
+
*
|
|
3311
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
3274
3312
|
*
|
|
3275
3313
|
* // Either continues as long as at least one schedule wants to continue
|
|
3276
3314
|
* const timeBasedSchedule = Schedule.spaced("2 seconds").pipe(Schedule.take(3))
|
|
@@ -3314,7 +3352,7 @@ export const either: {
|
|
|
3314
3352
|
* yield* Console.log(`Retry attempt ${attempt}`)
|
|
3315
3353
|
*
|
|
3316
3354
|
* if (attempt < 6) {
|
|
3317
|
-
* return yield* Effect.fail(new
|
|
3355
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
3318
3356
|
* }
|
|
3319
3357
|
*
|
|
3320
3358
|
* return `Success on attempt ${attempt}`
|
|
@@ -3818,7 +3856,9 @@ export const elapsed: Schedule<Duration.Duration> = fromStepWithMetadata(
|
|
|
3818
3856
|
*
|
|
3819
3857
|
* @example
|
|
3820
3858
|
* ```ts
|
|
3821
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3859
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3860
|
+
*
|
|
3861
|
+
* class RetryFailure extends Data.TaggedError("RetryFailure")<{ readonly message: string }> {}
|
|
3822
3862
|
*
|
|
3823
3863
|
* // Basic exponential backoff with default factor of 2
|
|
3824
3864
|
* const basicExponential = Schedule.exponential("100 millis")
|
|
@@ -3841,7 +3881,7 @@ export const elapsed: Schedule<Duration.Duration> = fromStepWithMetadata(
|
|
|
3841
3881
|
* attempt++
|
|
3842
3882
|
* if (attempt < 4) {
|
|
3843
3883
|
* yield* Console.log(`Attempt ${attempt} failed, retrying...`)
|
|
3844
|
-
* return yield* Effect.fail(new
|
|
3884
|
+
* return yield* Effect.fail(new RetryFailure({ message: `Failure ${attempt}` }))
|
|
3845
3885
|
* }
|
|
3846
3886
|
* return `Success on attempt ${attempt}`
|
|
3847
3887
|
* }),
|
|
@@ -3875,7 +3915,9 @@ export const exponential = (
|
|
|
3875
3915
|
*
|
|
3876
3916
|
* @example
|
|
3877
3917
|
* ```ts
|
|
3878
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
3918
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
3919
|
+
*
|
|
3920
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
3879
3921
|
*
|
|
3880
3922
|
* // Basic fibonacci schedule starting with 100ms
|
|
3881
3923
|
* const fibSchedule = Schedule.fibonacci("100 millis")
|
|
@@ -3891,7 +3933,7 @@ export const exponential = (
|
|
|
3891
3933
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
3892
3934
|
*
|
|
3893
3935
|
* if (attempt < 5) {
|
|
3894
|
-
* return yield* Effect.fail(new
|
|
3936
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
3895
3937
|
* }
|
|
3896
3938
|
*
|
|
3897
3939
|
* return `Success on attempt ${attempt}`
|
|
@@ -4421,7 +4463,9 @@ export const passthrough = <Output, Input, Error, Env>(
|
|
|
4421
4463
|
*
|
|
4422
4464
|
* @example
|
|
4423
4465
|
* ```ts
|
|
4424
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
4466
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
4467
|
+
*
|
|
4468
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
4425
4469
|
*
|
|
4426
4470
|
* // Basic recurs - retry at most 3 times
|
|
4427
4471
|
* const maxThreeAttempts = Schedule.recurs(3)
|
|
@@ -4436,7 +4480,7 @@ export const passthrough = <Output, Input, Error, Env>(
|
|
|
4436
4480
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
4437
4481
|
*
|
|
4438
4482
|
* if (attempt < 4) {
|
|
4439
|
-
* return yield* Effect.fail(new
|
|
4483
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
4440
4484
|
* }
|
|
4441
4485
|
*
|
|
4442
4486
|
* return `Success on attempt ${attempt}`
|
|
@@ -4906,12 +4950,14 @@ export const spaced = (duration: Duration.Input): Schedule<number> => {
|
|
|
4906
4950
|
*
|
|
4907
4951
|
* @example
|
|
4908
4952
|
* ```ts
|
|
4909
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
4953
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
4954
|
+
*
|
|
4955
|
+
* class RetryError extends Data.TaggedError("RetryError")<{ readonly message: string }> {}
|
|
4910
4956
|
*
|
|
4911
4957
|
* // Log retry errors for debugging
|
|
4912
4958
|
* const errorLoggingSchedule = Schedule.exponential("100 millis").pipe(
|
|
4913
4959
|
* Schedule.take(3),
|
|
4914
|
-
* Schedule.tapInput((error:
|
|
4960
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
4915
4961
|
* Console.log(`Retry triggered by error: ${String(error)}`)
|
|
4916
4962
|
* )
|
|
4917
4963
|
* )
|
|
@@ -4923,7 +4969,7 @@ export const spaced = (duration: Duration.Input): Schedule<number> => {
|
|
|
4923
4969
|
* Effect.gen(function*() {
|
|
4924
4970
|
* attempt++
|
|
4925
4971
|
* if (attempt < 4) {
|
|
4926
|
-
* return yield* Effect.fail(new
|
|
4972
|
+
* return yield* Effect.fail(new RetryError({ message: `Network timeout on attempt ${attempt}` }))
|
|
4927
4973
|
* }
|
|
4928
4974
|
* return `Success on attempt ${attempt}`
|
|
4929
4975
|
* }),
|
|
@@ -4972,7 +5018,7 @@ export const spaced = (duration: Duration.Input): Schedule<number> => {
|
|
|
4972
5018
|
* // Conditional alerting based on input
|
|
4973
5019
|
* const alertingSchedule = Schedule.exponential("200 millis").pipe(
|
|
4974
5020
|
* Schedule.take(6),
|
|
4975
|
-
* Schedule.tapInput((error:
|
|
5021
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
4976
5022
|
* Effect.gen(function*() {
|
|
4977
5023
|
* if (String(error).includes("critical")) {
|
|
4978
5024
|
* yield* Console.log(`🚨 CRITICAL ERROR: ${String(error)}`)
|
|
@@ -4994,7 +5040,7 @@ export const spaced = (duration: Duration.Input): Schedule<number> => {
|
|
|
4994
5040
|
* const errorType = isCritical
|
|
4995
5041
|
* ? "critical database failure"
|
|
4996
5042
|
* : "temporary network issue"
|
|
4997
|
-
* return yield* Effect.fail(new
|
|
5043
|
+
* return yield* Effect.fail(new RetryError({ message: errorType }))
|
|
4998
5044
|
* }),
|
|
4999
5045
|
* alertingSchedule
|
|
5000
5046
|
* ).pipe(
|
|
@@ -5007,10 +5053,10 @@ export const spaced = (duration: Duration.Input): Schedule<number> => {
|
|
|
5007
5053
|
* // Chain multiple input taps for different purposes
|
|
5008
5054
|
* const comprehensiveSchedule = Schedule.fibonacci("100 millis").pipe(
|
|
5009
5055
|
* Schedule.take(5),
|
|
5010
|
-
* Schedule.tapInput((error:
|
|
5011
|
-
* Console.log(`Error occurred: ${error.
|
|
5056
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5057
|
+
* Console.log(`Error occurred: ${error._tag}`)
|
|
5012
5058
|
* ),
|
|
5013
|
-
* Schedule.tapInput((error:
|
|
5059
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5014
5060
|
* String(error).length > 20
|
|
5015
5061
|
* ? Console.log("📝 Long error message detected")
|
|
5016
5062
|
* : Effect.void
|
|
@@ -5029,12 +5075,14 @@ export const tapInput: {
|
|
|
5029
5075
|
*
|
|
5030
5076
|
* @example
|
|
5031
5077
|
* ```ts
|
|
5032
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5078
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5079
|
+
*
|
|
5080
|
+
* class RetryError extends Data.TaggedError("RetryError")<{ readonly message: string }> {}
|
|
5033
5081
|
*
|
|
5034
5082
|
* // Log retry errors for debugging
|
|
5035
5083
|
* const errorLoggingSchedule = Schedule.exponential("100 millis").pipe(
|
|
5036
5084
|
* Schedule.take(3),
|
|
5037
|
-
* Schedule.tapInput((error:
|
|
5085
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5038
5086
|
* Console.log(`Retry triggered by error: ${String(error)}`)
|
|
5039
5087
|
* )
|
|
5040
5088
|
* )
|
|
@@ -5046,7 +5094,7 @@ export const tapInput: {
|
|
|
5046
5094
|
* Effect.gen(function*() {
|
|
5047
5095
|
* attempt++
|
|
5048
5096
|
* if (attempt < 4) {
|
|
5049
|
-
* return yield* Effect.fail(new
|
|
5097
|
+
* return yield* Effect.fail(new RetryError({ message: `Network timeout on attempt ${attempt}` }))
|
|
5050
5098
|
* }
|
|
5051
5099
|
* return `Success on attempt ${attempt}`
|
|
5052
5100
|
* }),
|
|
@@ -5095,7 +5143,7 @@ export const tapInput: {
|
|
|
5095
5143
|
* // Conditional alerting based on input
|
|
5096
5144
|
* const alertingSchedule = Schedule.exponential("200 millis").pipe(
|
|
5097
5145
|
* Schedule.take(6),
|
|
5098
|
-
* Schedule.tapInput((error:
|
|
5146
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5099
5147
|
* Effect.gen(function*() {
|
|
5100
5148
|
* if (String(error).includes("critical")) {
|
|
5101
5149
|
* yield* Console.log(`🚨 CRITICAL ERROR: ${String(error)}`)
|
|
@@ -5117,7 +5165,7 @@ export const tapInput: {
|
|
|
5117
5165
|
* const errorType = isCritical
|
|
5118
5166
|
* ? "critical database failure"
|
|
5119
5167
|
* : "temporary network issue"
|
|
5120
|
-
* return yield* Effect.fail(new
|
|
5168
|
+
* return yield* Effect.fail(new RetryError({ message: errorType }))
|
|
5121
5169
|
* }),
|
|
5122
5170
|
* alertingSchedule
|
|
5123
5171
|
* ).pipe(
|
|
@@ -5130,10 +5178,10 @@ export const tapInput: {
|
|
|
5130
5178
|
* // Chain multiple input taps for different purposes
|
|
5131
5179
|
* const comprehensiveSchedule = Schedule.fibonacci("100 millis").pipe(
|
|
5132
5180
|
* Schedule.take(5),
|
|
5133
|
-
* Schedule.tapInput((error:
|
|
5134
|
-
* Console.log(`Error occurred: ${error.
|
|
5181
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5182
|
+
* Console.log(`Error occurred: ${error._tag}`)
|
|
5135
5183
|
* ),
|
|
5136
|
-
* Schedule.tapInput((error:
|
|
5184
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5137
5185
|
* String(error).length > 20
|
|
5138
5186
|
* ? Console.log("📝 Long error message detected")
|
|
5139
5187
|
* : Effect.void
|
|
@@ -5154,12 +5202,14 @@ export const tapInput: {
|
|
|
5154
5202
|
*
|
|
5155
5203
|
* @example
|
|
5156
5204
|
* ```ts
|
|
5157
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5205
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5206
|
+
*
|
|
5207
|
+
* class RetryError extends Data.TaggedError("RetryError")<{ readonly message: string }> {}
|
|
5158
5208
|
*
|
|
5159
5209
|
* // Log retry errors for debugging
|
|
5160
5210
|
* const errorLoggingSchedule = Schedule.exponential("100 millis").pipe(
|
|
5161
5211
|
* Schedule.take(3),
|
|
5162
|
-
* Schedule.tapInput((error:
|
|
5212
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5163
5213
|
* Console.log(`Retry triggered by error: ${String(error)}`)
|
|
5164
5214
|
* )
|
|
5165
5215
|
* )
|
|
@@ -5171,7 +5221,7 @@ export const tapInput: {
|
|
|
5171
5221
|
* Effect.gen(function*() {
|
|
5172
5222
|
* attempt++
|
|
5173
5223
|
* if (attempt < 4) {
|
|
5174
|
-
* return yield* Effect.fail(new
|
|
5224
|
+
* return yield* Effect.fail(new RetryError({ message: `Network timeout on attempt ${attempt}` }))
|
|
5175
5225
|
* }
|
|
5176
5226
|
* return `Success on attempt ${attempt}`
|
|
5177
5227
|
* }),
|
|
@@ -5220,7 +5270,7 @@ export const tapInput: {
|
|
|
5220
5270
|
* // Conditional alerting based on input
|
|
5221
5271
|
* const alertingSchedule = Schedule.exponential("200 millis").pipe(
|
|
5222
5272
|
* Schedule.take(6),
|
|
5223
|
-
* Schedule.tapInput((error:
|
|
5273
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5224
5274
|
* Effect.gen(function*() {
|
|
5225
5275
|
* if (String(error).includes("critical")) {
|
|
5226
5276
|
* yield* Console.log(`🚨 CRITICAL ERROR: ${String(error)}`)
|
|
@@ -5242,7 +5292,7 @@ export const tapInput: {
|
|
|
5242
5292
|
* const errorType = isCritical
|
|
5243
5293
|
* ? "critical database failure"
|
|
5244
5294
|
* : "temporary network issue"
|
|
5245
|
-
* return yield* Effect.fail(new
|
|
5295
|
+
* return yield* Effect.fail(new RetryError({ message: errorType }))
|
|
5246
5296
|
* }),
|
|
5247
5297
|
* alertingSchedule
|
|
5248
5298
|
* ).pipe(
|
|
@@ -5255,10 +5305,10 @@ export const tapInput: {
|
|
|
5255
5305
|
* // Chain multiple input taps for different purposes
|
|
5256
5306
|
* const comprehensiveSchedule = Schedule.fibonacci("100 millis").pipe(
|
|
5257
5307
|
* Schedule.take(5),
|
|
5258
|
-
* Schedule.tapInput((error:
|
|
5259
|
-
* Console.log(`Error occurred: ${error.
|
|
5308
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5309
|
+
* Console.log(`Error occurred: ${error._tag}`)
|
|
5260
5310
|
* ),
|
|
5261
|
-
* Schedule.tapInput((error:
|
|
5311
|
+
* Schedule.tapInput((error: RetryError) =>
|
|
5262
5312
|
* String(error).length > 20
|
|
5263
5313
|
* ? Console.log("📝 Long error message detected")
|
|
5264
5314
|
* : Effect.void
|
|
@@ -5289,7 +5339,9 @@ export const tapInput: {
|
|
|
5289
5339
|
*
|
|
5290
5340
|
* @example
|
|
5291
5341
|
* ```ts
|
|
5292
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5342
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5343
|
+
*
|
|
5344
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5293
5345
|
*
|
|
5294
5346
|
* // Log schedule outputs for debugging/monitoring
|
|
5295
5347
|
* const monitoredSchedule = Schedule.exponential("100 millis").pipe(
|
|
@@ -5304,7 +5356,7 @@ export const tapInput: {
|
|
|
5304
5356
|
* Effect.gen(function*() {
|
|
5305
5357
|
* attempt++
|
|
5306
5358
|
* if (attempt < 4) {
|
|
5307
|
-
* return yield* Effect.fail(new
|
|
5359
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5308
5360
|
* }
|
|
5309
5361
|
* return `Success on attempt ${attempt}`
|
|
5310
5362
|
* }),
|
|
@@ -5373,7 +5425,9 @@ export const tapOutput: {
|
|
|
5373
5425
|
*
|
|
5374
5426
|
* @example
|
|
5375
5427
|
* ```ts
|
|
5376
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5428
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5429
|
+
*
|
|
5430
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5377
5431
|
*
|
|
5378
5432
|
* // Log schedule outputs for debugging/monitoring
|
|
5379
5433
|
* const monitoredSchedule = Schedule.exponential("100 millis").pipe(
|
|
@@ -5388,7 +5442,7 @@ export const tapOutput: {
|
|
|
5388
5442
|
* Effect.gen(function*() {
|
|
5389
5443
|
* attempt++
|
|
5390
5444
|
* if (attempt < 4) {
|
|
5391
|
-
* return yield* Effect.fail(new
|
|
5445
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5392
5446
|
* }
|
|
5393
5447
|
* return `Success on attempt ${attempt}`
|
|
5394
5448
|
* }),
|
|
@@ -5459,7 +5513,9 @@ export const tapOutput: {
|
|
|
5459
5513
|
*
|
|
5460
5514
|
* @example
|
|
5461
5515
|
* ```ts
|
|
5462
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5516
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5517
|
+
*
|
|
5518
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5463
5519
|
*
|
|
5464
5520
|
* // Log schedule outputs for debugging/monitoring
|
|
5465
5521
|
* const monitoredSchedule = Schedule.exponential("100 millis").pipe(
|
|
@@ -5474,7 +5530,7 @@ export const tapOutput: {
|
|
|
5474
5530
|
* Effect.gen(function*() {
|
|
5475
5531
|
* attempt++
|
|
5476
5532
|
* if (attempt < 4) {
|
|
5477
|
-
* return yield* Effect.fail(new
|
|
5533
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5478
5534
|
* }
|
|
5479
5535
|
* return `Success on attempt ${attempt}`
|
|
5480
5536
|
* }),
|
|
@@ -5555,7 +5611,9 @@ export const tapOutput: {
|
|
|
5555
5611
|
*
|
|
5556
5612
|
* @example
|
|
5557
5613
|
* ```ts
|
|
5558
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5614
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5615
|
+
*
|
|
5616
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5559
5617
|
*
|
|
5560
5618
|
* // Limit an infinite schedule to run only 5 times
|
|
5561
5619
|
* const limitedHeartbeat = Schedule.spaced("1 second").pipe(
|
|
@@ -5588,7 +5646,7 @@ export const tapOutput: {
|
|
|
5588
5646
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
5589
5647
|
*
|
|
5590
5648
|
* if (attempt < 5) { // Will fail more than 3 times
|
|
5591
|
-
* return yield* Effect.fail(new
|
|
5649
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5592
5650
|
* }
|
|
5593
5651
|
*
|
|
5594
5652
|
* return `Success on attempt ${attempt}`
|
|
@@ -5634,7 +5692,9 @@ export const take: {
|
|
|
5634
5692
|
*
|
|
5635
5693
|
* @example
|
|
5636
5694
|
* ```ts
|
|
5637
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5695
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5696
|
+
*
|
|
5697
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5638
5698
|
*
|
|
5639
5699
|
* // Limit an infinite schedule to run only 5 times
|
|
5640
5700
|
* const limitedHeartbeat = Schedule.spaced("1 second").pipe(
|
|
@@ -5667,7 +5727,7 @@ export const take: {
|
|
|
5667
5727
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
5668
5728
|
*
|
|
5669
5729
|
* if (attempt < 5) { // Will fail more than 3 times
|
|
5670
|
-
* return yield* Effect.fail(new
|
|
5730
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5671
5731
|
* }
|
|
5672
5732
|
*
|
|
5673
5733
|
* return `Success on attempt ${attempt}`
|
|
@@ -5715,7 +5775,9 @@ export const take: {
|
|
|
5715
5775
|
*
|
|
5716
5776
|
* @example
|
|
5717
5777
|
* ```ts
|
|
5718
|
-
* import { Console, Effect, Schedule } from "effect"
|
|
5778
|
+
* import { Console, Data, Effect, Schedule } from "effect"
|
|
5779
|
+
*
|
|
5780
|
+
* class RetryAttemptError extends Data.TaggedError("RetryAttemptError")<{ readonly message: string }> {}
|
|
5719
5781
|
*
|
|
5720
5782
|
* // Limit an infinite schedule to run only 5 times
|
|
5721
5783
|
* const limitedHeartbeat = Schedule.spaced("1 second").pipe(
|
|
@@ -5748,7 +5810,7 @@ export const take: {
|
|
|
5748
5810
|
* yield* Console.log(`Attempt ${attempt}`)
|
|
5749
5811
|
*
|
|
5750
5812
|
* if (attempt < 5) { // Will fail more than 3 times
|
|
5751
|
-
* return yield* Effect.fail(new
|
|
5813
|
+
* return yield* Effect.fail(new RetryAttemptError({ message: `Attempt ${attempt} failed` }))
|
|
5752
5814
|
* }
|
|
5753
5815
|
*
|
|
5754
5816
|
* return `Success on attempt ${attempt}`
|