@typed/fx 1.0.8 → 1.0.10
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/Fx.d.ts +3 -0
- package/dist/Fx.d.ts.map +1 -1
- package/dist/Fx.js.map +1 -1
- package/dist/operator/debounce.d.ts.map +1 -1
- package/dist/operator/debounce.js +2 -1
- package/dist/operator/debounce.js.map +1 -1
- package/dist/operator/exhaustMap.d.ts.map +1 -1
- package/dist/operator/exhaustMap.js +4 -1
- package/dist/operator/exhaustMap.js.map +1 -1
- package/dist/operator/exhaustMapLatest.d.ts.map +1 -1
- package/dist/operator/exhaustMapLatest.js +4 -1
- package/dist/operator/exhaustMapLatest.js.map +1 -1
- package/dist/operator/flatMap.d.ts.map +1 -1
- package/dist/operator/flatMap.js +2 -1
- package/dist/operator/flatMap.js.map +1 -1
- package/dist/operator/flatMapCause.d.ts +2 -2
- package/dist/operator/flatMapCause.d.ts.map +1 -1
- package/dist/operator/flatMapCause.js +2 -1
- package/dist/operator/flatMapCause.js.map +1 -1
- package/dist/operator/mergeRace.d.ts.map +1 -1
- package/dist/operator/mergeRace.js +3 -1
- package/dist/operator/mergeRace.js.map +1 -1
- package/dist/operator/snapshot.d.ts.map +1 -1
- package/dist/operator/snapshot.js +2 -1
- package/dist/operator/snapshot.js.map +1 -1
- package/dist/operator/snapshotEffect.d.ts.map +1 -1
- package/dist/operator/snapshotEffect.js +2 -1
- package/dist/operator/snapshotEffect.js.map +1 -1
- package/dist/operator/switchMap.d.ts.map +1 -1
- package/dist/operator/switchMap.js +2 -1
- package/dist/operator/switchMap.js.map +1 -1
- package/dist/operator/switchMatch.js +3 -3
- package/dist/operator/switchMatch.js.map +1 -1
- package/dist/run/run.d.ts +3 -3
- package/dist/run/run.d.ts.map +1 -1
- package/dist/run/run.js +4 -1
- package/dist/run/run.js.map +1 -1
- package/package.json +3 -3
- package/src/Fx.ts +3 -0
- package/src/operator/debounce.ts +4 -0
- package/src/operator/during.test.ts +4 -3
- package/src/operator/exhaustMap.ts +13 -5
- package/src/operator/exhaustMapLatest.ts +13 -5
- package/src/operator/flatMap.ts +4 -0
- package/src/operator/flatMapCause.ts +6 -3
- package/src/operator/mergeRace.ts +9 -1
- package/src/operator/since.test.ts +48 -48
- package/src/operator/snapshot.ts +4 -0
- package/src/operator/snapshotEffect.ts +4 -0
- package/src/operator/switchMap.ts +6 -1
- package/src/operator/switchMatch.ts +7 -3
- package/src/operator/until.test.ts +48 -47
- package/src/run/run.ts +16 -4
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
2
2
|
import * as Effect from '@effect/io/Effect'
|
|
3
3
|
import { pipe } from '@fp-ts/data/Function'
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ import { Fx } from '../Fx.js'
|
|
|
6
6
|
import { withRefCounter } from '../_internal/RefCounter.js'
|
|
7
7
|
|
|
8
8
|
export function flatMapCause<E, R2, E2, B>(
|
|
9
|
-
f: (cause: Cause<E>) => Fx<R2, E2, B>,
|
|
9
|
+
f: (cause: Cause.Cause<E>) => Fx<R2, E2, B>,
|
|
10
10
|
): <R, A>(fx: Fx<R, E, A>) => Fx<R | R2, E | E2, A | B> {
|
|
11
11
|
return (fx) => new FlatMapCauseFx(fx, f)
|
|
12
12
|
}
|
|
@@ -15,7 +15,7 @@ class FlatMapCauseFx<R, E, A, R2, E2, B>
|
|
|
15
15
|
extends Fx.Variance<R | R2, E | E2, B>
|
|
16
16
|
implements Fx<R | R2, E | E2, A | B>
|
|
17
17
|
{
|
|
18
|
-
constructor(readonly fx: Fx<R, E, A>, readonly f: (cause: Cause<E>) => Fx<R2, E2, B>) {
|
|
18
|
+
constructor(readonly fx: Fx<R, E, A>, readonly f: (cause: Cause.Cause<E>) => Fx<R2, E2, B>) {
|
|
19
19
|
super()
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -32,6 +32,9 @@ class FlatMapCauseFx<R, E, A, R2, E2, B>
|
|
|
32
32
|
Effect.flatMap(() =>
|
|
33
33
|
this.f(cause).run(Fx.Sink(sink.event, sink.error, counter.decrement)),
|
|
34
34
|
),
|
|
35
|
+
Effect.onError((cause) =>
|
|
36
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
37
|
+
),
|
|
35
38
|
Effect.forkScoped,
|
|
36
39
|
),
|
|
37
40
|
counter.decrement,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
1
2
|
import * as Effect from '@effect/io/Effect'
|
|
2
3
|
import * as Fiber from '@effect/io/Fiber'
|
|
4
|
+
import { pipe } from '@fp-ts/data/Function'
|
|
3
5
|
|
|
4
6
|
import { Fx } from '../Fx.js'
|
|
5
7
|
|
|
@@ -16,7 +18,13 @@ export function mergeRace<R2, E2, B>(raced: Fx<R2, E2, B>) {
|
|
|
16
18
|
Effect.gen(function* ($) {
|
|
17
19
|
let interrupted = false
|
|
18
20
|
const racedFiber = yield* $(
|
|
19
|
-
|
|
21
|
+
pipe(
|
|
22
|
+
raced.run(Fx.Sink(sink.event, sink.error, Effect.unit())),
|
|
23
|
+
Effect.onError((cause) =>
|
|
24
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
25
|
+
),
|
|
26
|
+
Effect.forkScoped,
|
|
27
|
+
),
|
|
20
28
|
)
|
|
21
29
|
|
|
22
30
|
return yield* $(
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
import { deepStrictEqual } from 'assert'
|
|
2
|
+
|
|
3
|
+
import * as Effect from '@effect/io/Effect'
|
|
4
|
+
import * as Fiber from '@effect/io/Fiber'
|
|
5
|
+
import * as TestClock from '@effect/test/TestClock'
|
|
6
|
+
import * as TE from '@effect/test/TestEnvironment'
|
|
7
|
+
import * as Duration from '@fp-ts/data/Duration'
|
|
8
|
+
import { pipe } from '@fp-ts/data/Function'
|
|
9
|
+
import { describe, it } from 'vitest'
|
|
10
|
+
|
|
11
|
+
import { at } from '../constructor/at.js'
|
|
12
|
+
import { periodic } from '../constructor/periodic.js'
|
|
13
|
+
import { collectAll } from '../run/collectAll.js'
|
|
14
|
+
|
|
15
|
+
import { since } from './since.js'
|
|
16
|
+
import { withItems } from './withItems.js'
|
|
17
|
+
|
|
18
|
+
// TODO: remove skip when @effect/test has been updated to latest @effect/io
|
|
19
|
+
describe.skip(import.meta.url, () => {
|
|
20
|
+
describe(since.name, () => {
|
|
21
|
+
it('interrupts a stream when a signal is received', async () => {
|
|
22
|
+
const delay = 20
|
|
23
|
+
const expected = 5
|
|
24
|
+
const fx = pipe(
|
|
25
|
+
periodic(Duration.millis(delay)),
|
|
26
|
+
withItems([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
|
|
27
|
+
since(at(Duration.millis(delay * expected), null)),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const test = pipe(
|
|
31
|
+
Effect.gen(function* ($) {
|
|
32
|
+
const fiber = yield* $(Effect.fork(collectAll(fx)))
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i <= expected * 2; i++) {
|
|
35
|
+
yield* $(TestClock.adjust(Duration.millis(delay)))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return yield* $(Fiber.join(fiber))
|
|
39
|
+
}),
|
|
40
|
+
Effect.provideSomeLayer(TE.TestEnvironment),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const events = await Effect.unsafeRunPromise(test)
|
|
44
|
+
|
|
45
|
+
deepStrictEqual(events, [6, 7, 8, 9, 10])
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
package/src/operator/snapshot.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
1
2
|
import * as Effect from '@effect/io/Effect'
|
|
2
3
|
import * as Ref from '@effect/io/Ref'
|
|
3
4
|
import { pipe } from '@fp-ts/data/Function'
|
|
@@ -32,6 +33,9 @@ class SnapshotFx<R, E, A, R2, E2, B, C>
|
|
|
32
33
|
pipe(
|
|
33
34
|
sampled,
|
|
34
35
|
run((b) => pipe(ref, Ref.set(Option.some(b))), sink.error, Effect.unit()),
|
|
36
|
+
Effect.onError((cause) =>
|
|
37
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
38
|
+
),
|
|
35
39
|
Effect.forkScoped,
|
|
36
40
|
),
|
|
37
41
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
1
2
|
import * as Effect from '@effect/io/Effect'
|
|
2
3
|
import * as Ref from '@effect/io/Ref/Synchronized'
|
|
3
4
|
import { pipe } from '@fp-ts/data/Function'
|
|
@@ -36,6 +37,9 @@ class SnapshotEffectFx<R, E, A, R2, E2, B, R3, E3, C>
|
|
|
36
37
|
pipe(
|
|
37
38
|
sampled,
|
|
38
39
|
run((b) => pipe(ref, Ref.set(Option.some(b))), sink.error, Effect.unit()),
|
|
40
|
+
Effect.onError((cause) =>
|
|
41
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
42
|
+
),
|
|
39
43
|
Effect.forkScoped,
|
|
40
44
|
),
|
|
41
45
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
1
2
|
import * as Effect from '@effect/io/Effect'
|
|
2
3
|
import * as Fiber from '@effect/io/Fiber'
|
|
3
4
|
import * as Ref from '@effect/io/Ref/Synchronized'
|
|
@@ -47,7 +48,7 @@ class SwitchMapFx<R, E, A, R2, E2, B>
|
|
|
47
48
|
: Effect.asUnit(counter.increment),
|
|
48
49
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
50
|
Effect.flatMap((_: unknown) =>
|
|
50
|
-
|
|
51
|
+
pipe(
|
|
51
52
|
this.f(a).run(
|
|
52
53
|
Fx.Sink(
|
|
53
54
|
sink.event,
|
|
@@ -55,6 +56,10 @@ class SwitchMapFx<R, E, A, R2, E2, B>
|
|
|
55
56
|
pipe(counter.decrement, Effect.zipLeft(resetRef)),
|
|
56
57
|
),
|
|
57
58
|
),
|
|
59
|
+
Effect.onError((cause) =>
|
|
60
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
61
|
+
),
|
|
62
|
+
Effect.forkScoped,
|
|
58
63
|
),
|
|
59
64
|
),
|
|
60
65
|
),
|
|
@@ -2,7 +2,7 @@ import * as Cause from '@effect/io/Cause'
|
|
|
2
2
|
import * as Effect from '@effect/io/Effect'
|
|
3
3
|
import * as Fiber from '@effect/io/Fiber'
|
|
4
4
|
import * as Ref from '@effect/io/Ref/Synchronized'
|
|
5
|
-
import
|
|
5
|
+
import * as Either from '@fp-ts/data/Either'
|
|
6
6
|
import { flow, pipe } from '@fp-ts/data/Function'
|
|
7
7
|
|
|
8
8
|
import { Fx } from '../Fx.js'
|
|
@@ -20,7 +20,7 @@ export function switchMatchError<E, R2, E2, B, A, R3, E3, C>(
|
|
|
20
20
|
f: (error: E) => Fx<R2, E2, B>,
|
|
21
21
|
g: (a: A) => Fx<R3, E3, C>,
|
|
22
22
|
): <R>(fx: Fx<R, E, A>) => Fx<R | R2 | R3, E2 | E3, B | C> {
|
|
23
|
-
return switchMatchCause(flow(Cause.failureOrCause,
|
|
23
|
+
return switchMatchCause(flow(Cause.failureOrCause, Either.match(f, failCause)), g)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
|
|
@@ -63,7 +63,7 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
|
|
|
63
63
|
: Effect.asUnit(counter.increment),
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
65
65
|
Effect.flatMap((_: unknown) =>
|
|
66
|
-
|
|
66
|
+
pipe(
|
|
67
67
|
fx.run(
|
|
68
68
|
Fx.Sink(
|
|
69
69
|
sink.event,
|
|
@@ -71,6 +71,10 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
|
|
|
71
71
|
pipe(counter.decrement, Effect.zipLeft(resetRef)),
|
|
72
72
|
),
|
|
73
73
|
),
|
|
74
|
+
Effect.onError((cause) =>
|
|
75
|
+
Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
|
|
76
|
+
),
|
|
77
|
+
Effect.forkScoped,
|
|
74
78
|
),
|
|
75
79
|
),
|
|
76
80
|
),
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
import { deepStrictEqual } from 'assert'
|
|
2
|
+
|
|
3
|
+
import * as Effect from '@effect/io/Effect'
|
|
4
|
+
import * as Fiber from '@effect/io/Fiber'
|
|
5
|
+
import * as TestClock from '@effect/test/TestClock'
|
|
6
|
+
import * as TE from '@effect/test/TestEnvironment'
|
|
7
|
+
import * as Duration from '@fp-ts/data/Duration'
|
|
8
|
+
import { pipe } from '@fp-ts/data/Function'
|
|
9
|
+
import { describe, it } from 'vitest'
|
|
10
|
+
|
|
11
|
+
import { at } from '../constructor/at.js'
|
|
12
|
+
import { periodic } from '../constructor/periodic.js'
|
|
13
|
+
import { collectAll } from '../run/collectAll.js'
|
|
14
|
+
|
|
15
|
+
import { until } from './until.js'
|
|
16
|
+
import { withItems } from './withItems.js'
|
|
17
|
+
|
|
18
|
+
// TODO: remove skip when @effect/test has been updated to latest @effect/io
|
|
19
|
+
describe.skip(import.meta.url, () => {
|
|
20
|
+
describe(until.name, () => {
|
|
21
|
+
it('interrupts a stream when a signal is received', async () => {
|
|
22
|
+
const delay = 20
|
|
23
|
+
const expected = 5
|
|
24
|
+
const fx = pipe(
|
|
25
|
+
periodic(Duration.millis(delay)),
|
|
26
|
+
withItems([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
|
|
27
|
+
until(at(Duration.millis(delay * expected), null)),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const test = pipe(
|
|
31
|
+
Effect.gen(function* ($) {
|
|
32
|
+
const fiber = yield* $(Effect.fork(collectAll(fx)))
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < expected; i++) {
|
|
35
|
+
yield* $(TestClock.adjust(Duration.millis(delay)))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return yield* $(Fiber.join(fiber))
|
|
39
|
+
}),
|
|
40
|
+
Effect.provideSomeLayer(TE.TestEnvironment),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const events = await Effect.unsafeRunPromise(test)
|
|
44
|
+
|
|
45
|
+
deepStrictEqual(events, [1, 2, 3, 4, 5])
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
package/src/run/run.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Cause from '@effect/io/Cause'
|
|
2
2
|
import * as Deferred from '@effect/io/Deferred'
|
|
3
3
|
import * as Effect from '@effect/io/Effect'
|
|
4
4
|
import * as Fiber from '@effect/io/Fiber'
|
|
@@ -9,7 +9,7 @@ import { Fx, Sink } from '../Fx.js'
|
|
|
9
9
|
|
|
10
10
|
export function run<A, R2, E2, E, R3, E3, B, R4, E4>(
|
|
11
11
|
event: (a: A) => Effect.Effect<R2, E2, any>,
|
|
12
|
-
error: (cause: Cause<E>) => Effect.Effect<R3, E3, B>,
|
|
12
|
+
error: (cause: Cause.Cause<E>) => Effect.Effect<R3, E3, B>,
|
|
13
13
|
end: Effect.Effect<R4, E4, B>,
|
|
14
14
|
): <R>(fx: Fx<R, E, A>) => Effect.Effect<R | R2 | R3 | R4, E2 | E3 | E4, B> {
|
|
15
15
|
return flow(run_(event, error, end), Effect.scoped)
|
|
@@ -17,7 +17,7 @@ export function run<A, R2, E2, E, R3, E3, B, R4, E4>(
|
|
|
17
17
|
|
|
18
18
|
export function run_<A, R2, E2, E, R3, E3, B, R4, E4>(
|
|
19
19
|
event: (a: A) => Effect.Effect<R2, E2, any>,
|
|
20
|
-
error: (cause: Cause<E>) => Effect.Effect<R3, E3, B>,
|
|
20
|
+
error: (cause: Cause.Cause<E>) => Effect.Effect<R3, E3, B>,
|
|
21
21
|
end: Effect.Effect<R4, E4, B>,
|
|
22
22
|
) {
|
|
23
23
|
return <R>(fx: Fx<R, E, A>): Effect.Effect<R | R2 | R3 | R4 | Scope, E2 | E3 | E4, B> =>
|
|
@@ -38,7 +38,19 @@ export function run_<A, R2, E2, E, R3, E3, B, R4, E4>(
|
|
|
38
38
|
pipe(end, Effect.intoDeferred(deferred)),
|
|
39
39
|
)
|
|
40
40
|
|
|
41
|
-
const fiber = yield* $(
|
|
41
|
+
const fiber = yield* $(
|
|
42
|
+
pipe(
|
|
43
|
+
fx.run(sink),
|
|
44
|
+
Effect.onError((cause) =>
|
|
45
|
+
Effect.sync(() =>
|
|
46
|
+
Cause.isInterruptedOnly(cause)
|
|
47
|
+
? null
|
|
48
|
+
: pipe(deferred, Deferred.unsafeDone<E2 | E3 | E4, B>(Effect.failCause(cause))),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
Effect.forkScoped,
|
|
52
|
+
),
|
|
53
|
+
)
|
|
42
54
|
|
|
43
55
|
const c = yield* $(Deferred.await(deferred))
|
|
44
56
|
|