@typed/fx 1.20.4 → 1.20.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.
- package/dist/cjs/AsyncData.js +36 -30
- package/dist/cjs/AsyncData.js.map +1 -1
- package/dist/cjs/Emitter.js +11 -3
- package/dist/cjs/Emitter.js.map +1 -1
- package/dist/cjs/Fx.js.map +1 -1
- package/dist/dts/AsyncData.d.ts +16 -26
- package/dist/dts/AsyncData.d.ts.map +1 -1
- package/dist/dts/Emitter.d.ts +2 -1
- package/dist/dts/Emitter.d.ts.map +1 -1
- package/dist/dts/Fx.d.ts +1 -1
- package/dist/dts/Fx.d.ts.map +1 -1
- package/dist/esm/AsyncData.js +33 -32
- package/dist/esm/AsyncData.js.map +1 -1
- package/dist/esm/Emitter.js +9 -3
- package/dist/esm/Emitter.js.map +1 -1
- package/dist/esm/Fx.js.map +1 -1
- package/package.json +8 -8
- package/src/AsyncData.ts +92 -90
- package/src/Emitter.ts +27 -16
- package/src/Fx.ts +1 -1
package/src/Emitter.ts
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* @since 1.20.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { ExecutionStrategy, type Scope } from "effect"
|
|
6
7
|
import * as Cause from "effect/Cause"
|
|
7
8
|
import * as Effect from "effect/Effect"
|
|
8
9
|
import type * as Exit from "effect/Exit"
|
|
9
10
|
import * as Runtime from "effect/Runtime"
|
|
11
|
+
import { withScope } from "./internal/helpers.js"
|
|
10
12
|
import * as Sink from "./Sink.js"
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -26,22 +28,31 @@ export interface Emitter<in E, in A> {
|
|
|
26
28
|
export function withEmitter<R, E, A, R2, B>(
|
|
27
29
|
sink: Sink.Sink<R, E, A>,
|
|
28
30
|
f: (emitter: Emitter<E, A>) => Effect.Effect<R2, E, B>
|
|
29
|
-
): Effect.Effect<R | R2, never, void> {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
): Effect.Effect<R | R2 | Scope.Scope, never, void> {
|
|
32
|
+
return withScope(
|
|
33
|
+
(scope) =>
|
|
34
|
+
Sink.withEarlyExit(
|
|
35
|
+
sink,
|
|
36
|
+
(sink): Effect.Effect<R | R2, E, B> => {
|
|
37
|
+
return Effect.flatMap(Effect.runtime<R>(), (runtime) => {
|
|
38
|
+
const runFork = Runtime.runFork(runtime)
|
|
39
|
+
const run = <E, A>(effect: Effect.Effect<R, E, A>): Promise<Exit.Exit<E, A>> =>
|
|
40
|
+
new Promise((resolve) => {
|
|
41
|
+
const fiber = runFork(effect, { scope })
|
|
42
|
+
fiber.addObserver(resolve)
|
|
43
|
+
})
|
|
44
|
+
const emitter: Emitter<E, A> = {
|
|
45
|
+
succeed: (value) => run(sink.onSuccess(value)),
|
|
46
|
+
failCause: (cause) => run(sink.onFailure(cause)),
|
|
47
|
+
fail: (error) => run(sink.onFailure(Cause.fail(error))),
|
|
48
|
+
die: (error) => run(sink.onFailure(Cause.die(error))),
|
|
49
|
+
end: () => run(sink.earlyExit)
|
|
50
|
+
}
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
52
|
+
return f(emitter)
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
),
|
|
56
|
+
ExecutionStrategy.sequential
|
|
46
57
|
)
|
|
47
58
|
}
|
package/src/Fx.ts
CHANGED
|
@@ -2384,7 +2384,7 @@ export const when: {
|
|
|
2384
2384
|
*/
|
|
2385
2385
|
export const withEmitter = <E, A, R = never, E2 = never>(
|
|
2386
2386
|
f: (emitter: Emitter.Emitter<E, A>) => Effect.Effect<R, E2, unknown>
|
|
2387
|
-
): Fx<R, E | E2, A> => core.make<R, E | E2, A>((sink) => Emitter.withEmitter(sink, f))
|
|
2387
|
+
): Fx<R | Scope.Scope, E | E2, A> => core.make<R | Scope.Scope, E | E2, A>((sink) => Emitter.withEmitter(sink, f))
|
|
2388
2388
|
|
|
2389
2389
|
/**
|
|
2390
2390
|
* Create an Fx which will wait a specified duration of time where no
|