@typed/fx 1.5.7 → 1.5.8

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.
Files changed (96) hide show
  1. package/dist/_internal/matchInterruptCause.d.ts +11 -0
  2. package/dist/_internal/matchInterruptCause.d.ts.map +1 -0
  3. package/dist/_internal/matchInterruptCause.js +6 -0
  4. package/dist/_internal/matchInterruptCause.js.map +1 -0
  5. package/dist/cjs/_internal/matchInterruptCause.d.ts +11 -0
  6. package/dist/cjs/_internal/matchInterruptCause.d.ts.map +1 -0
  7. package/dist/cjs/_internal/matchInterruptCause.js +32 -0
  8. package/dist/cjs/_internal/matchInterruptCause.js.map +1 -0
  9. package/dist/cjs/operator/combine.d.ts.map +1 -1
  10. package/dist/cjs/operator/combine.js +2 -1
  11. package/dist/cjs/operator/combine.js.map +1 -1
  12. package/dist/cjs/operator/debounce.d.ts.map +1 -1
  13. package/dist/cjs/operator/debounce.js +2 -2
  14. package/dist/cjs/operator/debounce.js.map +1 -1
  15. package/dist/cjs/operator/exhaustMap.js +2 -4
  16. package/dist/cjs/operator/exhaustMap.js.map +1 -1
  17. package/dist/cjs/operator/exhaustMapLatest.js +1 -1
  18. package/dist/cjs/operator/exhaustMapLatest.js.map +1 -1
  19. package/dist/cjs/operator/flatMap.js +1 -1
  20. package/dist/cjs/operator/flatMap.js.map +1 -1
  21. package/dist/cjs/operator/flatMapCause.js +1 -1
  22. package/dist/cjs/operator/flatMapCause.js.map +1 -1
  23. package/dist/cjs/operator/mergeRace.js +1 -1
  24. package/dist/cjs/operator/mergeRace.js.map +1 -1
  25. package/dist/cjs/operator/snapshot.js +1 -1
  26. package/dist/cjs/operator/snapshot.js.map +1 -1
  27. package/dist/cjs/operator/snapshotEffect.js +1 -1
  28. package/dist/cjs/operator/snapshotEffect.js.map +1 -1
  29. package/dist/cjs/operator/switchMap.d.ts.map +1 -1
  30. package/dist/cjs/operator/switchMap.js +3 -2
  31. package/dist/cjs/operator/switchMap.js.map +1 -1
  32. package/dist/cjs/operator/switchMapCause.d.ts.map +1 -1
  33. package/dist/cjs/operator/switchMapCause.js +2 -4
  34. package/dist/cjs/operator/switchMapCause.js.map +1 -1
  35. package/dist/cjs/operator/switchMatch.d.ts.map +1 -1
  36. package/dist/cjs/operator/switchMatch.js +2 -3
  37. package/dist/cjs/operator/switchMatch.js.map +1 -1
  38. package/dist/cjs/operator/zip.d.ts.map +1 -1
  39. package/dist/cjs/operator/zip.js +2 -1
  40. package/dist/cjs/operator/zip.js.map +1 -1
  41. package/dist/cjs/run/run.d.ts.map +1 -1
  42. package/dist/cjs/run/run.js +3 -2
  43. package/dist/cjs/run/run.js.map +1 -1
  44. package/dist/operator/combine.d.ts.map +1 -1
  45. package/dist/operator/combine.js +2 -1
  46. package/dist/operator/combine.js.map +1 -1
  47. package/dist/operator/debounce.d.ts.map +1 -1
  48. package/dist/operator/debounce.js +2 -2
  49. package/dist/operator/debounce.js.map +1 -1
  50. package/dist/operator/exhaustMap.js +2 -4
  51. package/dist/operator/exhaustMap.js.map +1 -1
  52. package/dist/operator/exhaustMapLatest.js +1 -1
  53. package/dist/operator/exhaustMapLatest.js.map +1 -1
  54. package/dist/operator/flatMap.js +1 -1
  55. package/dist/operator/flatMap.js.map +1 -1
  56. package/dist/operator/flatMapCause.js +1 -1
  57. package/dist/operator/flatMapCause.js.map +1 -1
  58. package/dist/operator/mergeRace.js +1 -1
  59. package/dist/operator/mergeRace.js.map +1 -1
  60. package/dist/operator/snapshot.js +1 -1
  61. package/dist/operator/snapshot.js.map +1 -1
  62. package/dist/operator/snapshotEffect.js +1 -1
  63. package/dist/operator/snapshotEffect.js.map +1 -1
  64. package/dist/operator/switchMap.d.ts.map +1 -1
  65. package/dist/operator/switchMap.js +3 -2
  66. package/dist/operator/switchMap.js.map +1 -1
  67. package/dist/operator/switchMapCause.d.ts.map +1 -1
  68. package/dist/operator/switchMapCause.js +3 -5
  69. package/dist/operator/switchMapCause.js.map +1 -1
  70. package/dist/operator/switchMatch.d.ts.map +1 -1
  71. package/dist/operator/switchMatch.js +2 -3
  72. package/dist/operator/switchMatch.js.map +1 -1
  73. package/dist/operator/zip.d.ts.map +1 -1
  74. package/dist/operator/zip.js +2 -1
  75. package/dist/operator/zip.js.map +1 -1
  76. package/dist/run/run.d.ts.map +1 -1
  77. package/dist/run/run.js +3 -2
  78. package/dist/run/run.js.map +1 -1
  79. package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
  80. package/package.json +2 -2
  81. package/src/_internal/matchInterruptCause.ts +50 -0
  82. package/src/operator/combine.ts +2 -1
  83. package/src/operator/debounce.ts +6 -5
  84. package/src/operator/exhaustMap.ts +3 -5
  85. package/src/operator/exhaustMapLatest.ts +1 -1
  86. package/src/operator/flatMap.ts +1 -1
  87. package/src/operator/flatMapCause.ts +1 -1
  88. package/src/operator/mergeRace.ts +1 -1
  89. package/src/operator/snapshot.ts +1 -1
  90. package/src/operator/snapshotEffect.ts +1 -1
  91. package/src/operator/switchMap.ts +7 -0
  92. package/src/operator/switchMapCause.ts +3 -9
  93. package/src/operator/switchMatch.ts +4 -8
  94. package/src/operator/zip.ts +2 -1
  95. package/src/run/run.ts +4 -2
  96. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,50 @@
