effect 2.0.5 → 2.1.1
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/cjs/Effect.js +6 -78
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/ReadonlyRecord.js +39 -1
- package/dist/cjs/ReadonlyRecord.js.map +1 -1
- package/dist/cjs/Runtime.js.map +1 -1
- package/dist/cjs/internal/channel.js +6 -2
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/runtime.js +21 -7
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/schedule.js +68 -24
- package/dist/cjs/internal/schedule.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Effect.d.ts +76 -105
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/ReadonlyRecord.d.ts +30 -0
- package/dist/dts/ReadonlyRecord.d.ts.map +1 -1
- package/dist/dts/Runtime.d.ts +12 -2
- package/dist/dts/Runtime.d.ts.map +1 -1
- package/dist/dts/internal/version.d.ts +1 -1
- package/dist/esm/Effect.js +3 -75
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/ReadonlyRecord.js +38 -0
- package/dist/esm/ReadonlyRecord.js.map +1 -1
- package/dist/esm/Runtime.js.map +1 -1
- package/dist/esm/internal/channel.js +6 -2
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/runtime.js +21 -7
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/schedule.js +64 -21
- package/dist/esm/internal/schedule.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/Effect.ts +92 -115
- package/src/ReadonlyRecord.ts +52 -0
- package/src/Runtime.ts +14 -3
- package/src/internal/channel.ts +2 -2
- package/src/internal/runtime.ts +39 -12
- package/src/internal/schedule.ts +126 -135
- package/src/internal/version.ts +1 -1
package/src/Runtime.ts
CHANGED
|
@@ -13,6 +13,7 @@ import * as internal from "./internal/runtime.js"
|
|
|
13
13
|
import type { Pipeable } from "./Pipeable.js"
|
|
14
14
|
import type * as RuntimeFlags from "./RuntimeFlags.js"
|
|
15
15
|
import type { Scheduler } from "./Scheduler.js"
|
|
16
|
+
import type { Scope } from "./Scope.js"
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* @since 2.0.0
|
|
@@ -28,7 +29,7 @@ export interface AsyncFiberException<out E, out A> {
|
|
|
28
29
|
* @category models
|
|
29
30
|
*/
|
|
30
31
|
export interface Cancel<out E, out A> {
|
|
31
|
-
(fiberId?: FiberId.FiberId,
|
|
32
|
+
(fiberId?: FiberId.FiberId, options?: RunCallbackOptions<E, A> | undefined): void
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -57,6 +58,8 @@ export interface Runtime<in R> extends Pipeable {
|
|
|
57
58
|
export interface RunForkOptions {
|
|
58
59
|
readonly scheduler?: Scheduler | undefined
|
|
59
60
|
readonly updateRefs?: ((refs: FiberRefs.FiberRefs, fiberId: FiberId.Runtime) => FiberRefs.FiberRefs) | undefined
|
|
61
|
+
readonly immediate?: boolean
|
|
62
|
+
readonly scope?: Scope
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
/**
|
|
@@ -93,6 +96,14 @@ export const runSyncExit: <R>(runtime: Runtime<R>) => <E, A>(effect: Effect.Effe
|
|
|
93
96
|
*/
|
|
94
97
|
export const runSync: <R>(runtime: Runtime<R>) => <E, A>(effect: Effect.Effect<R, E, A>) => A = internal.unsafeRunSync
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @since 2.0.0
|
|
101
|
+
* @category models
|
|
102
|
+
*/
|
|
103
|
+
export interface RunCallbackOptions<E, A> extends RunForkOptions {
|
|
104
|
+
readonly onExit?: ((exit: Exit.Exit<E, A>) => void) | undefined
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
/**
|
|
97
108
|
* Executes the effect asynchronously, eventually passing the exit value to
|
|
98
109
|
* the specified callback.
|
|
@@ -107,8 +118,8 @@ export const runCallback: <R>(
|
|
|
107
118
|
runtime: Runtime<R>
|
|
108
119
|
) => <E, A>(
|
|
109
120
|
effect: Effect.Effect<R, E, A>,
|
|
110
|
-
|
|
111
|
-
) => (fiberId?: FiberId.FiberId | undefined,
|
|
121
|
+
options?: RunCallbackOptions<E, A> | undefined
|
|
122
|
+
) => (fiberId?: FiberId.FiberId | undefined, options?: RunCallbackOptions<E, A> | undefined) => void =
|
|
112
123
|
internal.unsafeRunCallback
|
|
113
124
|
|
|
114
125
|
/**
|
package/src/internal/channel.ts
CHANGED
|
@@ -1217,7 +1217,7 @@ export const mergeAllWith = (
|
|
|
1217
1217
|
)
|
|
1218
1218
|
})
|
|
1219
1219
|
),
|
|
1220
|
-
Effect.
|
|
1220
|
+
Effect.repeat({ until: (_): _ is Option.Some<OutDone> => Option.isSome(_) }),
|
|
1221
1221
|
Effect.flatMap((outDone) =>
|
|
1222
1222
|
Ref.update(
|
|
1223
1223
|
lastDone,
|
|
@@ -1325,7 +1325,7 @@ export const mergeAllWith = (
|
|
|
1325
1325
|
})
|
|
1326
1326
|
})
|
|
1327
1327
|
}),
|
|
1328
|
-
Effect.
|
|
1328
|
+
Effect.repeat({ while: (_) => _ }),
|
|
1329
1329
|
Effect.forkScoped
|
|
1330
1330
|
)
|
|
1331
1331
|
return [queue, input] as const
|
package/src/internal/runtime.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { equals } from "effect/Equal"
|
|
1
2
|
import type * as Cause from "../Cause.js"
|
|
2
3
|
import * as Context from "../Context.js"
|
|
3
4
|
import type * as Effect from "../Effect.js"
|
|
@@ -15,8 +16,10 @@ import type * as ReadonlyArray from "../ReadonlyArray.js"
|
|
|
15
16
|
import type * as Runtime from "../Runtime.js"
|
|
16
17
|
import type * as RuntimeFlags from "../RuntimeFlags.js"
|
|
17
18
|
import * as _scheduler from "../Scheduler.js"
|
|
19
|
+
import * as _scope from "../Scope.js"
|
|
18
20
|
import * as InternalCause from "./cause.js"
|
|
19
21
|
import * as core from "./core.js"
|
|
22
|
+
import * as executionStrategy from "./executionStrategy.js"
|
|
20
23
|
import * as FiberRuntime from "./fiberRuntime.js"
|
|
21
24
|
import * as fiberScope from "./fiberScope.js"
|
|
22
25
|
import * as OpCodes from "./opCodes/effect.js"
|
|
@@ -30,8 +33,6 @@ export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
30
33
|
options?: Runtime.RunForkOptions
|
|
31
34
|
): Fiber.RuntimeFiber<E, A> => {
|
|
32
35
|
const fiberId = FiberId.unsafeMake()
|
|
33
|
-
const effect = self
|
|
34
|
-
|
|
35
36
|
const fiberRefUpdates: ReadonlyArray.NonEmptyArray<
|
|
36
37
|
readonly [FiberRef.FiberRef<any>, ReadonlyArray.NonEmptyReadonlyArray<readonly [FiberId.Runtime, any]>]
|
|
37
38
|
> = [[core.currentContext, [[fiberId, runtime.context]]]]
|
|
@@ -55,6 +56,24 @@ export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
55
56
|
runtime.runtimeFlags
|
|
56
57
|
)
|
|
57
58
|
|
|
59
|
+
let effect: Effect.Effect<R, E, A> = self
|
|
60
|
+
|
|
61
|
+
if (options?.scope) {
|
|
62
|
+
effect = core.flatMap(
|
|
63
|
+
_scope.fork(options.scope, executionStrategy.sequential),
|
|
64
|
+
(closeableScope) =>
|
|
65
|
+
core.zipRight(
|
|
66
|
+
core.scopeAddFinalizer(
|
|
67
|
+
closeableScope,
|
|
68
|
+
core.fiberIdWith((id) =>
|
|
69
|
+
equals(id, fiberRuntime.id()) ? core.unit : core.interruptAsFiber(fiberRuntime, id)
|
|
70
|
+
)
|
|
71
|
+
),
|
|
72
|
+
core.onExit(effect, (exit) => _scope.close(closeableScope, exit))
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
58
77
|
const supervisor = fiberRuntime._supervisor
|
|
59
78
|
|
|
60
79
|
// we can compare by reference here as _supervisor.none is wrapped with globalValue
|
|
@@ -66,7 +85,12 @@ export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
66
85
|
|
|
67
86
|
fiberScope.globalScope.add(runtime.runtimeFlags, fiberRuntime)
|
|
68
87
|
|
|
69
|
-
|
|
88
|
+
// Only an explicit false will prevent immediate execution
|
|
89
|
+
if (options?.immediate === false) {
|
|
90
|
+
fiberRuntime.resume(effect)
|
|
91
|
+
} else {
|
|
92
|
+
fiberRuntime.start(effect)
|
|
93
|
+
}
|
|
70
94
|
|
|
71
95
|
return fiberRuntime
|
|
72
96
|
}
|
|
@@ -75,22 +99,25 @@ export const unsafeFork = <R>(runtime: Runtime.Runtime<R>) =>
|
|
|
75
99
|
export const unsafeRunCallback = <R>(runtime: Runtime.Runtime<R>) =>
|
|
76
100
|
<E, A>(
|
|
77
101
|
effect: Effect.Effect<R, E, A>,
|
|
78
|
-
|
|
79
|
-
): (fiberId?: FiberId.FiberId,
|
|
80
|
-
const fiberRuntime = unsafeFork(runtime)(effect)
|
|
102
|
+
options: Runtime.RunCallbackOptions<E, A> = {}
|
|
103
|
+
): (fiberId?: FiberId.FiberId, options?: Runtime.RunCallbackOptions<E, A> | undefined) => void => {
|
|
104
|
+
const fiberRuntime = unsafeFork(runtime)(effect, options)
|
|
81
105
|
|
|
82
|
-
if (onExit) {
|
|
106
|
+
if (options.onExit) {
|
|
83
107
|
fiberRuntime.addObserver((exit) => {
|
|
84
|
-
onExit(exit)
|
|
108
|
+
options.onExit!(exit)
|
|
85
109
|
})
|
|
86
110
|
}
|
|
87
111
|
|
|
88
|
-
return (id,
|
|
112
|
+
return (id, cancelOptions) =>
|
|
89
113
|
unsafeRunCallback(runtime)(
|
|
90
114
|
pipe(fiberRuntime, Fiber.interruptAs(id ?? FiberId.none)),
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
{
|
|
116
|
+
...cancelOptions,
|
|
117
|
+
onExit: cancelOptions?.onExit
|
|
118
|
+
? (exit) => cancelOptions.onExit!(Exit.flatten(exit))
|
|
119
|
+
: undefined
|
|
120
|
+
}
|
|
94
121
|
)
|
|
95
122
|
}
|
|
96
123
|
|
package/src/internal/schedule.ts
CHANGED
|
@@ -11,13 +11,14 @@ import type { LazyArg } from "../Function.js"
|
|
|
11
11
|
import { constVoid, dual, pipe } from "../Function.js"
|
|
12
12
|
import * as Option from "../Option.js"
|
|
13
13
|
import { pipeArguments } from "../Pipeable.js"
|
|
14
|
-
import
|
|
14
|
+
import { hasProperty, type Predicate } from "../Predicate.js"
|
|
15
15
|
import * as Random from "../Random.js"
|
|
16
16
|
import type * as Ref from "../Ref.js"
|
|
17
17
|
import type * as Schedule from "../Schedule.js"
|
|
18
18
|
import * as ScheduleDecision from "../ScheduleDecision.js"
|
|
19
19
|
import * as Interval from "../ScheduleInterval.js"
|
|
20
20
|
import * as Intervals from "../ScheduleIntervals.js"
|
|
21
|
+
import * as internalCause from "./cause.js"
|
|
21
22
|
import * as effect from "./core-effect.js"
|
|
22
23
|
import * as core from "./core.js"
|
|
23
24
|
import * as ref from "./ref.js"
|
|
@@ -30,6 +31,9 @@ export const ScheduleTypeId: Schedule.ScheduleTypeId = Symbol.for(
|
|
|
30
31
|
ScheduleSymbolKey
|
|
31
32
|
) as Schedule.ScheduleTypeId
|
|
32
33
|
|
|
34
|
+
/** @internal */
|
|
35
|
+
export const isSchedule = (u: unknown): u is Schedule.Schedule<any, any, any> => hasProperty(u, ScheduleTypeId)
|
|
36
|
+
|
|
33
37
|
/** @internal */
|
|
34
38
|
const ScheduleDriverSymbolKey = "effect/ScheduleDriver"
|
|
35
39
|
|
|
@@ -1831,6 +1835,29 @@ export const findNextMonth = (now: number, day: number, months: number): number
|
|
|
1831
1835
|
|
|
1832
1836
|
// circular with Effect
|
|
1833
1837
|
|
|
1838
|
+
const ScheduleDefectTypeId = Symbol.for("effect/Schedule/ScheduleDefect")
|
|
1839
|
+
class ScheduleDefect<E> {
|
|
1840
|
+
readonly [ScheduleDefectTypeId]: typeof ScheduleDefectTypeId
|
|
1841
|
+
constructor(readonly error: E) {
|
|
1842
|
+
this[ScheduleDefectTypeId] = ScheduleDefectTypeId
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
const isScheduleDefect = <E = unknown>(u: unknown): u is ScheduleDefect<E> => hasProperty(u, ScheduleDefectTypeId)
|
|
1846
|
+
const scheduleDefectWrap = <R, E, A>(self: Effect.Effect<R, E, A>) =>
|
|
1847
|
+
core.catchAll(self, (e) => core.die(new ScheduleDefect(e)))
|
|
1848
|
+
const scheduleDefectRefail = <R, E, A>(self: Effect.Effect<R, E, A>) =>
|
|
1849
|
+
core.catchAllCause(self, (cause) =>
|
|
1850
|
+
Option.match(
|
|
1851
|
+
internalCause.find(
|
|
1852
|
+
cause,
|
|
1853
|
+
(_) => internalCause.isDieType(_) && isScheduleDefect<E>(_.defect) ? Option.some(_.defect) : Option.none()
|
|
1854
|
+
),
|
|
1855
|
+
{
|
|
1856
|
+
onNone: () => core.failCause(cause),
|
|
1857
|
+
onSome: (error) => core.fail(error.error)
|
|
1858
|
+
}
|
|
1859
|
+
))
|
|
1860
|
+
|
|
1834
1861
|
/** @internal */
|
|
1835
1862
|
export const repeat_Effect = dual<
|
|
1836
1863
|
<R1, A extends A0, A0, B>(
|
|
@@ -1842,6 +1869,57 @@ export const repeat_Effect = dual<
|
|
|
1842
1869
|
) => Effect.Effect<R | R1, E, B>
|
|
1843
1870
|
>(2, (self, schedule) => repeatOrElse_Effect(self, schedule, (e, _) => core.fail(e)))
|
|
1844
1871
|
|
|
1872
|
+
/** @internal */
|
|
1873
|
+
export const repeat_combined = dual<{
|
|
1874
|
+
<A, O extends Effect.Repeat.Options<A>>(
|
|
1875
|
+
options: O
|
|
1876
|
+
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Repeat.Return<R, E, A, O>
|
|
1877
|
+
<R1, A extends A0, A0, B>(
|
|
1878
|
+
schedule: Schedule.Schedule<R1, A, B>
|
|
1879
|
+
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, B>
|
|
1880
|
+
}, {
|
|
1881
|
+
<R, E, A, O extends Effect.Repeat.Options<A>>(
|
|
1882
|
+
self: Effect.Effect<R, E, A>,
|
|
1883
|
+
options: O
|
|
1884
|
+
): Effect.Repeat.Return<R, E, A, O>
|
|
1885
|
+
<R, E, A extends A0, A0, R1, B>(
|
|
1886
|
+
self: Effect.Effect<R, E, A>,
|
|
1887
|
+
schedule: Schedule.Schedule<R1, A0, B>
|
|
1888
|
+
): Effect.Effect<R | R1, E, B>
|
|
1889
|
+
}>(
|
|
1890
|
+
2,
|
|
1891
|
+
(self: Effect.Effect<any, any, any>, options: Effect.Repeat.Options<any> | Schedule.Schedule<any, any, any>) => {
|
|
1892
|
+
if (isSchedule(options)) {
|
|
1893
|
+
return repeat_Effect(self, options)
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
const base = options.schedule ?? passthrough(forever)
|
|
1897
|
+
const withWhile = options.while ?
|
|
1898
|
+
whileInputEffect(base, (a) => {
|
|
1899
|
+
const applied = options.while!(a)
|
|
1900
|
+
if (typeof applied === "boolean") {
|
|
1901
|
+
return core.succeed(applied)
|
|
1902
|
+
}
|
|
1903
|
+
return scheduleDefectWrap(applied)
|
|
1904
|
+
}) :
|
|
1905
|
+
base
|
|
1906
|
+
const withUntil = options.until ?
|
|
1907
|
+
untilInputEffect(withWhile, (a) => {
|
|
1908
|
+
const applied = options.until!(a)
|
|
1909
|
+
if (typeof applied === "boolean") {
|
|
1910
|
+
return core.succeed(applied)
|
|
1911
|
+
}
|
|
1912
|
+
return scheduleDefectWrap(applied)
|
|
1913
|
+
}) :
|
|
1914
|
+
withWhile
|
|
1915
|
+
const withTimes = options.times ?
|
|
1916
|
+
intersect(withUntil, recurs(options.times)) :
|
|
1917
|
+
withUntil
|
|
1918
|
+
|
|
1919
|
+
return scheduleDefectRefail(repeat_Effect(self, withTimes))
|
|
1920
|
+
}
|
|
1921
|
+
)
|
|
1922
|
+
|
|
1845
1923
|
/** @internal */
|
|
1846
1924
|
export const repeatOrElse_Effect = dual<
|
|
1847
1925
|
<R2, A extends A0, A0, B, E, R3, E2>(
|
|
@@ -1877,66 +1955,6 @@ const repeatOrElseEffectLoop = <R, E, A extends A0, A0, R1, B, R2, E2, C>(
|
|
|
1877
1955
|
})
|
|
1878
1956
|
}
|
|
1879
1957
|
|
|
1880
|
-
/** @internal */
|
|
1881
|
-
export const repeatUntil_Effect = dual<
|
|
1882
|
-
{
|
|
1883
|
-
<A, B extends A>(f: Refinement<A, B>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, B>
|
|
1884
|
-
<A>(f: Predicate<A>): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
1885
|
-
},
|
|
1886
|
-
{
|
|
1887
|
-
<R, E, A, B extends A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, B>
|
|
1888
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>): Effect.Effect<R, E, A>
|
|
1889
|
-
}
|
|
1890
|
-
>(
|
|
1891
|
-
2,
|
|
1892
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) =>
|
|
1893
|
-
repeatUntilEffect_Effect(self, (a) => core.sync(() => f(a)))
|
|
1894
|
-
)
|
|
1895
|
-
|
|
1896
|
-
/** @internal */
|
|
1897
|
-
export const repeatUntilEffect_Effect: {
|
|
1898
|
-
<A, R2, E2>(
|
|
1899
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1900
|
-
): <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>
|
|
1901
|
-
<R, E, A, R2, E2>(
|
|
1902
|
-
self: Effect.Effect<R, E, A>,
|
|
1903
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1904
|
-
): Effect.Effect<R | R2, E | E2, A>
|
|
1905
|
-
} = dual<
|
|
1906
|
-
<A, R2, E2>(
|
|
1907
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1908
|
-
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R2, E | E2, A>,
|
|
1909
|
-
<R, E, A, R2, E2>(
|
|
1910
|
-
self: Effect.Effect<R, E, A>,
|
|
1911
|
-
f: (a: A) => Effect.Effect<R2, E2, boolean>
|
|
1912
|
-
) => Effect.Effect<R | R2, E | E2, A>
|
|
1913
|
-
>(2, (self, f) =>
|
|
1914
|
-
core.flatMap(self, (a) =>
|
|
1915
|
-
core.flatMap(f(a), (result) =>
|
|
1916
|
-
result ?
|
|
1917
|
-
core.succeed(a) :
|
|
1918
|
-
core.flatMap(
|
|
1919
|
-
core.yieldNow(),
|
|
1920
|
-
() => repeatUntilEffect_Effect(self, f)
|
|
1921
|
-
))))
|
|
1922
|
-
|
|
1923
|
-
/** @internal */
|
|
1924
|
-
export const repeatWhile_Effect = dual<
|
|
1925
|
-
<A>(f: Predicate<A>) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
1926
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<A>) => Effect.Effect<R, E, A>
|
|
1927
|
-
>(2, (self, f) => repeatWhileEffect_Effect(self, (a) => core.sync(() => f(a))))
|
|
1928
|
-
|
|
1929
|
-
/** @internal */
|
|
1930
|
-
export const repeatWhileEffect_Effect = dual<
|
|
1931
|
-
<R1, A, E2>(
|
|
1932
|
-
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1933
|
-
) => <R, E>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
1934
|
-
<R, E, R1, A, E2>(
|
|
1935
|
-
self: Effect.Effect<R, E, A>,
|
|
1936
|
-
f: (a: A) => Effect.Effect<R1, E2, boolean>
|
|
1937
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
1938
|
-
>(2, (self, f) => repeatUntilEffect_Effect(self, (a) => effect.negate(f(a))))
|
|
1939
|
-
|
|
1940
1958
|
/** @internal */
|
|
1941
1959
|
export const retry_Effect = dual<
|
|
1942
1960
|
<R1, E extends E0, E0, B>(
|
|
@@ -1949,21 +1967,54 @@ export const retry_Effect = dual<
|
|
|
1949
1967
|
>(2, (self, policy) => retryOrElse_Effect(self, policy, (e, _) => core.fail(e)))
|
|
1950
1968
|
|
|
1951
1969
|
/** @internal */
|
|
1952
|
-
export const
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1970
|
+
export const retry_combined = dual<{
|
|
1971
|
+
<E, O extends Effect.Retry.Options<E>>(
|
|
1972
|
+
options: O
|
|
1973
|
+
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Retry.Return<R, E, A, O>
|
|
1974
|
+
<R1, E extends E0, E0, B>(
|
|
1975
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1976
|
+
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E, A>
|
|
1977
|
+
}, {
|
|
1978
|
+
<R, A, E, O extends Effect.Retry.Options<E>>(
|
|
1979
|
+
self: Effect.Effect<R, E, A>,
|
|
1980
|
+
options: O
|
|
1981
|
+
): Effect.Retry.Return<R, E, A, O>
|
|
1982
|
+
<R, E extends E0, E0, A, R1, B>(
|
|
1983
|
+
self: Effect.Effect<R, E, A>,
|
|
1984
|
+
policy: Schedule.Schedule<R1, E0, B>
|
|
1985
|
+
): Effect.Effect<R | R1, E, A>
|
|
1986
|
+
}>(
|
|
1987
|
+
2,
|
|
1988
|
+
(self: Effect.Effect<any, any, any>, options: Effect.Retry.Options<any> | Schedule.Schedule<any, any, any>) => {
|
|
1989
|
+
if (isSchedule(options)) {
|
|
1990
|
+
return retry_Effect(self, options)
|
|
1991
|
+
}
|
|
1956
1992
|
|
|
1957
|
-
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1993
|
+
const base = options.schedule ?? forever
|
|
1994
|
+
const withWhile = options.while ?
|
|
1995
|
+
whileInputEffect(base, (e) => {
|
|
1996
|
+
const applied = options.while!(e)
|
|
1997
|
+
if (typeof applied === "boolean") {
|
|
1998
|
+
return core.succeed(applied)
|
|
1999
|
+
}
|
|
2000
|
+
return scheduleDefectWrap(applied)
|
|
2001
|
+
}) :
|
|
2002
|
+
base
|
|
2003
|
+
const withUntil = options.until ?
|
|
2004
|
+
untilInputEffect(withWhile, (e) => {
|
|
2005
|
+
const applied = options.until!(e)
|
|
2006
|
+
if (typeof applied === "boolean") {
|
|
2007
|
+
return core.succeed(applied)
|
|
2008
|
+
}
|
|
2009
|
+
return scheduleDefectWrap(applied)
|
|
2010
|
+
}) :
|
|
2011
|
+
withWhile
|
|
2012
|
+
const withTimes = options.times ?
|
|
2013
|
+
intersect(withUntil, recurs(options.times)) :
|
|
2014
|
+
withUntil
|
|
2015
|
+
return scheduleDefectRefail(retry_Effect(self, withTimes))
|
|
2016
|
+
}
|
|
2017
|
+
)
|
|
1967
2018
|
|
|
1968
2019
|
/** @internal */
|
|
1969
2020
|
export const retryOrElse_Effect = dual<
|
|
@@ -2003,66 +2054,6 @@ const retryOrElse_EffectLoop = <R, E, A, R1, A1, R2, E2, A2>(
|
|
|
2003
2054
|
)
|
|
2004
2055
|
}
|
|
2005
2056
|
|
|
2006
|
-
/** @internal */
|
|
2007
|
-
export const retryUntil_Effect = dual<
|
|
2008
|
-
{
|
|
2009
|
-
<E, E2 extends E>(f: Refinement<E, E2>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E2, A>
|
|
2010
|
-
<E>(f: Predicate<E>): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>
|
|
2011
|
-
},
|
|
2012
|
-
{
|
|
2013
|
-
<R, E, A, E2 extends E>(self: Effect.Effect<R, E, A>, f: Refinement<E, E2>): Effect.Effect<R, E2, A>
|
|
2014
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>): Effect.Effect<R, E, A>
|
|
2015
|
-
}
|
|
2016
|
-
>(2, <R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) =>
|
|
2017
|
-
retryUntilEffect_Effect(
|
|
2018
|
-
self,
|
|
2019
|
-
(e) => core.sync(() => f(e))
|
|
2020
|
-
))
|
|
2021
|
-
|
|
2022
|
-
/** @internal */
|
|
2023
|
-
export const retryUntilEffect_Effect: {
|
|
2024
|
-
<R1, E, E2>(
|
|
2025
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2026
|
-
): <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R1 | R, E | E2, A>
|
|
2027
|
-
<R, E, A, R1, E2>(
|
|
2028
|
-
self: Effect.Effect<R, E, A>,
|
|
2029
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2030
|
-
): Effect.Effect<R | R1, E | E2, A>
|
|
2031
|
-
} = dual<
|
|
2032
|
-
<R1, E, E2>(
|
|
2033
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2034
|
-
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
2035
|
-
<R, E, A, R1, E2>(
|
|
2036
|
-
self: Effect.Effect<R, E, A>,
|
|
2037
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2038
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
2039
|
-
>(2, (self, f) =>
|
|
2040
|
-
core.catchAll(self, (e) =>
|
|
2041
|
-
core.flatMap(f(e), (b) =>
|
|
2042
|
-
b ?
|
|
2043
|
-
core.fail(e) :
|
|
2044
|
-
core.flatMap(
|
|
2045
|
-
core.yieldNow(),
|
|
2046
|
-
() => retryUntilEffect_Effect(self, f)
|
|
2047
|
-
))))
|
|
2048
|
-
|
|
2049
|
-
/** @internal */
|
|
2050
|
-
export const retryWhile_Effect = dual<
|
|
2051
|
-
<E>(f: Predicate<E>) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R, E, A>,
|
|
2052
|
-
<R, E, A>(self: Effect.Effect<R, E, A>, f: Predicate<E>) => Effect.Effect<R, E, A>
|
|
2053
|
-
>(2, (self, f) => retryWhileEffect_Effect(self, (e) => core.sync(() => f(e))))
|
|
2054
|
-
|
|
2055
|
-
/** @internal */
|
|
2056
|
-
export const retryWhileEffect_Effect = dual<
|
|
2057
|
-
<R1, E, E2>(
|
|
2058
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2059
|
-
) => <R, A>(self: Effect.Effect<R, E, A>) => Effect.Effect<R | R1, E | E2, A>,
|
|
2060
|
-
<R, E, A, R1, E2>(
|
|
2061
|
-
self: Effect.Effect<R, E, A>,
|
|
2062
|
-
f: (e: E) => Effect.Effect<R1, E2, boolean>
|
|
2063
|
-
) => Effect.Effect<R | R1, E | E2, A>
|
|
2064
|
-
>(2, (self, f) => retryUntilEffect_Effect(self, (e) => effect.negate(f(e))))
|
|
2065
|
-
|
|
2066
2057
|
/** @internal */
|
|
2067
2058
|
export const schedule_Effect = dual<
|
|
2068
2059
|
<R2, Out>(
|
package/src/internal/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const moduleVersion = "2.
|
|
1
|
+
export const moduleVersion = "2.1.1"
|