@typed/fx 1.5.2 → 1.5.6

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 (65) hide show
  1. package/dist/_internal/Mutable.d.ts +9 -0
  2. package/dist/_internal/Mutable.d.ts.map +1 -0
  3. package/dist/_internal/Mutable.js +10 -0
  4. package/dist/_internal/Mutable.js.map +1 -0
  5. package/dist/_internal/disableCooperativeYielding.d.ts +3 -0
  6. package/dist/_internal/disableCooperativeYielding.d.ts.map +1 -0
  7. package/dist/_internal/disableCooperativeYielding.js +7 -0
  8. package/dist/_internal/disableCooperativeYielding.js.map +1 -0
  9. package/dist/cjs/_internal/Mutable.d.ts +9 -0
  10. package/dist/cjs/_internal/Mutable.d.ts.map +1 -0
  11. package/dist/cjs/_internal/Mutable.js +14 -0
  12. package/dist/cjs/_internal/Mutable.js.map +1 -0
  13. package/dist/cjs/_internal/disableCooperativeYielding.d.ts +3 -0
  14. package/dist/cjs/_internal/disableCooperativeYielding.d.ts.map +1 -0
  15. package/dist/cjs/_internal/disableCooperativeYielding.js +11 -0
  16. package/dist/cjs/_internal/disableCooperativeYielding.js.map +1 -0
  17. package/dist/cjs/operator/hold.d.ts +4 -4
  18. package/dist/cjs/operator/hold.d.ts.map +1 -1
  19. package/dist/cjs/operator/hold.js +6 -7
  20. package/dist/cjs/operator/hold.js.map +1 -1
  21. package/dist/cjs/operator/slice.js +3 -3
  22. package/dist/cjs/operator/slice.js.map +1 -1
  23. package/dist/cjs/run/observe.d.ts.map +1 -1
  24. package/dist/cjs/run/observe.js +2 -1
  25. package/dist/cjs/run/observe.js.map +1 -1
  26. package/dist/cjs/subject/HoldSubject.d.ts +6 -2
  27. package/dist/cjs/subject/HoldSubject.d.ts.map +1 -1
  28. package/dist/cjs/subject/HoldSubject.js +3 -3
  29. package/dist/cjs/subject/HoldSubject.js.map +1 -1
  30. package/dist/cjs/subject/RefSubject.d.ts +7 -2
  31. package/dist/cjs/subject/RefSubject.d.ts.map +1 -1
  32. package/dist/cjs/subject/RefSubject.js +16 -13
  33. package/dist/cjs/subject/RefSubject.js.map +1 -1
  34. package/dist/cjs/subject/SynchronizedSubject.d.ts.map +1 -1
  35. package/dist/cjs/subject/SynchronizedSubject.js +11 -10
  36. package/dist/cjs/subject/SynchronizedSubject.js.map +1 -1
  37. package/dist/operator/hold.d.ts +4 -4
  38. package/dist/operator/hold.d.ts.map +1 -1
  39. package/dist/operator/hold.js +6 -7
  40. package/dist/operator/hold.js.map +1 -1
  41. package/dist/operator/slice.js +3 -3
  42. package/dist/operator/slice.js.map +1 -1
  43. package/dist/run/observe.d.ts.map +1 -1
  44. package/dist/run/observe.js +2 -1
  45. package/dist/run/observe.js.map +1 -1
  46. package/dist/subject/HoldSubject.d.ts +6 -2
  47. package/dist/subject/HoldSubject.d.ts.map +1 -1
  48. package/dist/subject/HoldSubject.js +3 -3
  49. package/dist/subject/HoldSubject.js.map +1 -1
  50. package/dist/subject/RefSubject.d.ts +7 -2
  51. package/dist/subject/RefSubject.d.ts.map +1 -1
  52. package/dist/subject/RefSubject.js +16 -13
  53. package/dist/subject/RefSubject.js.map +1 -1
  54. package/dist/subject/SynchronizedSubject.d.ts.map +1 -1
  55. package/dist/subject/SynchronizedSubject.js +11 -10
  56. package/dist/subject/SynchronizedSubject.js.map +1 -1
  57. package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
  58. package/package.json +2 -2
  59. package/src/operator/multicast.ts +1 -2
  60. package/src/operator/race.ts +1 -2
  61. package/src/operator/switchMap.ts +14 -3
  62. package/src/operator/switchMapCause.ts +9 -2
  63. package/src/operator/switchMatch.ts +8 -1
  64. package/src/subject/SynchronizedSubject.ts +11 -10
  65. package/tsconfig.build.tsbuildinfo +1 -1
@@ -7,7 +7,6 @@ import * as Exit from '@effect/io/Exit'
7
7
  import * as Scope from '@effect/io/Scope'
8
8
 
9
9
  import { Fx } from '../Fx.js'
10
- import { asap } from '../_internal/RefCounter.js'
11
10
  import { run } from '../run/run.js'
12
11
 
13
12
  import { tap } from './tap.js'
@@ -55,7 +54,7 @@ class RaceAllFx<Streams extends readonly Fx<any, any, any>[]>
55
54
  s,
56
55
  tap(() => cleanupScopes(i)),
57
56
  run(sink.event, sink.error, sink.end),
58
- Effect.scheduleForked(asap), // Schedule starts so that all Scopes can be returned *before* attempting to cleanup
57
+ Effect.forkScoped, // Schedule starts so that all Scopes can be returned *before* attempting to cleanup
59
58
  Effect.as(scope),
60
59
  Effect.provideService(Scope.Scope, scope),
61
60
  ),