1
+ import { dualWithTrace } from '@effect/data/Debug'
2
+ import * as Cause from '@effect/io/Cause'
3
+ import * as Effect from '@effect/io/Effect'
4
+
5
+ export const matchInterruptCause: {
6
+ <E, A, R2, E2, B, R3, E3, C, R4, E4, D>(
7
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
8
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
9
+ onSuccess: (a: A) => Effect.Effect<R4, E4, D>,
10
+ ): <R>(effect: Effect.Effect<R, E, A>) => Effect.Effect<R | R2 | R3 | R4, E2 | E3 | E4, B | C | D>
11
+ <R, E, A, R2, E2, B, R3, E3, C, R4, E4, D>(
12
+ effect: Effect.Effect<R, E, A>,
13
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
14
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
15
+ onSuccess: (a: A) => Effect.Effect<R4, E4, D>,
16
+ ): Effect.Effect<R | R2 | R3 | R4, E2 | E3 | E4, B | C | D>
17
+ } = dualWithTrace(
18
+ 4,
19
+ (trace) =>
20
+ <R, E, A, R2, E2, B, R3, E3, C, R4, E4, D>(
21
+ effect: Effect.Effect<R, E, A>,
22
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
23
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
24
+ onSuccess: (a: A) => Effect.Effect<R4, E4, D>,
25
+ ): Effect.Effect<R | R2 | R3 | R4, E2 | E3 | E4, B | C | D> =>
26
+ Effect.matchCauseEffect(effect, splitInterrupt(onCause, onInterrupt), onSuccess).traced(
27
+ trace,
28
+ ),
29
+ )
30
+
31
+ export const splitInterrupt: {
32
+ <E, R2, E2, B, R3, E3, C>(
33
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
34
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
35
+ ): (cause: Cause.Cause<E>) => Effect.Effect<R2 | R3, E2 | E3, B | C>
36
+ <E, R2, E2, B, R3, E3, C>(
37
+ cause: Cause.Cause<E>,
38
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
39
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
40
+ ): Effect.Effect<R2 | R3, E2 | E3, B | C>
41
+ } = dualWithTrace(
42
+ 3,
43
+ (trace) =>
44
+ <E, R2, E2, B, R3, E3, C>(
45
+ cause: Cause.Cause<E>,
46
+ onCause: (cause: Cause.Cause<E>) => Effect.Effect<R2, E2, B>,
47
+ onInterrupt: () => Effect.Effect<R3, E3, C>,
48
+ ): Effect.Effect<R2 | R3, E2 | E3, B | C> =>
49
+ (Cause.isInterruptedOnly(cause) ? onInterrupt() : onCause(cause)).traced(trace),
50
+ )
@@ -3,6 +3,7 @@ import * as Effect from '@effect/io/Effect'
3
3
 
