mini-effect 0.0.4 → 0.0.5
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/mini-effect.d.mts +2 -1
- package/dist/mini-effect.mjs +5 -1
- package/package.json +1 -1
package/dist/mini-effect.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ declare const succeed: <R$1>(result: R$1) => Effect<R$1, never>;
|
|
|
10
10
|
declare const catchSome: <T = any, C = any, CE = any>(thunk: (cause: unknown) => Effect<T, C> | undefined) => WrapEffect<T, C, CE>;
|
|
11
11
|
declare const gen: <T extends Effect<any, any>, TReturn, TNext>(thunk: (signal: AbortSignal) => Generator<T, TReturn, TNext>) => Effect<TReturn, inferError<T>>;
|
|
12
12
|
declare const pipe: <F extends Effect, P$1 extends [Pipeable, ...Pipeable[]]>(first: F, ...pipeable: PipeReturn<[F, ...P$1]> extends never ? never : P$1) => PipeReturn<[F, ...P$1]>;
|
|
13
|
+
declare const retry: <R$1 extends number | "forever", T, C>(times: R$1, effect: Effect<T, C>) => Effect<T, R$1 extends "forever" ? never : C>;
|
|
13
14
|
declare class Effect<T = any, C = any> {
|
|
14
15
|
[RUN]?: (signal: AbortSignal) => T | PromiseLike<T>;
|
|
15
16
|
[ERROR]?: (cause: unknown) => Effect | undefined;
|
|
@@ -38,4 +39,4 @@ type IsNever<T> = [T] extends [never] ? true : false;
|
|
|
38
39
|
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
39
40
|
type ExtendsStrict<Left, Right> = IsAny<Left | Right> extends true ? true : IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
|
|
40
41
|
//#endregion
|
|
41
|
-
export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, succeed };
|
|
42
|
+
export { Effect, Pipeable, PipeableThunk, Thunk, WrapEffect, run as _run, run, catchSome, fail, fn, gen, inferError, inferExclude, inferInput, inferReturn, pipe, retry, succeed };
|
package/dist/mini-effect.mjs
CHANGED
|
@@ -45,6 +45,10 @@ const pipe = (first, ...pipeable) => {
|
|
|
45
45
|
return next;
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
+
const retry = (times, effect) => {
|
|
49
|
+
let step = 0;
|
|
50
|
+
return effect.pipe(catchSome((cause) => typeof times === "number" && ++step > times ? fail(cause) : effect));
|
|
51
|
+
};
|
|
48
52
|
var Effect = class {
|
|
49
53
|
[RUN];
|
|
50
54
|
[ERROR];
|
|
@@ -97,4 +101,4 @@ var WrapEffect = class {
|
|
|
97
101
|
};
|
|
98
102
|
|
|
99
103
|
//#endregion
|
|
100
|
-
export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, succeed };
|
|
104
|
+
export { Effect, WrapEffect, run as _run, run, catchSome, fail, fn, gen, pipe, retry, succeed };
|