@@ -53,12 +53,23 @@ class SwitchMapFx<R, E, A, R2, E2, B>
53
53
  this.f(a).run(
54
54
  Fx.Sink(
55
55
  sink.event,
56
- flow(sink.error, Effect.zipLeft(resetRef)),
56
+ flow(
57
+ Effect.unified((cause) =>
58
+ Cause.isInterruptedOnly(cause)
59
+ ? counter.decrement
60
+ : sink.error(cause),
61
+ ),
62
+ Effect.zipLeft(resetRef),
63
+ ),
57
64
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
58
65
  ),
59
66
  ),
60
- Effect.onError((cause) =>
61
- Cause.isInterruptedOnly(cause) ? Effect.unit() : sink.error(cause),
67
+ Effect.onError(
68
+ Effect.unified((cause) =>
69
+ Cause.isInterruptedOnly(cause)
70
+ ? counter.decrement
71
+ : sink.error(cause),
72
+ ),
62
73
  ),
63
74
  Effect.forkScoped,
64
75
  ),
@@ -1,5 +1,5 @@
1
1
  import { flow, pipe } from '@effect/data/Function'
2
- import type * as Cause from '@effect/io/Cause'
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'
5
5
  import * as Ref from '@effect/io/Ref/Synchronized'
@@ -65,7 +65,14 @@ class SwitchMapCauseFx<R, E, A, R2, E2, B>
65
65
  this.f(cause).run(
66
66
  Fx.Sink(
67
67
  sink.event,
68
- flow(sink.error, Effect.zipLeft(resetRef)),
68
+ flow(
69
+ Effect.unified((cause) =>
70
+ Cause.isInterruptedOnly(cause)
71
+ ? counter.decrement
72
+ : sink.error(cause),
73
+ ),
74
+ Effect.zipLeft(resetRef),
75
+ ),
69
76
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
70
77
  ),
71
78
  ),
@@ -67,7 +67,14 @@ class SwitchMatchFx<R, E, A, R2, E2, B, R3, E3, C>
67
67
  fx.run(
68
68
  Fx.Sink(
69
69
  sink.event,
70
- flow(sink.error, Effect.zipLeft(resetRef)),
70
+ flow(
71
+ Effect.unified((cause) =>
72
+ Cause.isInterruptedOnly(cause)
73
+ ? counter.decrement
74
+ : sink.error(cause),
75
+ ),
76
+ Effect.zipLeft(resetRef),
77
+ ),
71
78
  pipe(counter.decrement, Effect.zipLeft(resetRef)),
72
79
  ),
73
80
  ),
@@ -1,12 +1,12 @@
1
1
  import { equals } from '@effect/data/Equal'
2
2
  import { identity, pipe } from '@effect/data/Function'
3
- import * as MutableRef from '@effect/data/MutableRef'
4
3
  import * as Option from '@effect/data/Option'
5
4
  import * as Effect from '@effect/io/Effect'
6
5
  import * as Ref from '@effect/io/Ref'
7
6
  import * as Synchronized from '@effect/io/Ref/Synchronized'
8
7
 
9
8
  import { Fx } from '../Fx.js'
9
+ import { Mutable } from '../_internal/Mutable.js'
10
10
 
11
11
  import { HoldSubject } from './HoldSubject.js'
12
12
  import { Computed, isRefSubject, RefSubject } from './RefSubject.js'
@@ -28,17 +28,17 @@ export namespace SynchronizedSubject {
28
28
  initial: () => A,
29
29
  eq: (a: A, b: A) => boolean = equals,
30
30
  ): SynchronizedSubject<A> {
31
- const mutableRef = MutableRef.make(Option.some(initial()))
32
- const subject = HoldSubject.unsafeMake<never, A>(mutableRef)
31
+ const current = Mutable(Option.some(initial()))
32
+ const subject = HoldSubject.unsafeMake<never, A>(current)
33
33
  const locked = Effect.unsafeMakeSemaphore(1).withPermits(1)
34
34
 
35
35
  const getValue = () =>
36
36
  pipe(
37
- MutableRef.get(mutableRef),
37
+ current.get(),
38
38
  Option.getOrElse(() => {
39
39
  const a = initial()
40
40
 
41
- MutableRef.set(mutableRef, Option.some(a))
41
+ current.set(Option.some(a))
42
42
 
43
43
  return a
44
44
  }),
@@ -49,14 +49,14 @@ export namespace SynchronizedSubject {
49
49
  ): Effect.Effect<R2, E2, B> =>
50
50
  locked(
51
51
  Effect.gen(function* ($) {
52
- const current = getValue()
53
- const [b, a] = yield* $(f(current))
52
+ const next = getValue()
53
+ const [b, a] = yield* $(f(next))
54
54
 
55
- if (eq(current, a)) {
55
+ if (eq(next, a)) {
56
56
  return b
57
57
  }
58
58
 
59
- MutableRef.set(mutableRef, Option.some(a))
59
+ current.set(Option.some(a))
60
60
 
61
61
  yield* $(subject.event(a))
62
62
 
@@ -82,6 +82,7 @@ export namespace SynchronizedSubject {
82
82
  error: subject.error.bind(subject),
83
83
  end: subject.end,
84
84
  value: subject.value,
85
+ current,
85
86
  eq,
86
87
  modify,
87
88
  modifyEffect,
@@ -100,7 +101,7 @@ export namespace SynchronizedSubject {
100
101
  delete: Effect.sync(() => {
101
102
  const value = getValue()
102
103
 
103
- MutableRef.set(mutableRef, Option.some(value))
104
+ current.set(Option.some(value))
104
105
 
105
106
  return value
106
107
  }),