effect 2.0.5 → 2.1.0

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.
@@ -1192,27 +1192,51 @@ export declare const parallelErrors: <R, E, A>(self: Effect<R, E, A>) => Effect<
1192
1192
  */
1193
1193
  export declare const sandbox: <R, E, A>(self: Effect<R, E, A>) => Effect<R, Cause.Cause<E>, A>;
1194
1194
  /**
1195
- * Retries with the specified retry policy. Retries are done following the
1196
- * failure of the original `io` (up to a fixed maximum with `once` or `recurs`
1197
- * for example), so that that `io.retry(Schedule.once)` means "execute `io`
1198
- * and in case of failure, try again once".
1199
- *
1200
1195
  * @since 2.0.0
1201
1196
  * @category error handling
1202
1197
  */
1203
- export declare const retry: {
1204
- <R1, E extends E0, E0, B>(policy: Schedule.Schedule<R1, E0, B>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E, A>;
1205
- <R, E extends E0, E0, A, R1, B>(self: Effect<R, E, A>, policy: Schedule.Schedule<R1, E0, B>): Effect<R | R1, E, A>;
1206
- };
1198
+ export declare namespace Retry {
1199
+ /**
1200
+ * @since 2.0.0
1201
+ * @category error handling
1202
+ */
1203
+ type Return<R, E, A, O extends Options<E>> = Effect<R | (O extends {
1204
+ schedule: Schedule.Schedule<infer X, infer _I, infer _O>;
1205
+ } ? X : never) | (O extends {
1206
+ while: (...args: Array<any>) => Effect<infer X, infer _E, infer _A>;
1207
+ } ? X : never) | (O extends {
1208
+ until: (...args: Array<any>) => Effect<infer X, infer _E, infer _A>;
1209
+ } ? X : never), (O extends {
1210
+ schedule: Schedule.Schedule<infer _R, infer _I, infer _O>;
1211
+ } ? E : O extends {
1212
+ until: Refinement<E, infer E2>;
1213
+ } ? E2 : E) | (O extends {
1214
+ while: (...args: Array<any>) => Effect<infer _R, infer X, infer _A>;
1215
+ } ? X : never) | (O extends {
1216
+ until: (...args: Array<any>) => Effect<infer _R, infer X, infer _A>;
1217
+ } ? X : never), A> extends infer Z ? Z : never;
1218
+ /**
1219
+ * @since 2.0.0
1220
+ * @category error handling
1221
+ */
1222
+ interface Options<E> {
1223
+ while?: (error: E) => boolean | Effect<any, any, boolean>;
1224
+ until?: (error: E) => boolean | Effect<any, any, boolean>;
1225
+ times?: number;
1226
+ schedule?: Schedule.Schedule<any, E, any>;
1227
+ }
1228
+ }
1207
1229
  /**
1208
- * Retries this effect the specified number of times.
1230
+ * Retries according to the options provided
1209
1231
  *
1210
1232
  * @since 2.0.0
1211
1233
  * @category error handling
1212
1234
  */
1213
- export declare const retryN: {
1214
- (n: number): <R, E, A>(self: Effect<R, E, A>) => Effect<R, E, A>;
1215
- <R, E, A>(self: Effect<R, E, A>, n: number): Effect<R, E, A>;
1235
+ export declare const retry: {
1236
+ <E, O extends Retry.Options<E>>(options: O): <R, A>(self: Effect<R, E, A>) => Retry.Return<R, E, A, O>;
1237
+ <R1, E extends E0, E0, B>(policy: Schedule.Schedule<R1, E0, B>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E, A>;
1238
+ <R, A, E, O extends Retry.Options<E>>(self: Effect<R, E, A>, options: O): Retry.Return<R, E, A, O>;
1239
+ <R, E extends E0, E0, A, R1, B>(self: Effect<R, E, A>, policy: Schedule.Schedule<R1, E0, B>): Effect<R | R1, E, A>;
1216
1240
  };
1217
1241
  /**
1218
1242
  * Retries with the specified schedule, until it fails, and then both the
@@ -1226,50 +1250,6 @@ export declare const retryOrElse: {
1226
1250
  <R1, E extends E3, A1, R2, E2, A2, E3>(policy: Schedule.Schedule<R1, E3, A1>, orElse: (e: E, out: A1) => Effect<R2, E2, A2>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R2 | R, E | E2, A2 | A>;
1227
1251
  <R, E extends E3, A, R1, A1, R2, E2, A2, E3>(self: Effect<R, E, A>, policy: Schedule.Schedule<R1, E3, A1>, orElse: (e: E, out: A1) => Effect<R2, E2, A2>): Effect<R | R1 | R2, E | E2, A | A2>;
1228
1252
  };
1229
- /**
1230
- * Retries this effect until its error satisfies the specified predicate.
1231
- *
1232
- * @since 2.0.0
1233
- * @category error handling
1234
- */
1235
- export declare const retryUntil: {
1236
- <E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect<R, E, A>) => Effect<R, E2, A>;
1237
- <E>(f: Predicate<E>): <R, A>(self: Effect<R, E, A>) => Effect<R, E, A>;
1238
- <R, E, A, E2 extends E>(self: Effect<R, E, A>, f: Refinement<E, E2>): Effect<R, E2, A>;
1239
- <R, E, A>(self: Effect<R, E, A>, f: Predicate<E>): Effect<R, E, A>;
1240
- };
1241
- /**
1242
- * Retries this effect until its error satisfies the specified effectful
1243
- * predicate.
1244
- *
1245
- * @since 2.0.0
1246
- * @category error handling
1247
- */
1248
- export declare const retryUntilEffect: {
1249
- <R1, E, E2>(f: (e: E) => Effect<R1, E2, boolean>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E | E2, A>;
1250
- <R, E, A, R1, E2>(self: Effect<R, E, A>, f: (e: E) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>;
1251
- };
1252
- /**
1253
- * Retries this effect while its error satisfies the specified predicate.
1254
- *
1255
- * @since 2.0.0
1256
- * @category error handling
1257
- */
1258
- export declare const retryWhile: {
1259
- <E>(f: Predicate<E>): <R, A>(self: Effect<R, E, A>) => Effect<R, E, A>;
1260
- <R, E, A>(self: Effect<R, E, A>, f: Predicate<E>): Effect<R, E, A>;
1261
- };
1262
- /**
1263
- * Retries this effect while its error satisfies the specified effectful
1264
- * predicate.
1265
- *
1266
- * @since 2.0.0
1267
- * @category error handling
1268
- */
1269
- export declare const retryWhileEffect: {
1270
- <R1, E, E2>(f: (e: E) => Effect<R1, E2, boolean>): <R, A>(self: Effect<R, E, A>) => Effect<R1 | R, E | E2, A>;
1271
- <R, E, A, R1, E2>(self: Effect<R, E, A>, f: (e: E) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>;
1272
- };
1273
1253
  declare const try_: {
1274
1254
  <A, E>(options: {
1275
1255
  readonly try: LazyArg<A>;
@@ -2901,6 +2881,41 @@ export declare const loop: {
2901
2881
  readonly discard: true;
2902
2882
  }): Effect<R, E, void>;
2903
2883
  };
2884
+ /**
2885
+ * @since 2.0.0
2886
+ * @category repetition / recursion
2887
+ */
2888
+ export declare namespace Repeat {
2889
+ /**
2890
+ * @since 2.0.0
2891
+ * @category repetition / recursion
2892
+ */
2893
+ type Return<R, E, A, O extends Options<A>> = Effect<R | (O extends {
2894
+ schedule: Schedule.Schedule<infer X, infer _I, infer _O>;
2895
+ } ? X : never) | (O extends {
2896
+ while: (...args: Array<any>) => Effect<infer X, infer _E, infer _A>;
2897
+ } ? X : never) | (O extends {
2898
+ until: (...args: Array<any>) => Effect<infer X, infer _E, infer _A>;
2899
+ } ? X : never), E | (O extends {
2900
+ while: (...args: Array<any>) => Effect<infer _R, infer X, infer _A>;
2901
+ } ? X : never) | (O extends {
2902
+ until: (...args: Array<any>) => Effect<infer _R, infer X, infer _A>;
2903
+ } ? X : never), (O extends {
2904
+ schedule: Schedule.Schedule<infer _R, infer _I, infer Out>;
2905
+ } ? Out : O extends {
2906
+ until: Refinement<A, infer B>;
2907
+ } ? B : A)> extends infer Z ? Z : never;
2908
+ /**
2909
+ * @since 2.0.0
2910
+ * @category repetition / recursion
2911
+ */
2912
+ interface Options<A> {
2913
+ while?: (_: A) => boolean | Effect<any, any, boolean>;
2914
+ until?: (_: A) => boolean | Effect<any, any, boolean>;
2915
+ times?: number;
2916
+ schedule?: Schedule.Schedule<any, A, any>;
2917
+ }
2918
+ }
2904
2919
  /**
2905
2920
  * Returns a new effect that repeats this effect according to the specified
2906
2921
  * schedule or until the first failure. Scheduled recurrences are in addition
@@ -2912,7 +2927,9 @@ export declare const loop: {
2912
2927
  * @category repetition / recursion
2913
2928
  */
2914
2929
  export declare const repeat: {
2930
+ <A, O extends Repeat.Options<A>>(options: O): <R, E>(self: Effect<R, E, A>) => Repeat.Return<R, E, A, O>;
2915
2931
  <R1, A extends A0, A0, B>(schedule: Schedule.Schedule<R1, A, B>): <R, E>(self: Effect<R, E, A>) => Effect<R1 | R, E, B>;
2932
+ <R, E, A, O extends Repeat.Options<A>>(self: Effect<R, E, A>, options: O): Repeat.Return<R, E, A, O>;
2916
2933
  <R, E, A extends A0, A0, R1, B>(self: Effect<R, E, A>, schedule: Schedule.Schedule<R1, A0, B>): Effect<R | R1, E, B>;
2917
2934
  };
2918
2935
  /**
@@ -2944,52 +2961,6 @@ export declare const repeatOrElse: {
2944
2961
  <R2, A extends A0, A0, B, E, R3, E2>(schedule: Schedule.Schedule<R2, A, B>, orElse: (error: E, option: Option.Option<B>) => Effect<R3, E2, B>): <R>(self: Effect<R, E, A>) => Effect<R2 | R3 | R, E2, B>;
2945
2962
  <R, E, A extends A0, A0, R2, B, R3, E2>(self: Effect<R, E, A>, schedule: Schedule.Schedule<R2, A0, B>, orElse: (error: E, option: Option.Option<B>) => Effect<R3, E2, B>): Effect<R | R2 | R3, E2, B>;
2946
2963
  };
2947
- /**
2948
- * Repeats this effect until its value satisfies the specified predicate or
2949
- * until the first failure.
2950
- *
2951
- * @since 2.0.0
2952
- * @category repetition / recursion
2953
- */
2954
- export declare const repeatUntil: {
2955
- <A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, B>;
2956
- <A>(f: Predicate<A>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, A>;
2957
- <R, E, A, B extends A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, B>;
2958
- <R, E, A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, A>;
2959
- };
2960
- /**
2961
- * Repeats this effect until its value satisfies the specified effectful
2962
- * predicate or until the first failure.
2963
- *
2964
- * @since 2.0.0
2965
- * @category repetition / recursion
2966
- */
2967
- export declare const repeatUntilEffect: {
2968
- <A, R2, E2>(f: (a: A) => Effect<R2, E2, boolean>): <R, E>(self: Effect<R, E, A>) => Effect<R2 | R, E2 | E, A>;
2969
- <R, E, A, R2, E2>(self: Effect<R, E, A>, f: (a: A) => Effect<R2, E2, boolean>): Effect<R | R2, E | E2, A>;
2970
- };
2971
- /**
2972
- * Repeats this effect while its value satisfies the specified effectful
2973
- * predicate or until the first failure.
2974
- *
2975
- * @since 2.0.0
2976
- * @category repetition / recursion
2977
- */
2978
- export declare const repeatWhile: {
2979
- <A>(f: Predicate<A>): <R, E>(self: Effect<R, E, A>) => Effect<R, E, A>;
2980
- <R, E, A>(self: Effect<R, E, A>, f: Predicate<A>): Effect<R, E, A>;
2981
- };
2982
- /**
2983
- * Repeats this effect while its value satisfies the specified effectful
2984
- * predicate or until the first failure.
2985
- *
2986
- * @since 2.0.0
2987
- * @category repetition / recursion
2988
- */
2989
- export declare const repeatWhileEffect: {
2990
- <R1, A, E2>(f: (a: A) => Effect<R1, E2, boolean>): <R, E>(self: Effect<R, E, A>) => Effect<R1 | R, E2 | E, A>;
2991
- <R, E, R1, A, E2>(self: Effect<R, E, A>, f: (a: A) => Effect<R1, E2, boolean>): Effect<R | R1, E | E2, A>;
2992
- };
2993
2964
  /**
2994
2965
  * Runs this effect according to the specified schedule.
2995
2966
  *
@@ -3470,12 +3441,12 @@ export declare const makeSemaphore: (permits: number) => Effect<never, never, Se
3470
3441
  * @since 2.0.0
3471
3442
  * @category execution
3472
3443
  */
3473
- export declare const runFork: <E, A>(effect: Effect<never, E, A>) => Fiber.RuntimeFiber<E, A>;
3444
+ export declare const runFork: <E, A>(effect: Effect<never, E, A>, options?: Runtime.RunForkOptions) => Fiber.RuntimeFiber<E, A>;
3474
3445
  /**
3475
3446
  * @since 2.0.0
3476
3447
  * @category execution
3477
3448
  */
3478
- export declare const runCallback: <E, A>(effect: Effect<never, E, A>, onExit?: (exit: Exit.Exit<E, A>) => void) => Runtime.Cancel<E, A>;
3449
+ export declare const runCallback: <E, A>(effect: Effect<never, E, A>, options?: Runtime.RunCallbackOptions<E, A> | undefined) => Runtime.Cancel<E, A>;
3479
3450
  /**
3480
3451
  * Runs an `Effect` workflow, returning a `Promise` which resolves with the
3481
3452
  * result of the workflow or rejects with an error.