@typed/fx 1.2.1 → 1.4.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.
- package/dist/Subject/HoldSubject.d.ts +2 -2
- package/dist/Subject/HoldSubject.d.ts.map +1 -1
- package/dist/Subject/HoldSubject.js +3 -3
- package/dist/Subject/HoldSubject.js.map +1 -1
- package/dist/Subject/RefSubject.d.ts.map +1 -1
- package/dist/Subject/RefSubject.js +10 -10
- package/dist/Subject/RefSubject.js.map +1 -1
- package/dist/Subject/Subject.js +1 -1
- package/dist/Subject/Subject.js.map +1 -1
- package/dist/Subject/SynchronizedSubject.js +5 -5
- package/dist/Subject/SynchronizedSubject.js.map +1 -1
- package/dist/_internal/RefCounter.js +1 -1
- package/dist/_internal/RefCounter.js.map +1 -1
- package/dist/cjs/Subject/HoldSubject.d.ts +2 -2
- package/dist/cjs/Subject/HoldSubject.d.ts.map +1 -1
- package/dist/cjs/Subject/HoldSubject.js +3 -3
- package/dist/cjs/Subject/HoldSubject.js.map +1 -1
- package/dist/cjs/Subject/RefSubject.d.ts.map +1 -1
- package/dist/cjs/Subject/RefSubject.js +9 -9
- package/dist/cjs/Subject/RefSubject.js.map +1 -1
- package/dist/cjs/Subject/SynchronizedSubject.js +4 -4
- package/dist/cjs/Subject/SynchronizedSubject.js.map +1 -1
- package/dist/cjs/_internal/RefCounter.js +1 -1
- package/dist/cjs/_internal/RefCounter.js.map +1 -1
- package/dist/cjs/constructor/index.d.ts +0 -5
- package/dist/cjs/constructor/index.d.ts.map +1 -1
- package/dist/cjs/constructor/index.js +0 -5
- package/dist/cjs/constructor/index.js.map +1 -1
- package/dist/cjs/constructor/promiseFx.d.ts +0 -2
- package/dist/cjs/constructor/promiseFx.d.ts.map +1 -1
- package/dist/cjs/constructor/promiseFx.js +1 -5
- package/dist/cjs/constructor/promiseFx.js.map +1 -1
- package/dist/cjs/constructor/serviceWith.d.ts +1 -1
- package/dist/cjs/constructor/serviceWith.d.ts.map +1 -1
- package/dist/cjs/constructor/serviceWith.js +1 -1
- package/dist/cjs/constructor/serviceWith.js.map +1 -1
- package/dist/cjs/constructor/serviceWithEffect.d.ts +1 -1
- package/dist/cjs/constructor/serviceWithEffect.d.ts.map +1 -1
- package/dist/cjs/constructor/serviceWithEffect.js +1 -1
- package/dist/cjs/constructor/serviceWithEffect.js.map +1 -1
- package/dist/cjs/constructor/serviceWithFx.d.ts +1 -1
- package/dist/cjs/constructor/serviceWithFx.d.ts.map +1 -1
- package/dist/cjs/constructor/serviceWithFx.js +1 -1
- package/dist/cjs/constructor/serviceWithFx.js.map +1 -1
- package/dist/cjs/operator/catchAllDefect.d.ts.map +1 -1
- package/dist/cjs/operator/catchAllDefect.js +2 -1
- package/dist/cjs/operator/catchAllDefect.js.map +1 -1
- package/dist/cjs/operator/continueWith.js +1 -1
- package/dist/cjs/operator/continueWith.js.map +1 -1
- package/dist/cjs/operator/debounce.js +1 -1
- package/dist/cjs/operator/debounce.js.map +1 -1
- package/dist/cjs/operator/during.js +1 -1
- package/dist/cjs/operator/during.js.map +1 -1
- package/dist/cjs/operator/hold.d.ts.map +1 -1
- package/dist/cjs/operator/hold.js +8 -8
- package/dist/cjs/operator/hold.js.map +1 -1
- package/dist/cjs/operator/loop.js +1 -1
- package/dist/cjs/operator/loop.js.map +1 -1
- package/dist/cjs/operator/multicast.js +3 -3
- package/dist/cjs/operator/multicast.js.map +1 -1
- package/dist/cjs/operator/provideService.d.ts +1 -1
- package/dist/cjs/operator/provideService.d.ts.map +1 -1
- package/dist/cjs/operator/provideService.js.map +1 -1
- package/dist/cjs/operator/provideServiceEffect.d.ts +1 -1
- package/dist/cjs/operator/provideServiceEffect.d.ts.map +1 -1
- package/dist/cjs/operator/provideServiceEffect.js.map +1 -1
- package/dist/cjs/operator/race.js +1 -1
- package/dist/cjs/operator/race.js.map +1 -1
- package/dist/cjs/operator/skipRepeats.js +2 -2
- package/dist/cjs/operator/skipRepeats.js.map +1 -1
- package/dist/cjs/operator/switchMatch.js +1 -1
- package/dist/cjs/operator/switchMatch.js.map +1 -1
- package/dist/cjs/operator/tapDefect.d.ts.map +1 -1
- package/dist/cjs/operator/tapDefect.js +2 -1
- package/dist/cjs/operator/tapDefect.js.map +1 -1
- package/dist/cjs/run/collectAll.js +1 -1
- package/dist/cjs/run/collectAll.js.map +1 -1
- package/dist/cjs/run/collectN.js +1 -1
- package/dist/cjs/run/collectN.js.map +1 -1
- package/dist/cjs/run/reduce.js +1 -1
- package/dist/cjs/run/reduce.js.map +1 -1
- package/dist/constructor/done.js +1 -1
- package/dist/constructor/done.js.map +1 -1
- package/dist/constructor/empty.js +1 -1
- package/dist/constructor/empty.js.map +1 -1
- package/dist/constructor/fromArray.js +1 -1
- package/dist/constructor/fromArray.js.map +1 -1
- package/dist/constructor/fromEffect.js +1 -1
- package/dist/constructor/fromEffect.js.map +1 -1
- package/dist/constructor/fromIterable.js +1 -1
- package/dist/constructor/fromIterable.js.map +1 -1
- package/dist/constructor/index.d.ts +0 -5
- package/dist/constructor/index.d.ts.map +1 -1
- package/dist/constructor/index.js +0 -5
- package/dist/constructor/index.js.map +1 -1
- package/dist/constructor/never.js +1 -1
- package/dist/constructor/never.js.map +1 -1
- package/dist/constructor/promiseFx.d.ts +0 -2
- package/dist/constructor/promiseFx.d.ts.map +1 -1
- package/dist/constructor/promiseFx.js +0 -2
- package/dist/constructor/promiseFx.js.map +1 -1
- package/dist/constructor/service.d.ts +1 -1
- package/dist/constructor/service.d.ts.map +1 -1
- package/dist/constructor/service.js.map +1 -1
- package/dist/constructor/serviceWith.d.ts +1 -1
- package/dist/constructor/serviceWith.d.ts.map +1 -1
- package/dist/constructor/serviceWith.js +1 -1
- package/dist/constructor/serviceWith.js.map +1 -1
- package/dist/constructor/serviceWithEffect.d.ts +1 -1
- package/dist/constructor/serviceWithEffect.d.ts.map +1 -1
- package/dist/constructor/serviceWithEffect.js +1 -1
- package/dist/constructor/serviceWithEffect.js.map +1 -1
- package/dist/constructor/serviceWithFx.d.ts +1 -1
- package/dist/constructor/serviceWithFx.d.ts.map +1 -1
- package/dist/constructor/serviceWithFx.js +1 -1
- package/dist/constructor/serviceWithFx.js.map +1 -1
- package/dist/operator/catchAllDefect.d.ts.map +1 -1
- package/dist/operator/catchAllDefect.js +2 -1
- package/dist/operator/catchAllDefect.js.map +1 -1
- package/dist/operator/continueWith.js +2 -2
- package/dist/operator/continueWith.js.map +1 -1
- package/dist/operator/debounce.js +1 -1
- package/dist/operator/debounce.js.map +1 -1
- package/dist/operator/during.js +1 -1
- package/dist/operator/during.js.map +1 -1
- package/dist/operator/hold.d.ts.map +1 -1
- package/dist/operator/hold.js +8 -8
- package/dist/operator/hold.js.map +1 -1
- package/dist/operator/loop.js +1 -1
- package/dist/operator/loop.js.map +1 -1
- package/dist/operator/multicast.js +3 -3
- package/dist/operator/multicast.js.map +1 -1
- package/dist/operator/provideService.d.ts +1 -1
- package/dist/operator/provideService.d.ts.map +1 -1
- package/dist/operator/provideService.js.map +1 -1
- package/dist/operator/provideServiceEffect.d.ts +1 -1
- package/dist/operator/provideServiceEffect.d.ts.map +1 -1
- package/dist/operator/provideServiceEffect.js.map +1 -1
- package/dist/operator/race.js +1 -1
- package/dist/operator/race.js.map +1 -1
- package/dist/operator/scanEffect.js +1 -1
- package/dist/operator/scanEffect.js.map +1 -1
- package/dist/operator/skipRepeats.js +2 -2
- package/dist/operator/skipRepeats.js.map +1 -1
- package/dist/operator/switchMatch.js +1 -1
- package/dist/operator/switchMatch.js.map +1 -1
- package/dist/operator/tapDefect.d.ts.map +1 -1
- package/dist/operator/tapDefect.js +2 -1
- package/dist/operator/tapDefect.js.map +1 -1
- package/dist/run/collectAll.js +1 -1
- package/dist/run/collectAll.js.map +1 -1
- package/dist/run/collectN.js +1 -1
- package/dist/run/collectN.js.map +1 -1
- package/dist/run/reduce.js +1 -1
- package/dist/run/reduce.js.map +1 -1
- package/dist/run/run.js +1 -1
- package/dist/run/run.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/Subject/HoldSubject.ts +4 -4
- package/src/Subject/RefSubject.ts +9 -9
- package/src/Subject/SynchronizedSubject.ts +4 -4
- package/src/_internal/RefCounter.ts +1 -1
- package/src/constructor/index.ts +0 -5
- package/src/constructor/promiseFx.ts +0 -22
- package/src/constructor/serviceWith.ts +2 -2
- package/src/constructor/serviceWithEffect.ts +4 -4
- package/src/constructor/serviceWithFx.ts +5 -5
- package/src/operator/catchAllDefect.ts +2 -1
- package/src/operator/continueWith.ts +2 -2
- package/src/operator/debounce.ts +1 -1
- package/src/operator/during.ts +1 -1
- package/src/operator/hold.ts +9 -8
- package/src/operator/loop.ts +1 -1
- package/src/operator/multicast.ts +3 -3
- package/src/operator/provideService.ts +10 -6
- package/src/operator/provideServiceEffect.ts +9 -9
- package/src/operator/race.ts +1 -1
- package/src/operator/skipRepeats.ts +2 -2
- package/src/operator/switchMatch.ts +1 -1
- package/src/operator/tapDefect.ts +2 -1
- package/src/run/collectAll.ts +1 -1
- package/src/run/collectN.ts +1 -1
- package/src/run/reduce.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.cjs.build.json +2 -2
- package/src/constructor/service.ts +0 -9
- package/src/constructor/tryCatchPromise.ts +0 -11
- package/src/constructor/tryCatchPromiseAbort.ts +0 -11
- package/src/constructor/tryPromise.ts +0 -11
- package/src/constructor/tryPromiseAbort.ts +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { identity } from '@effect/data/Function'
|
|
2
|
-
import
|
|
2
|
+
import * as MutableRef from '@effect/data/MutableRef'
|
|
3
3
|
import { type Option, none } from '@effect/data/Option'
|
|
4
4
|
import * as Effect from '@effect/io/Effect'
|
|
5
5
|
|
|
@@ -32,7 +32,7 @@ export namespace HoldSubject {
|
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
33
|
export type OutputsOf<T> = [T] extends [Variance<infer _E, infer A>] ? A : never
|
|
34
34
|
|
|
35
|
-
export function unsafeMake<E, A>(value: MutableRef<Option<A>> = make(none())): HoldSubject<E, A> {
|
|
35
|
+
export function unsafeMake<E, A>(value: MutableRef.MutableRef<Option<A>> = MutableRef.make(none())): HoldSubject<E, A> {
|
|
36
36
|
return new HoldSubjectImpl(value)
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -43,11 +43,11 @@ export namespace HoldSubject {
|
|
|
43
43
|
};
|
|
44
44
|
readonly [TypeId]: HoldSubject.Variance<E, A>[TypeId] = this[Subject.TypeId]
|
|
45
45
|
|
|
46
|
-
constructor(value: MutableRef<Option<A>>) {
|
|
46
|
+
constructor(value: MutableRef.MutableRef<Option<A>>) {
|
|
47
47
|
super(never, value)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
readonly value = Effect.sync(() => this.current
|
|
50
|
+
readonly value = Effect.sync(() => MutableRef.get(this.current))
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -48,14 +48,14 @@ export namespace RefSubject {
|
|
|
48
48
|
const current = MutableRef.make(Option.some(initial()))
|
|
49
49
|
const subject = HoldSubject.unsafeMake<never, A>(current)
|
|
50
50
|
|
|
51
|
-
const getValue = () => pipe(current.get
|
|
51
|
+
const getValue = () => pipe(current, MutableRef.get, Option.getOrElse(initial))
|
|
52
52
|
|
|
53
53
|
const modify = <B>(f: (a: A) => readonly [B, A]): Effect.Effect<never, never, B> =>
|
|
54
|
-
Effect.
|
|
54
|
+
Effect.suspend(() => {
|
|
55
55
|
const currentValue = getValue()
|
|
56
56
|
const [b, a] = f(currentValue)
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
MutableRef.set(current, Option.some(a))
|
|
59
59
|
|
|
60
60
|
if (eq(currentValue, a)) {
|
|
61
61
|
return Effect.succeed(b)
|
|
@@ -80,9 +80,9 @@ export namespace RefSubject {
|
|
|
80
80
|
modify,
|
|
81
81
|
...makeDerivations(modify, Effect.sync(getValue)),
|
|
82
82
|
delete: Effect.sync(() => {
|
|
83
|
-
const option =
|
|
83
|
+
const option = MutableRef.get(current)
|
|
84
84
|
const reset = initial()
|
|
85
|
-
|
|
85
|
+
MutableRef.set(current, Option.some(reset))
|
|
86
86
|
|
|
87
87
|
return Option.getOrElse(option, () => reset)
|
|
88
88
|
}),
|
|
@@ -103,7 +103,7 @@ export namespace RefSubject {
|
|
|
103
103
|
type Val = { readonly [K in keyof Subjects]: ValueOf<Subjects[K]> }
|
|
104
104
|
const length = subjects.length
|
|
105
105
|
|
|
106
|
-
const getUnderlyingValues = Effect.
|
|
106
|
+
const getUnderlyingValues = Effect.all(
|
|
107
107
|
...ReadonlyArray.mapNonEmpty(subjects, (s) => s.get),
|
|
108
108
|
) as Effect.Effect<never, never, Val>
|
|
109
109
|
|
|
@@ -128,7 +128,7 @@ export namespace RefSubject {
|
|
|
128
128
|
|
|
129
129
|
// Override event to replicate events into underlying subjects
|
|
130
130
|
const event = (val: Val) =>
|
|
131
|
-
Effect.
|
|
131
|
+
Effect.all(...ReadonlyArray.mapNonEmpty(subjects, (s, i) => s.event(val[i])))
|
|
132
132
|
|
|
133
133
|
// Override modify to replicate events into underlying subjects
|
|
134
134
|
const modify = <B>(f: (a: Val) => readonly [B, Val]): Effect.Effect<never, never, B> =>
|
|
@@ -173,7 +173,7 @@ export namespace RefSubject {
|
|
|
173
173
|
> {
|
|
174
174
|
type Val = { readonly [K in keyof Subjects]: ValueOf<Subjects[K]> }
|
|
175
175
|
|
|
176
|
-
const getUnderlyingValues = Effect.
|
|
176
|
+
const getUnderlyingValues = Effect.all(
|
|
177
177
|
ReadonlyRecord.map(subjects, (s) => s.get),
|
|
178
178
|
) as Effect.Effect<never, never, Val>
|
|
179
179
|
|
|
@@ -197,7 +197,7 @@ export namespace RefSubject {
|
|
|
197
197
|
|
|
198
198
|
// Override event to replicate events into underlying subjects
|
|
199
199
|
const event = (val: Val) =>
|
|
200
|
-
Effect.
|
|
200
|
+
Effect.all(ReadonlyRecord.map(subjects, (s, i) => s.event(val[i])))
|
|
201
201
|
|
|
202
202
|
// Override modify to replicate events into underlying subjects
|
|
203
203
|
const modify = <B>(f: (a: Val) => readonly [B, Val]): Effect.Effect<never, never, B> =>
|
|
@@ -34,11 +34,11 @@ export namespace SynchronizedSubject {
|
|
|
34
34
|
|
|
35
35
|
const getValue = () =>
|
|
36
36
|
pipe(
|
|
37
|
-
|
|
37
|
+
MutableRef.get(mutableRef),
|
|
38
38
|
Option.getOrElse(() => {
|
|
39
39
|
const a = initial()
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
MutableRef.set(mutableRef, Option.some(a))
|
|
42
42
|
|
|
43
43
|
return a
|
|
44
44
|
}),
|
|
@@ -56,7 +56,7 @@ export namespace SynchronizedSubject {
|
|
|
56
56
|
return b
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
MutableRef.set(mutableRef, Option.some(a))
|
|
60
60
|
|
|
61
61
|
yield* $(subject.event(a))
|
|
62
62
|
|
|
@@ -100,7 +100,7 @@ export namespace SynchronizedSubject {
|
|
|
100
100
|
delete: Effect.sync(() => {
|
|
101
101
|
const value = getValue()
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
MutableRef.set(mutableRef, Option.some(value))
|
|
104
104
|
|
|
105
105
|
return value
|
|
106
106
|
}),
|
|
@@ -33,7 +33,7 @@ export class RefCounter {
|
|
|
33
33
|
|
|
34
34
|
readonly wait = Deferred.await(this.deferred)
|
|
35
35
|
|
|
36
|
-
private checkShouldClose = Effect.
|
|
36
|
+
private checkShouldClose = Effect.suspend(() => {
|
|
37
37
|
const interrupt = this.fiber ? Fiber.interrupt(this.fiber) : Effect.unit()
|
|
38
38
|
|
|
39
39
|
this.fiber = undefined
|
package/src/constructor/index.ts
CHANGED
|
@@ -31,15 +31,10 @@ export * from './promiseAbort.js'
|
|
|
31
31
|
export * from './promiseFx.js'
|
|
32
32
|
export * from './random.js'
|
|
33
33
|
export * from './scheduled.js'
|
|
34
|
-
export * from './service.js'
|
|
35
34
|
export * from './serviceWith.js'
|
|
36
35
|
export * from './serviceWithEffect.js'
|
|
37
36
|
export * from './serviceWithFx.js'
|
|
38
37
|
export * from './succeed.js'
|
|
39
38
|
export * from './suspend.js'
|
|
40
39
|
export * from './sync.js'
|
|
41
|
-
export * from './tryCatchPromise.js'
|
|
42
|
-
export * from './tryCatchPromiseAbort.js'
|
|
43
|
-
export * from './tryPromise.js'
|
|
44
|
-
export * from './tryPromiseAbort.js'
|
|
45
40
|
export * from './unit.js'
|
|
@@ -20,25 +20,3 @@ export const promiseInterruptFx = <R, E, A>(
|
|
|
20
20
|
Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
|
|
21
21
|
),
|
|
22
22
|
)
|
|
23
|
-
|
|
24
|
-
export const tryCatchPromiseFx = <R, E, A, E2>(
|
|
25
|
-
f: () => Promise<Fx<R, E, A>>,
|
|
26
|
-
onError: (u: unknown) => E2,
|
|
27
|
-
): Fx<R, E | E2, A> =>
|
|
28
|
-
Fx((sink) =>
|
|
29
|
-
pipe(
|
|
30
|
-
Effect.tryCatchPromise(f, onError),
|
|
31
|
-
Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
|
|
32
|
-
),
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
export const tryCatchPromiseInterruptFx = <R, E, A, E2>(
|
|
36
|
-
f: (signal: AbortSignal) => Promise<Fx<R, E, A>>,
|
|
37
|
-
onError: (u: unknown) => E2,
|
|
38
|
-
): Fx<R, E | E2, A> =>
|
|
39
|
-
Fx((sink) =>
|
|
40
|
-
pipe(
|
|
41
|
-
Effect.tryCatchPromiseInterrupt(f, onError),
|
|
42
|
-
Effect.matchCauseEffect(sink.error, (fx) => fx.run(sink)),
|
|
43
|
-
),
|
|
44
|
-
)
|
|
@@ -5,6 +5,6 @@ import type { Fx } from '../Fx.js'
|
|
|
5
5
|
|
|
6
6
|
import { fromEffect } from './fromEffect.js'
|
|
7
7
|
|
|
8
|
-
export const serviceWith: <T>(tag: Tag<T>) => <A>(f: (a: T) => A) => Fx<
|
|
8
|
+
export const serviceWith: <I, T>(tag: Tag<I, T>) => <A>(f: (a: T) => A) => Fx<I, never, A> =
|
|
9
9
|
(tag) => (f) =>
|
|
10
|
-
fromEffect(Effect.
|
|
10
|
+
fromEffect(Effect.map(tag, f))
|
|
@@ -5,7 +5,7 @@ import type { Fx } from '../Fx.js'
|
|
|
5
5
|
|
|
6
6
|
import { fromEffect } from './fromEffect.js'
|
|
7
7
|
|
|
8
|
-
export const serviceWithEffect: <T>(
|
|
9
|
-
tag: Tag<T>,
|
|
10
|
-
) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<
|
|
11
|
-
fromEffect(Effect.
|
|
8
|
+
export const serviceWithEffect: <I, T>(
|
|
9
|
+
tag: Tag<I, T>,
|
|
10
|
+
) => <R, E, A>(f: (a: T) => Effect.Effect<R, E, A>) => Fx<I | R, E, A> = (tag) => (f) =>
|
|
11
|
+
fromEffect(Effect.flatMap(tag, f))
|
|
@@ -4,16 +4,16 @@ import * as Effect from '@effect/io/Effect'
|
|
|
4
4
|
import { Fx } from '../Fx.js'
|
|
5
5
|
|
|
6
6
|
export const serviceWithFx =
|
|
7
|
-
<
|
|
8
|
-
<R, E, A>(f: (
|
|
7
|
+
<I, S>(tag: Tag<I, S>) =>
|
|
8
|
+
<R, E, A>(f: (s: S) => Fx<R, E, A>): Fx<I | R, E, A> =>
|
|
9
9
|
new ServiceWithFx(tag, f)
|
|
10
10
|
|
|
11
|
-
class ServiceWithFx<
|
|
12
|
-
constructor(readonly tag: Tag<
|
|
11
|
+
class ServiceWithFx<I, S, R, E, A> extends Fx.Variance<I | R, E, A> implements Fx<I | R, E, A> {
|
|
12
|
+
constructor(readonly tag: Tag<I, S>, readonly f: (a: S) => Fx<R, E, A>) {
|
|
13
13
|
super()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
run<R2>(sink: Fx.Sink<R2, E, A>) {
|
|
17
|
-
return Effect.
|
|
17
|
+
return Effect.flatMap(this.tag, (a) => this.f(a).run(sink))
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pipe } from '@effect/data/Function'
|
|
2
2
|
import { match } from '@effect/data/Option'
|
|
3
|
+
import * as Chunk from '@effect/data/Chunk'
|
|
3
4
|
import * as Cause from '@effect/io/Cause'
|
|
4
5
|
|
|
5
6
|
import type { Fx } from '../Fx.js'
|
|
@@ -14,7 +15,7 @@ export function catchAllDefect<R2, E2, B>(f: (defect: unknown) => Fx<R2, E2, B>)
|
|
|
14
15
|
catchAllCause(
|
|
15
16
|
(cause): Fx<R2, E | E2, B> =>
|
|
16
17
|
pipe(
|
|
17
|
-
|
|
18
|
+
Chunk.get(Cause.defects(cause), 0),
|
|
18
19
|
match(() => failCause(cause), f),
|
|
19
20
|
),
|
|
20
21
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { suspend } from '@effect/io/Effect'
|
|
2
2
|
|
|
3
3
|
import { Fx } from '../Fx.js'
|
|
4
4
|
|
|
@@ -24,5 +24,5 @@ class ContinueWithSink<R, E, A, R2, E2, B> {
|
|
|
24
24
|
|
|
25
25
|
event = this.sink.event
|
|
26
26
|
error = this.sink.error
|
|
27
|
-
end =
|
|
27
|
+
end = suspend(() => this.f().run(this.sink))
|
|
28
28
|
}
|
package/src/operator/debounce.ts
CHANGED
|
@@ -27,7 +27,7 @@ class DebounceFx<R, E, A> extends Fx.Variance<R, E, A> implements Fx<R, E, A> {
|
|
|
27
27
|
return fx.run(
|
|
28
28
|
Fx.Sink(
|
|
29
29
|
(a: A) =>
|
|
30
|
-
Effect.
|
|
30
|
+
Effect.suspend(() =>
|
|
31
31
|
pipe(
|
|
32
32
|
scheduledFiber ? Fiber.interrupt(scheduledFiber) : counter.increment,
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
package/src/operator/during.ts
CHANGED
package/src/operator/hold.ts
CHANGED
|
@@ -34,8 +34,8 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
run<R2>(sink: Fx.Sink<R2, E, A>): Effect.Effect<Scope | R | R2, never, void> {
|
|
37
|
-
return Effect.
|
|
38
|
-
if (Option.isSome(this.current
|
|
37
|
+
return Effect.suspend(() => {
|
|
38
|
+
if (Option.isSome(MutableRef.get(this.current))) {
|
|
39
39
|
return pipe(
|
|
40
40
|
this.scheduleFlush(sink),
|
|
41
41
|
Effect.flatMap(() => super.run(sink)),
|
|
@@ -47,7 +47,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
event(a: A) {
|
|
50
|
-
return Effect.
|
|
50
|
+
return Effect.suspend(() => {
|
|
51
51
|
this.addValue(a)
|
|
52
52
|
|
|
53
53
|
return pipe(
|
|
@@ -58,7 +58,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
error(cause: Cause.Cause<E>) {
|
|
61
|
-
return Effect.
|
|
61
|
+
return Effect.suspend(() =>
|
|
62
62
|
pipe(
|
|
63
63
|
this.flushPending(),
|
|
64
64
|
Effect.flatMap(() => super.error(cause)),
|
|
@@ -67,7 +67,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
get end() {
|
|
70
|
-
return Effect.
|
|
70
|
+
return Effect.suspend(() =>
|
|
71
71
|
pipe(
|
|
72
72
|
this.flushPending(),
|
|
73
73
|
Effect.flatMap(() => super.end),
|
|
@@ -76,11 +76,12 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
protected scheduleFlush(sink: Fx.Sink<any, E, A>) {
|
|
79
|
-
return Effect.
|
|
79
|
+
return Effect.suspend(() => {
|
|
80
80
|
this.pendingSinks.push([
|
|
81
81
|
sink,
|
|
82
82
|
pipe(
|
|
83
|
-
this.current
|
|
83
|
+
this.current,
|
|
84
|
+
MutableRef.get,
|
|
84
85
|
Option.match(
|
|
85
86
|
() => [],
|
|
86
87
|
(a) => [a],
|
|
@@ -137,7 +138,7 @@ export class HoldFx<R, E, A> extends MulticastFx<R, E, A> implements Fx<R, E, A>
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
protected addValue(a: A) {
|
|
140
|
-
this.current
|
|
141
|
+
MutableRef.set(this.current, Option.some(a))
|
|
141
142
|
this.pendingSinks.forEach(([, events]) => events.push(a))
|
|
142
143
|
}
|
|
143
144
|
}
|
package/src/operator/loop.ts
CHANGED
|
@@ -55,13 +55,13 @@ export class MulticastFx<R, E, A>
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
event(a: A) {
|
|
58
|
-
return Effect.
|
|
58
|
+
return Effect.suspend(() =>
|
|
59
59
|
Effect.forEachDiscard(this.observers.slice(), (observer) => this.runEvent(a, observer)),
|
|
60
60
|
)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
error(cause: Cause<E>) {
|
|
64
|
-
return Effect.
|
|
64
|
+
return Effect.suspend(() =>
|
|
65
65
|
pipe(
|
|
66
66
|
Effect.forEachDiscard(this.observers.slice(), (observer) => this.runError(cause, observer)),
|
|
67
67
|
Effect.tap(() => this.cleanup()),
|
|
@@ -70,7 +70,7 @@ export class MulticastFx<R, E, A>
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
get end(): Effect.Effect<never, never, void> {
|
|
73
|
-
return Effect.
|
|
73
|
+
return Effect.suspend(() =>
|
|
74
74
|
pipe(
|
|
75
75
|
this.observers.slice(),
|
|
76
76
|
Effect.forEachDiscard((observer) => this.runEnd(observer)),
|
|
@@ -4,18 +4,22 @@ import * as Effect from '@effect/io/Effect'
|
|
|
4
4
|
|
|
5
5
|
import { Fx } from '../Fx.js'
|
|
6
6
|
|
|
7
|
-
export function provideService<S>(tag: Context.Tag<S>) {
|
|
7
|
+
export function provideService<I, S>(tag: Context.Tag<I, S>) {
|
|
8
8
|
return (service: S) => {
|
|
9
|
-
return <R, E, A>(self: Fx<R |
|
|
9
|
+
return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R, I>, E, A> =>
|
|
10
10
|
new ProvideServiceFx(self, tag, service)
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
class ProvideServiceFx<R, E, A, S>
|
|
15
|
-
extends Fx.Variance<Exclude<R,
|
|
16
|
-
implements Fx<Exclude<R,
|
|
14
|
+
class ProvideServiceFx<R, E, A, I, S>
|
|
15
|
+
extends Fx.Variance<Exclude<R, I>, E, A>
|
|
16
|
+
implements Fx<Exclude<R, I>, E, A>
|
|
17
17
|
{
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
readonly self: Fx<R | I, E, A>,
|
|
20
|
+
readonly tag: Context.Tag<I, S>,
|
|
21
|
+
readonly service: S,
|
|
22
|
+
) {
|
|
19
23
|
super()
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -5,21 +5,21 @@ import type { Scope } from '@effect/io/Scope'
|
|
|
5
5
|
|
|
6
6
|
import { Fx } from '../Fx.js'
|
|
7
7
|
|
|
8
|
-
export function provideServiceEffect<S, R2, E2>(
|
|
9
|
-
tag: Context.Tag<S>,
|
|
8
|
+
export function provideServiceEffect<I, S, R2, E2>(
|
|
9
|
+
tag: Context.Tag<I, S>,
|
|
10
10
|
service: Effect.Effect<R2, E2, S>,
|
|
11
11
|
) {
|
|
12
|
-
return <R, E, A>(self: Fx<R |
|
|
12
|
+
return <R, E, A>(self: Fx<R | I, E, A>): Fx<Exclude<R | R2, I>, E | E2, A> =>
|
|
13
13
|
new ProvideServiceEffectFx(self, tag, service)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
class ProvideServiceEffectFx<R, E, A, R2, E2, S>
|
|
17
|
-
extends Fx.Variance<Exclude<R | R2,
|
|
18
|
-
implements Fx<Exclude<R | R2,
|
|
16
|
+
class ProvideServiceEffectFx<R, E, A, R2, E2, I, S>
|
|
17
|
+
extends Fx.Variance<Exclude<R | R2, I>, E | E2, A>
|
|
18
|
+
implements Fx<Exclude<R | R2, I>, E | E2, A>
|
|
19
19
|
{
|
|
20
20
|
constructor(
|
|
21
|
-
readonly self: Fx<R |
|
|
22
|
-
readonly tag: Context.Tag<S>,
|
|
21
|
+
readonly self: Fx<R | I, E, A>,
|
|
22
|
+
readonly tag: Context.Tag<I, S>,
|
|
23
23
|
readonly service: Effect.Effect<R2, E2, S>,
|
|
24
24
|
) {
|
|
25
25
|
super()
|
|
@@ -30,6 +30,6 @@ class ProvideServiceEffectFx<R, E, A, R2, E2, S>
|
|
|
30
30
|
this.self.run(sink),
|
|
31
31
|
Effect.provideServiceEffect(this.tag, this.service),
|
|
32
32
|
Effect.matchCauseEffect(sink.error, Effect.succeed),
|
|
33
|
-
) as Effect.Effect<Exclude<R | R2 | R3 | Scope,
|
|
33
|
+
) as Effect.Effect<Exclude<R | R2 | R3 | Scope, I>, never, unknown>
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/operator/race.ts
CHANGED
|
@@ -57,7 +57,7 @@ class RaceAllFx<Streams extends readonly Fx<any, any, any>[]>
|
|
|
57
57
|
run(sink.event, sink.error, sink.end),
|
|
58
58
|
Effect.scheduleForked(asap), // Schedule starts so that all Scopes can be returned *before* attempting to cleanup
|
|
59
59
|
Effect.as(scope),
|
|
60
|
-
Effect.provideService(Scope.
|
|
60
|
+
Effect.provideService(Scope.Scope, scope),
|
|
61
61
|
),
|
|
62
62
|
),
|
|
63
63
|
),
|
|
@@ -22,13 +22,13 @@ class SkipRepeatsWithFx<R, E, A> extends Fx.Variance<R, E, A> implements Fx<R, E
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
run<R2>(sink: Fx.Sink<R2, E, A>) {
|
|
25
|
-
return Effect.
|
|
25
|
+
return Effect.suspend(() => {
|
|
26
26
|
let previous: Option.Option<A> = Option.none()
|
|
27
27
|
|
|
28
28
|
return this.self.run({
|
|
29
29
|
...sink,
|
|
30
30
|
event: (a) =>
|
|
31
|
-
Effect.
|
|
31
|
+
Effect.suspend(() => {
|
|
32
32
|
if (Option.isNone(previous) || !this.equals(previous.value, a)) {
|
|
33
33
|
previous = Option.some(a)
|
|
34
34
|
|
|
@@ -49,7 +49,7 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
|
|
|
49
49
|
|
|
50
50
|
let firstError = true
|
|
51
51
|
|
|
52
|
-
const handleError = Effect.
|
|
52
|
+
const handleError = Effect.suspend(() =>
|
|
53
53
|
firstError ? ((firstError = false), Effect.asUnit(counter.decrement)) : Effect.unit(),
|
|
54
54
|
)
|
|
55
55
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { pipe } from '@effect/data/Function'
|
|
2
2
|
import { match } from '@effect/data/Option'
|
|
3
|
+
import * as Chunk from '@effect/data/Chunk'
|
|
3
4
|
import * as Cause from '@effect/io/Cause'
|
|
4
5
|
import * as Effect from '@effect/io/Effect'
|
|
5
6
|
|
|
@@ -14,7 +15,7 @@ export function tapDefect<R2, E2, B>(f: (defect: unknown) => Effect.Effect<R2, E
|
|
|
14
15
|
tapCause(
|
|
15
16
|
(cause): Effect.Effect<R2, E | E2, B> =>
|
|
16
17
|
pipe(
|
|
17
|
-
Cause.defects(cause)
|
|
18
|
+
Chunk.get(Cause.defects(cause), 0),
|
|
18
19
|
match(() => Effect.failCause(cause), f),
|
|
19
20
|
),
|
|
20
21
|
),
|
package/src/run/collectAll.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Fx } from '../Fx.js'
|
|
|
6
6
|
import { reduce } from './reduce.js'
|
|
7
7
|
|
|
8
8
|
export const collectAll = <R, E, A>(fx: Fx<R, E, A>): Effect.Effect<R, E, readonly A[]> =>
|
|
9
|
-
Effect.
|
|
9
|
+
Effect.suspend(() =>
|
|
10
10
|
pipe(
|
|
11
11
|
fx,
|
|
12
12
|
reduce([] as A[], (acc, a) => {
|
package/src/run/collectN.ts
CHANGED
package/src/run/reduce.ts
CHANGED