4
4
  import { Fx } from '../Fx.js'
5
5
  import { withRefCounter } from '../_internal/RefCounter.js'
6
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
6
7
 
7
8
  export function combineAll<Streams extends readonly Fx<any, any, any>[]>(
8
9
  ...streams: Streams
@@ -75,7 +76,7 @@ class CombineAllFx<Streams extends readonly Fx<any, any, any>[]>
75
76
  Effect.sync(() => results.set(i, a)),
76
77
  Effect.zipRight(emitIfReady),
77
78
  ),
78
- sink.error,
79
+ splitInterrupt(sink.error, () => counter.decrement),
79
80
  counter.decrement,
80
81
  ),
81
82
  ),
@@ -1,11 +1,11 @@
1
1
  import type * as Duration from '@effect/data/Duration'
2
2
  import { pipe } from '@effect/data/Function'
3
- import * as Cause from '@effect/io/Cause'
4
3
  import * as Effect from '@effect/io/Effect'
5
4
  import * as Fiber from '@effect/io/Fiber'
6
5
 
7
6
  import { Fx } from '../Fx.js'
8
7
  import { withRefCounter } from '../_internal/RefCounter.js'
8
+ import { matchInterruptCause } from '../_internal/matchInterruptCause.js'
9
9
 
10
10
  export function debounce(duration: Duration.Duration) {
11
11
  return <R, E, A>(fx: Fx<R, E, A>): Fx<R, E, A> => new DebounceFx(fx, duration)
@@ -36,11 +36,12 @@ class DebounceFx<R, E, A> extends Fx.Variance<R, E, A> implements Fx<R, E, A> {
36
36
  sink.event(a),
37
37
  Effect.delay(duration),
38
38
  Effect.interruptible,
39
- Effect.zipRight(counter.decrement),
40
- Effect.uninterruptible,
41
- Effect.onError((cause) =>
42
- Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
39
+ matchInterruptCause(
40
+ sink.error,
41
+ () => counter.decrement,
42
+ () => counter.decrement,
43
43
  ),
44
+ Effect.uninterruptible,
44
45
  Effect.forkScoped,
45
46
  Effect.tap((fiber) =>
46
47
  Effect.sync(() => {
@@ -1,12 +1,12 @@
1
1
  import { dual, pipe } from '@effect/data/Function'
2
2
  import type { FlatMap } from '@effect/data/typeclass/FlatMap'
3
- import * as Cause from '@effect/io/Cause'
4
3
  import * as Effect from '@effect/io/Effect'
5
4
  import type * as Fiber from '@effect/io/Fiber'
6
5
  import * as Ref from '@effect/io/Ref/Synchronized'
7
6
 
8
7
  import { Fx } from '../Fx.js'
9
8
  import { withRefCounter } from '../_internal/RefCounter.js'
9
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
10
10
  import type { FxTypeLambda } from '../typeclass/TypeLambda.js'
11
11
 
12
12
  export const exhaustMap: FlatMap<FxTypeLambda>['flatMap'] = dual(
@@ -51,10 +51,8 @@ class ExhaustMapFx<R, E, A, R2, E2, B>
51
51
  pipe(resetRef, Effect.zipRight(counter.decrement)),
52
52
  ),
53
53
  ),
54
- Effect.onError((cause) =>
55
- Cause.isInterruptedOnly(cause)
56
- ? Effect.unit()
57
- : sink.error(cause),
54
+ Effect.catchAllCause(
55
+ splitInterrupt(sink.error, () => counter.decrement),
58
56
  ),
59
57
  ),
60
58
  ),
@@ -55,7 +55,7 @@ class ExhaustMapLatestFx<R, E, A, R2, E2, B>
55
55
  pipe(resetRef, Effect.zipRight(runNextFx)),
56
56
  ),
57
57
  ),
58
- Effect.onError((e) =>
58
+ Effect.catchAllCause((e) =>
59
59
  Cause.isInterruptedOnly(e)
60
60
  ? resetRef
61
61
  : pipe(resetRef, Effect.zipRight(sink.error(e))),
@@ -35,7 +35,7 @@ class FlatMapFx<R, E, A, R2, E2, B>
35
35
  Effect.flatMap(() =>
36
36
  this.f(a).run(Fx.Sink(sink.event, sink.error, counter.decrement)),
37
37
  ),
38
- Effect.onError((cause) =>
38
+ Effect.catchAllCause((cause) =>
39
39
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
40
40
  ),
41
41
  Effect.forkScoped,
@@ -32,7 +32,7 @@ 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) =>
35
+ Effect.catchAllCause((cause) =>
36
36
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
37
37
  ),
38
38
  Effect.forkScoped,
@@ -20,7 +20,7 @@ export function mergeRace<R2, E2, B>(raced: Fx<R2, E2, B>) {
20
20
  const racedFiber = yield* $(
21
21
  pipe(
22
22
  raced.run(Fx.Sink(sink.event, sink.error, Effect.unit())),
23
- Effect.onError((cause) =>
23
+ Effect.catchAllCause((cause) =>
24
24
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
25
25
  ),
26
26
  Effect.forkScoped,
@@ -33,7 +33,7 @@ class SnapshotFx<R, E, A, R2, E2, B, C>
33
33
  pipe(
34
34
  sampled,
35
35
  run((b) => pipe(ref, Ref.set(Option.some(b))), sink.error, Effect.unit()),
36
- Effect.onError((cause) =>
36
+ Effect.catchAllCause((cause) =>
37
37
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
38
38
  ),
39
39
  Effect.forkScoped,
@@ -37,7 +37,7 @@ class SnapshotEffectFx<R, E, A, R2, E2, B, R3, E3, C>
37
37
  pipe(
38
38
  sampled,
39
39
  run((b) => pipe(ref, Ref.set(Option.some(b))), sink.error, Effect.unit()),
40
- Effect.onError((cause) =>
40
+ Effect.catchAllCause((cause) =>
41
41
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
42
42
  ),
43
43
  Effect.forkScoped,
@@ -7,6 +7,7 @@ import * as Ref from '@effect/io/Ref/Synchronized'
7
7
 
8
8
  import { Fx } from '../Fx.js'
9
9
  import { withRefCounter } from '../_internal/RefCounter.js'
10
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
10
11
  import type { FxTypeLambda } from '../typeclass/TypeLambda.js'
11
12
 
12
13
  export const switchMap: FlatMap<FxTypeLambda>['flatMap'] = dual(
@@ -64,6 +65,11 @@ class SwitchMapFx<R, E, A, R2, E2, B>
64
65
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
65
66
  ),
66
67
  ),
68
+ Effect.catchAllCause(
69
+ splitInterrupt(sink.error, () =>
70
+ pipe(resetRef, Effect.zipRight(counter.decrement)),
71
+ ),
72
+ ),
67
73
  Effect.forkScoped,
68
74
  ),
69
75
  ),
@@ -75,6 +81,7 @@ class SwitchMapFx<R, E, A, R2, E2, B>
75
81
  ),
76
82
  )
77
83
  }),
84
+ Effect.catchAllCause(splitInterrupt(sink.error, () => counter.decrement)),
78
85
  ),
79
86
  sink.end,
80
87
  )
@@ -1,4 +1,4 @@
1
- import { flow, pipe } from '@effect/data/Function'
1
+ import { pipe } from '@effect/data/Function'
2
2
  import * as Cause from '@effect/io/Cause'
3
3
  import * as Effect from '@effect/io/Effect'
4
4
  import * as Fiber from '@effect/io/Fiber'
@@ -6,6 +6,7 @@ import * as Ref from '@effect/io/Ref/Synchronized'
6
6
 
7
7
  import { Fx } from '../Fx.js'
8
8
  import { withRefCounter } from '../_internal/RefCounter.js'
9
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
9
10
 
10
11
  import { catchTag_ } from './catchTag.js'
11
12
 
@@ -65,14 +66,7 @@ class SwitchMapCauseFx<R, E, A, R2, E2, B>
65
66
  this.f(cause).run(
66
67
  Fx.Sink(
67
68
  sink.event,
68
- flow(
69
- Effect.unified((cause) =>
70
- Cause.isInterruptedOnly(cause)
71
- ? counter.decrement
72
- : sink.error(cause),
73
- ),
74
- Effect.zipLeft(resetRef),
75
- ),
69
+ splitInterrupt(sink.error, () => counter.decrement),
76
70
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
77
71
  ),
78
72
  ),
@@ -7,6 +7,7 @@ import * as Ref from '@effect/io/Ref/Synchronized'
7
7
 
8
8
  import { Fx } from '../Fx.js'
9
9
  import { withRefCounter } from '../_internal/RefCounter.js'
10
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
10
11
  import { failCause } from '../constructor/failCause.js'
11
12
 
12
13
  export function switchMatchCause<E, R2, E2, B, A, R3, E3, C>(
@@ -67,18 +68,13 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
67
68
  fx.run(
68
69
  Fx.Sink(
69
70
  sink.event,
70
- flow(
71
- Effect.unified((cause) =>
72
- Cause.isInterruptedOnly(cause)
73
- ? counter.decrement
74
- : sink.error(cause),
75
- ),
76
- Effect.zipLeft(resetRef),
71
+ splitInterrupt(sink.error, () =>
72
+ Effect.zip(counter.decrement, resetRef),
77
73
  ),
78
74
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
79
75
  ),
80
76
  ),
81
- Effect.onError((cause) =>
77
+ Effect.catchAllCause((cause) =>
82
78
  Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
83
79
  ),
84
80
  Effect.forkScoped,
@@ -3,6 +3,7 @@ import * as Effect from '@effect/io/Effect'
3
3
 
4
4
  import { Fx } from '../Fx.js'
5
5
  import { withRefCounter } from '../_internal/RefCounter.js'
6
+ import { splitInterrupt } from '../_internal/matchInterruptCause.js'
6
7
 
7
8
  export function zipAll<Streams extends readonly Fx<any, any, any>[]>(
8
9
  ...streams: Streams
@@ -79,7 +80,7 @@ class ZipAllFx<Streams extends readonly Fx<any, any, any>[]>
79
80
  Effect.sync(() => results.set(i, a)),
80
81
  Effect.zipRight(emitIfReady),
81
82
  ),
82
- sink.error,
83
+ splitInterrupt(sink.error, () => counter.decrement),
83
84
  counter.decrement,
84
85
  ),
85
86
  ),
package/src/run/run.ts CHANGED
@@ -6,6 +6,7 @@ import * as Fiber from '@effect/io/Fiber'
6
6
  import type { Scope } from '@effect/io/Scope'
7
7
 
8
8
  import { Fx, Sink } from '../Fx.js'
9
+ import { matchInterruptCause } from '../_internal/matchInterruptCause.js'
9
10
 
10
11
  export function run<A, R2, E2, E, R3, E3, B, R4, E4>(
11
12
  event: (a: A) => Effect.Effect<R2, E2, any>,
@@ -26,11 +27,12 @@ export function run_<A, R2, E2, E, R3, E3, B, R4, E4>(
26
27
  const sink = Sink(
27
28
  flow(
28
29
  event,
29
- Effect.matchCauseEffect(
30
+ matchInterruptCause(
30
31
  (cause) =>
31
32
  Effect.sync(() =>
32
33
  Deferred.unsafeDone<E2 | E3 | E4, B>(deferred, Effect.failCause(cause)),
33
34
  ),
35
+ () => pipe(end, Effect.intoDeferred(deferred)),
34
36
  Effect.unit,
35
37
  ),
36
38
  ),
@@ -41,7 +43,7 @@ export function run_<A, R2, E2, E, R3, E3, B, R4, E4>(
41
43
  const fiber = yield* $(
42
44
  pipe(
43
45
  fx.run(sink),
44
- Effect.onError((cause) =>
46
+ Effect.catchAllCause((cause) =>
45
47
  Effect.sync(() =>
46
48
  Cause.isInterruptedOnly(cause)
47
49
  ? null