@typed/fx 1.27.3 → 1.28.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/cjs/AsyncData.js +1 -1
- package/dist/cjs/AsyncData.js.map +1 -1
- package/dist/cjs/Emitter.js +3 -3
- package/dist/cjs/Emitter.js.map +1 -1
- package/dist/cjs/Form.js +15 -15
- package/dist/cjs/Form.js.map +1 -1
- package/dist/cjs/FormEntry.js +3 -3
- package/dist/cjs/FormEntry.js.map +1 -1
- package/dist/cjs/Fx.js +11 -9
- package/dist/cjs/Fx.js.map +1 -1
- package/dist/cjs/Idle.js +8 -8
- package/dist/cjs/Idle.js.map +1 -1
- package/dist/cjs/Match.js +17 -17
- package/dist/cjs/Match.js.map +1 -1
- package/dist/cjs/Pull.js +3 -3
- package/dist/cjs/Pull.js.map +1 -1
- package/dist/cjs/Push.js +1 -1
- package/dist/cjs/Push.js.map +1 -1
- package/dist/cjs/RefArray.js +2 -2
- package/dist/cjs/RefArray.js.map +1 -1
- package/dist/cjs/RefChunk.js +1 -1
- package/dist/cjs/RefChunk.js.map +1 -1
- package/dist/cjs/RefHashMap.js +1 -1
- package/dist/cjs/RefHashMap.js.map +1 -1
- package/dist/cjs/RefHashSet.js +1 -1
- package/dist/cjs/RefHashSet.js.map +1 -1
- package/dist/cjs/RefSubject.js +150 -75
- package/dist/cjs/RefSubject.js.map +1 -1
- package/dist/cjs/Sink.js +14 -14
- package/dist/cjs/Sink.js.map +1 -1
- package/dist/cjs/Stream.js +1 -1
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/Subject.js +27 -22
- package/dist/cjs/Subject.js.map +1 -1
- package/dist/cjs/Typeclass.js +1 -1
- package/dist/cjs/Typeclass.js.map +1 -1
- package/dist/cjs/Versioned.js +4 -4
- package/dist/cjs/Versioned.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/DeferredRef.js +14 -11
- package/dist/cjs/internal/DeferredRef.js.map +1 -1
- package/dist/cjs/internal/core.js +71 -42
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/diff.js +1 -1
- package/dist/cjs/internal/diff.js.map +1 -1
- package/dist/cjs/internal/effect-loop-operator.js +1 -1
- package/dist/cjs/internal/effect-loop-operator.js.map +1 -1
- package/dist/cjs/internal/effect-operator.js +3 -3
- package/dist/cjs/internal/effect-operator.js.map +1 -1
- package/dist/cjs/internal/effect-producer.js +3 -3
- package/dist/cjs/internal/effect-producer.js.map +1 -1
- package/dist/cjs/internal/helpers.js +63 -42
- package/dist/cjs/internal/helpers.js.map +1 -1
- package/dist/cjs/internal/keyed.js +34 -26
- package/dist/cjs/internal/keyed.js.map +1 -1
- package/dist/cjs/internal/loop-operator.js +1 -1
- package/dist/cjs/internal/loop-operator.js.map +1 -1
- package/dist/cjs/internal/operator.js +1 -1
- package/dist/cjs/internal/operator.js.map +1 -1
- package/dist/cjs/internal/protos.js +1 -1
- package/dist/cjs/internal/protos.js.map +1 -1
- package/dist/cjs/internal/provide.js +1 -1
- package/dist/cjs/internal/provide.js.map +1 -1
- package/dist/cjs/internal/share.js +8 -13
- package/dist/cjs/internal/share.js.map +1 -1
- package/dist/cjs/internal/sync-operator.js +4 -4
- package/dist/cjs/internal/sync-operator.js.map +1 -1
- package/dist/cjs/internal/sync-producer.js +27 -23
- package/dist/cjs/internal/sync-producer.js.map +1 -1
- package/dist/cjs/internal/withKey.js +7 -7
- package/dist/cjs/internal/withKey.js.map +1 -1
- package/dist/dts/AsyncData.d.ts +2 -2
- package/dist/dts/AsyncData.d.ts.map +1 -1
- package/dist/dts/Emitter.d.ts +1 -1
- package/dist/dts/Emitter.d.ts.map +1 -1
- package/dist/dts/Fx.d.ts +39 -13
- package/dist/dts/Fx.d.ts.map +1 -1
- package/dist/dts/Idle.d.ts.map +1 -1
- package/dist/dts/Match.d.ts +1 -1
- package/dist/dts/Match.d.ts.map +1 -1
- package/dist/dts/Push.d.ts +4 -1
- package/dist/dts/Push.d.ts.map +1 -1
- package/dist/dts/RefArray.d.ts +1 -2
- package/dist/dts/RefArray.d.ts.map +1 -1
- package/dist/dts/RefChunk.d.ts.map +1 -1
- package/dist/dts/RefHashMap.d.ts +1 -1
- package/dist/dts/RefHashMap.d.ts.map +1 -1
- package/dist/dts/RefHashSet.d.ts.map +1 -1
- package/dist/dts/RefSubject.d.ts +64 -3
- package/dist/dts/RefSubject.d.ts.map +1 -1
- package/dist/dts/Sink.d.ts +2 -1
- package/dist/dts/Sink.d.ts.map +1 -1
- package/dist/dts/Subject.d.ts +2 -1
- package/dist/dts/Subject.d.ts.map +1 -1
- package/dist/dts/Versioned.d.ts +3 -1
- package/dist/dts/Versioned.d.ts.map +1 -1
- package/dist/dts/internal/DeferredRef.d.ts +6 -4
- package/dist/dts/internal/DeferredRef.d.ts.map +1 -1
- package/dist/dts/internal/core.d.ts +25 -12
- package/dist/dts/internal/core.d.ts.map +1 -1
- package/dist/dts/internal/diff.d.ts +1 -1
- package/dist/dts/internal/diff.d.ts.map +1 -1
- package/dist/dts/internal/effect-operator.d.ts.map +1 -1
- package/dist/dts/internal/helpers.d.ts +8 -6
- package/dist/dts/internal/helpers.d.ts.map +1 -1
- package/dist/dts/internal/keyed.d.ts +2 -2
- package/dist/dts/internal/keyed.d.ts.map +1 -1
- package/dist/dts/internal/loop-operator.d.ts +1 -1
- package/dist/dts/internal/loop-operator.d.ts.map +1 -1
- package/dist/dts/internal/protos.d.ts +1 -1
- package/dist/dts/internal/protos.d.ts.map +1 -1
- package/dist/dts/internal/provide.d.ts.map +1 -1
- package/dist/dts/internal/share.d.ts +1 -1
- package/dist/dts/internal/share.d.ts.map +1 -1
- package/dist/dts/internal/strategies.d.ts.map +1 -1
- package/dist/dts/internal/sync-operator.d.ts.map +1 -1
- package/dist/dts/internal/sync-producer.d.ts +4 -4
- package/dist/dts/internal/sync-producer.d.ts.map +1 -1
- package/dist/esm/Emitter.js +1 -1
- package/dist/esm/Emitter.js.map +1 -1
- package/dist/esm/Form.js +14 -14
- package/dist/esm/Form.js.map +1 -1
- package/dist/esm/FormEntry.js +2 -2
- package/dist/esm/FormEntry.js.map +1 -1
- package/dist/esm/Fx.js +16 -5
- package/dist/esm/Fx.js.map +1 -1
- package/dist/esm/Idle.js +7 -7
- package/dist/esm/Idle.js.map +1 -1
- package/dist/esm/Match.js +17 -17
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Pull.js +2 -2
- package/dist/esm/Push.js.map +1 -1
- package/dist/esm/RefArray.js +1 -1
- package/dist/esm/RefArray.js.map +1 -1
- package/dist/esm/RefHashMap.js.map +1 -1
- package/dist/esm/RefSubject.js +140 -59
- package/dist/esm/RefSubject.js.map +1 -1
- package/dist/esm/Sink.js +13 -13
- package/dist/esm/Sink.js.map +1 -1
- package/dist/esm/Subject.js +29 -20
- package/dist/esm/Subject.js.map +1 -1
- package/dist/esm/Versioned.js +1 -1
- package/dist/esm/Versioned.js.map +1 -1
- package/dist/esm/internal/DeferredRef.js +13 -10
- package/dist/esm/internal/DeferredRef.js.map +1 -1
- package/dist/esm/internal/core.js +70 -37
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/diff.js.map +1 -1
- package/dist/esm/internal/effect-operator.js +2 -2
- package/dist/esm/internal/effect-producer.js +1 -1
- package/dist/esm/internal/helpers.js +62 -39
- package/dist/esm/internal/helpers.js.map +1 -1
- package/dist/esm/internal/keyed.js +26 -17
- package/dist/esm/internal/keyed.js.map +1 -1
- package/dist/esm/internal/share.js +7 -12
- package/dist/esm/internal/share.js.map +1 -1
- package/dist/esm/internal/sync-operator.js +3 -3
- package/dist/esm/internal/sync-operator.js.map +1 -1
- package/dist/esm/internal/sync-producer.js +7 -5
- package/dist/esm/internal/sync-producer.js.map +1 -1
- package/dist/esm/internal/withKey.js +6 -6
- package/dist/esm/internal/withKey.js.map +1 -1
- package/package.json +8 -7
- package/src/Emitter.ts +2 -1
- package/src/Form.ts +22 -30
- package/src/FormEntry.ts +2 -2
- package/src/Fx.ts +54 -36
- package/src/Idle.ts +7 -7
- package/src/Match.ts +24 -26
- package/src/Pull.ts +2 -2
- package/src/Push.ts +4 -1
- package/src/RefArray.ts +1 -1
- package/src/RefHashMap.ts +1 -1
- package/src/RefSubject.ts +262 -98
- package/src/Sink.ts +15 -14
- package/src/Subject.ts +55 -39
- package/src/Versioned.ts +4 -2
- package/src/internal/DeferredRef.ts +21 -11
- package/src/internal/core.ts +92 -61
- package/src/internal/diff.ts +1 -1
- package/src/internal/effect-operator.ts +2 -2
- package/src/internal/effect-producer.ts +3 -3
- package/src/internal/helpers.ts +89 -42
- package/src/internal/keyed.ts +47 -42
- package/src/internal/loop-operator.ts +1 -1
- package/src/internal/protos.ts +1 -1
- package/src/internal/share.ts +11 -26
- package/src/internal/sync-operator.ts +3 -3
- package/src/internal/sync-producer.ts +7 -5
- package/src/internal/withKey.ts +6 -6
package/src/Fx.ts
CHANGED
|
@@ -4,35 +4,33 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type * as Ctx from "@typed/context"
|
|
7
|
-
import type {
|
|
8
|
-
ConfigProvider,
|
|
9
|
-
Duration,
|
|
10
|
-
Equivalence,
|
|
11
|
-
ExecutionStrategy,
|
|
12
|
-
Exit,
|
|
13
|
-
Fiber,
|
|
14
|
-
FiberId,
|
|
15
|
-
FiberRef,
|
|
16
|
-
HashSet,
|
|
17
|
-
Pipeable,
|
|
18
|
-
Predicate,
|
|
19
|
-
PubSub,
|
|
20
|
-
Request,
|
|
21
|
-
Runtime,
|
|
22
|
-
Scope,
|
|
23
|
-
Tracer
|
|
24
|
-
} from "effect"
|
|
25
7
|
import * as Cause from "effect/Cause"
|
|
26
|
-
import type
|
|
8
|
+
import type * as ConfigProvider from "effect/ConfigProvider"
|
|
9
|
+
import type * as Duration from "effect/Duration"
|
|
27
10
|
import * as Effect from "effect/Effect"
|
|
28
11
|
import * as Either from "effect/Either"
|
|
12
|
+
import type * as Equivalence from "effect/Equivalence"
|
|
13
|
+
import type * as ExecutionStrategy from "effect/ExecutionStrategy"
|
|
14
|
+
import type * as Exit from "effect/Exit"
|
|
15
|
+
import type * as Fiber from "effect/Fiber"
|
|
16
|
+
import type * as FiberId from "effect/FiberId"
|
|
17
|
+
import type * as FiberRef from "effect/FiberRef"
|
|
29
18
|
import { dual, identity } from "effect/Function"
|
|
19
|
+
import type * as HashSet from "effect/HashSet"
|
|
30
20
|
import * as Layer from "effect/Layer"
|
|
31
21
|
import * as Option from "effect/Option"
|
|
22
|
+
import type * as Pipeable from "effect/Pipeable"
|
|
23
|
+
import type * as Predicate from "effect/Predicate"
|
|
32
24
|
import { hasProperty } from "effect/Predicate"
|
|
25
|
+
import type * as PubSub from "effect/PubSub"
|
|
33
26
|
import * as Queue from "effect/Queue"
|
|
27
|
+
import type * as Request from "effect/Request"
|
|
28
|
+
import type * as Runtime from "effect/Runtime"
|
|
34
29
|
import * as Schedule from "effect/Schedule"
|
|
30
|
+
import type * as Scope from "effect/Scope"
|
|
31
|
+
import type * as Tracer from "effect/Tracer"
|
|
35
32
|
import type * as Types from "effect/Types"
|
|
33
|
+
import type * as Utils from "effect/Utils"
|
|
36
34
|
import * as Emitter from "./Emitter.js"
|
|
37
35
|
import * as core from "./internal/core.js"
|
|
38
36
|
import * as coreKeyed from "./internal/keyed.js"
|
|
@@ -89,7 +87,7 @@ export namespace Fx {
|
|
|
89
87
|
/**
|
|
90
88
|
* @since 1.20.0
|
|
91
89
|
*/
|
|
92
|
-
export type Unify<T> = [T] extends [Fx<infer A, infer E, infer R>
|
|
90
|
+
export type Unify<T> = [T] extends [Fx<infer A, infer E, infer R>] ? Fx<A, E, R> : never
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
/**
|
|
@@ -1037,11 +1035,11 @@ export const middleware: {
|
|
|
1037
1035
|
export const onExit: {
|
|
1038
1036
|
<R2>(
|
|
1039
1037
|
f: (exit: Exit.Exit<unknown>) => Effect.Effect<unknown, never, R2>
|
|
1040
|
-
): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E, R2>
|
|
1038
|
+
): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E, R | R2>
|
|
1041
1039
|
|
|
1042
1040
|
<A, E, R, R2>(
|
|
1043
1041
|
fx: Fx<A, E, R>,
|
|
1044
|
-
f: (exit: Exit.Exit<unknown>) => Effect.Effect<unknown, never, R2>
|
|
1042
|
+
f: (exit: Exit.Exit<unknown>) => Effect.Effect<unknown, never, R | R2>
|
|
1045
1043
|
): Fx<A, E, R | R2>
|
|
1046
1044
|
} = dual(2, core.onExit)
|
|
1047
1045
|
|
|
@@ -1227,7 +1225,7 @@ export const withSpan: {
|
|
|
1227
1225
|
readonly root?: boolean
|
|
1228
1226
|
readonly context?: Ctx.Context<never>
|
|
1229
1227
|
}): Fx<A, E, R>
|
|
1230
|
-
} = dual(
|
|
1228
|
+
} = dual((args) => isFx(args[0]), core.withSpan)
|
|
1231
1229
|
|
|
1232
1230
|
/**
|
|
1233
1231
|
* @since 1.20.0
|
|
@@ -2246,7 +2244,12 @@ export const at: {
|
|
|
2246
2244
|
export function drainLayer<FXS extends ReadonlyArray<Fx<any, never, any>>>(
|
|
2247
2245
|
...fxs: FXS
|
|
2248
2246
|
): Layer.Layer<never, never, Exclude<Fx.Context<FXS[number]>, Scope.Scope>> {
|
|
2249
|
-
return Layer.scopedDiscard(
|
|
2247
|
+
return Layer.scopedDiscard(
|
|
2248
|
+
Effect.forkWithErrorHandler(
|
|
2249
|
+
core.drain(core.mergeAll(fxs)),
|
|
2250
|
+
(e) => Effect.logError(`Error originating from Fx.drainLayer`, Cause.fail(e))
|
|
2251
|
+
)
|
|
2252
|
+
)
|
|
2250
2253
|
}
|
|
2251
2254
|
|
|
2252
2255
|
/**
|
|
@@ -2310,23 +2313,24 @@ export const partitionMap: {
|
|
|
2310
2313
|
/**
|
|
2311
2314
|
* @since 1.20.0
|
|
2312
2315
|
*/
|
|
2313
|
-
export const gen: <Y extends Effect.
|
|
2316
|
+
export const gen: <Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>, FX extends Fx<any, any, any>>(
|
|
2314
2317
|
f: (_: Effect.Adapter) => Generator<Y, FX, any>
|
|
2315
2318
|
) => Fx<
|
|
2316
2319
|
Fx.Success<FX>,
|
|
2317
|
-
Effect.Effect
|
|
2318
|
-
Effect.Effect
|
|
2320
|
+
(Y extends Utils.YieldWrap<Effect.Effect<infer _, infer E, any>> ? E : never) | Fx.Error<FX>,
|
|
2321
|
+
(Y extends Utils.YieldWrap<Effect.Effect<any, any, infer R>> ? R : never) | Fx.Context<FX>
|
|
2319
2322
|
> = core.gen
|
|
2320
2323
|
|
|
2321
2324
|
/**
|
|
2322
2325
|
* @since 1.20.0
|
|
2323
2326
|
*/
|
|
2324
|
-
export const genScoped: <Y extends Effect.
|
|
2327
|
+
export const genScoped: <Y extends Utils.YieldWrap<Effect.Effect<any, any, any>>, FX extends Fx<any, any, any>>(
|
|
2325
2328
|
f: (_: Effect.Adapter) => Generator<Y, FX, any>
|
|
2326
2329
|
) => Fx<
|
|
2327
2330
|
Fx.Success<FX>,
|
|
2328
|
-
Effect.Effect
|
|
2329
|
-
Exclude<Effect.Effect
|
|
2331
|
+
(Y extends Utils.YieldWrap<Effect.Effect<infer _, infer E, any>> ? E : never) | Fx.Error<FX>,
|
|
2332
|
+
| Exclude<Y extends Utils.YieldWrap<Effect.Effect<any, any, infer R>> ? R : never, Scope.Scope>
|
|
2333
|
+
| Exclude<Fx.Context<FX>, Scope.Scope>
|
|
2330
2334
|
> = core.genScoped
|
|
2331
2335
|
|
|
2332
2336
|
/**
|
|
@@ -2448,9 +2452,9 @@ export const withEmitter = <A, E = never, E2 = never, R = never>(
|
|
|
2448
2452
|
* @since 1.18.0
|
|
2449
2453
|
*/
|
|
2450
2454
|
export const delay: {
|
|
2451
|
-
(delay: DurationInput): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E, R | Scope.Scope>
|
|
2452
|
-
<A, E, R>(fx: Fx<A, E, R>, delay: DurationInput): Fx<A, E, R | Scope.Scope>
|
|
2453
|
-
} = dual(2, function<A, E, R>(fx: Fx<A, E, R>, delay: DurationInput): Fx<A, E, R | Scope.Scope> {
|
|
2455
|
+
(delay: Duration.DurationInput): <A, E, R>(fx: Fx<A, E, R>) => Fx<A, E, R | Scope.Scope>
|
|
2456
|
+
<A, E, R>(fx: Fx<A, E, R>, delay: Duration.DurationInput): Fx<A, E, R | Scope.Scope>
|
|
2457
|
+
} = dual(2, function<A, E, R>(fx: Fx<A, E, R>, delay: Duration.DurationInput): Fx<A, E, R | Scope.Scope> {
|
|
2454
2458
|
return core.flatMap(fx, (a) => core.fromEffect(Effect.delay(Effect.succeed(a), delay)))
|
|
2455
2459
|
})
|
|
2456
2460
|
|
|
@@ -2500,9 +2504,9 @@ export function fromDequeue<A>(dequeue: Queue.Dequeue<A>): Fx<A>
|
|
|
2500
2504
|
export function fromDequeue<I, A>(dequeue: Ctx.Dequeue<I, A>): Fx<A, never, I>
|
|
2501
2505
|
export function fromDequeue<I, A>(dequeue: Ctx.Dequeue<I, A> | Queue.Dequeue<A>): Fx<A, never, I> {
|
|
2502
2506
|
return core.make((sink) =>
|
|
2503
|
-
Effect.gen(function*(
|
|
2504
|
-
while (yield*
|
|
2505
|
-
yield*
|
|
2507
|
+
Effect.gen(function*() {
|
|
2508
|
+
while (yield* dequeueIsActive(dequeue)) {
|
|
2509
|
+
yield* Effect.matchCauseEffect(dequeue.take, sink)
|
|
2506
2510
|
}
|
|
2507
2511
|
})
|
|
2508
2512
|
)
|
|
@@ -2571,3 +2575,17 @@ export function promise<A>(f: (signal: AbortSignal) => Promise<A>) {
|
|
|
2571
2575
|
export function promiseFx<A, E = never, R = never>(f: (signal: AbortSignal) => Promise<Fx<A, E, R>>) {
|
|
2572
2576
|
return fromFxEffect(Effect.promise(f))
|
|
2573
2577
|
}
|
|
2578
|
+
|
|
2579
|
+
const void_ = succeed<void>(undefined)
|
|
2580
|
+
const null_ = succeed<null>(null)
|
|
2581
|
+
|
|
2582
|
+
export {
|
|
2583
|
+
/**
|
|
2584
|
+
* @since 2.0.0
|
|
2585
|
+
*/
|
|
2586
|
+
null_ as null,
|
|
2587
|
+
/**
|
|
2588
|
+
* @since 2.0.0
|
|
2589
|
+
*/
|
|
2590
|
+
void_ as void
|
|
2591
|
+
}
|
package/src/Idle.ts
CHANGED
|
@@ -159,12 +159,12 @@ export interface WhileIdleRequestOptions<R, E, R2, E2> extends IdleRequestOption
|
|
|
159
159
|
export const whileIdle = <R, E, R2, E2>(
|
|
160
160
|
options: WhileIdleRequestOptions<R, E, R2, E2>
|
|
161
161
|
): Effect.Effect<void, E | E2, Scope.Scope | R | R2> =>
|
|
162
|
-
Effect.gen(function*(
|
|
163
|
-
while (yield*
|
|
164
|
-
const deadline = yield*
|
|
162
|
+
Effect.gen(function*() {
|
|
163
|
+
while (yield* options.while) {
|
|
164
|
+
const deadline = yield* whenIdle(options)
|
|
165
165
|
|
|
166
166
|
while (shouldContinue(deadline)) {
|
|
167
|
-
yield*
|
|
167
|
+
yield* options.body
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
})
|
|
@@ -246,12 +246,12 @@ class IdleQueueImpl<I> implements IdleQueue<I> {
|
|
|
246
246
|
else {
|
|
247
247
|
const [part, task] = result.value
|
|
248
248
|
this.queue.delete(part)
|
|
249
|
-
yield*
|
|
249
|
+
yield* task
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
if (this.queue.size > 0) {
|
|
254
|
-
yield*
|
|
254
|
+
yield* run
|
|
255
255
|
} else {
|
|
256
256
|
this.scheduled = false
|
|
257
257
|
}
|
|
@@ -260,7 +260,7 @@ class IdleQueueImpl<I> implements IdleQueue<I> {
|
|
|
260
260
|
|
|
261
261
|
this.scheduleNextRun = Effect.provideService(
|
|
262
262
|
Effect.suspend(() => {
|
|
263
|
-
if (this.queue.size === 0) return Effect.
|
|
263
|
+
if (this.queue.size === 0) return Effect.void
|
|
264
264
|
|
|
265
265
|
this.scheduled = true
|
|
266
266
|
|
package/src/Match.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { getGuard, type GuardInput } from "@typed/guard"
|
|
6
|
+
import { isNonEmptyReadonlyArray, reduce } from "effect/Array"
|
|
6
7
|
import * as Cause from "effect/Cause"
|
|
7
8
|
import * as Chunk from "effect/Chunk"
|
|
8
9
|
import * as Effect from "effect/Effect"
|
|
@@ -12,7 +13,6 @@ import * as Fiber from "effect/Fiber"
|
|
|
12
13
|
import { identity } from "effect/Function"
|
|
13
14
|
import * as MutableRef from "effect/MutableRef"
|
|
14
15
|
import * as Option from "effect/Option"
|
|
15
|
-
import { isNonEmptyReadonlyArray, reduce } from "effect/ReadonlyArray"
|
|
16
16
|
import * as Scope from "effect/Scope"
|
|
17
17
|
import * as Fx from "./Fx.js"
|
|
18
18
|
import { withScopedFork } from "./internal/helpers.js"
|
|
@@ -166,17 +166,17 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
166
166
|
when: When<R | R2 | Scope.Scope, E | E2, I, A, O>,
|
|
167
167
|
value: A
|
|
168
168
|
) =>
|
|
169
|
-
Effect.gen(function*(
|
|
169
|
+
Effect.gen(function*() {
|
|
170
170
|
if (previous?.when === when) {
|
|
171
|
-
yield*
|
|
171
|
+
yield* RefSubject.set(previous.ref, value)
|
|
172
172
|
} else {
|
|
173
173
|
// Interrupt any previous resources
|
|
174
174
|
if (previous !== undefined) {
|
|
175
|
-
yield*
|
|
175
|
+
yield* previous.interrupt
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
// RefSubject to pass along to our matching function
|
|
179
|
-
const refSubject = yield*
|
|
179
|
+
const refSubject = yield* RefSubject.of(value)
|
|
180
180
|
|
|
181
181
|
// Track if the case is ended
|
|
182
182
|
const hasEnded = MutableRef.make(false)
|
|
@@ -184,19 +184,17 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
184
184
|
const endSignal = Subject.unsafeMake<void>(0)
|
|
185
185
|
|
|
186
186
|
// Run the case
|
|
187
|
-
const fiber = yield*
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
.
|
|
191
|
-
|
|
192
|
-
(cause)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
(value) => MutableRef.get(hasEnded) ? Effect.unit : sink.onSuccess(Option.some(value))
|
|
197
|
-
)
|
|
187
|
+
const fiber = yield* fork(
|
|
188
|
+
Fx.mergeFirst(when.onMatch(refSubject), Fx.tap(endSignal, () => MutableRef.set(hasEnded, true)))
|
|
189
|
+
.run(
|
|
190
|
+
Sink.make(
|
|
191
|
+
(cause) =>
|
|
192
|
+
MutableRef.get(hasEnded) || Cause.isInterruptedOnly(cause)
|
|
193
|
+
? Effect.void
|
|
194
|
+
: sink.onFailure(cause),
|
|
195
|
+
(value) => MutableRef.get(hasEnded) ? Effect.void : sink.onSuccess(Option.some(value))
|
|
198
196
|
)
|
|
199
|
-
|
|
197
|
+
)
|
|
200
198
|
)
|
|
201
199
|
|
|
202
200
|
previous = new Matched(
|
|
@@ -211,11 +209,11 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
211
209
|
}).pipe(Effect.provideService(Scope.Scope, parentScope))
|
|
212
210
|
|
|
213
211
|
function matchWhen<A>(input: I, when: When<R | R2 | Scope.Scope, E | E2, I, A, O>) {
|
|
214
|
-
return Effect.gen(function*(
|
|
215
|
-
const matched = yield*
|
|
212
|
+
return Effect.gen(function*() {
|
|
213
|
+
const matched = yield* when.guard(input)
|
|
216
214
|
|
|
217
215
|
if (Option.isSome(matched)) {
|
|
218
|
-
yield*
|
|
216
|
+
yield* onMatch(when, matched.value)
|
|
219
217
|
|
|
220
218
|
return true
|
|
221
219
|
} else {
|
|
@@ -225,14 +223,14 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
225
223
|
}
|
|
226
224
|
|
|
227
225
|
function matchInput(input: I) {
|
|
228
|
-
return Effect.gen(function*(
|
|
226
|
+
return Effect.gen(function*() {
|
|
229
227
|
// Allow failures to be accumulated, such that errors do not break the overall match
|
|
230
228
|
// and additional matchers can be attempted against first
|
|
231
229
|
const causes: Array<Cause.Cause<E | E2>> = []
|
|
232
230
|
|
|
233
231
|
// If there's a previous match, attempt it first to avoid re-testing all cases in order
|
|
234
232
|
if (previous !== undefined) {
|
|
235
|
-
const matchedExit = yield*
|
|
233
|
+
const matchedExit = yield* Effect.exit(matchWhen(input, previous.when))
|
|
236
234
|
|
|
237
235
|
if (Exit.isFailure(matchedExit)) {
|
|
238
236
|
causes.push(matchedExit.cause)
|
|
@@ -245,7 +243,7 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
245
243
|
// Don't test this case twice
|
|
246
244
|
if (when === previous?.when) continue
|
|
247
245
|
|
|
248
|
-
const matchedExit = yield*
|
|
246
|
+
const matchedExit = yield* Effect.exit(matchWhen(input, when))
|
|
249
247
|
|
|
250
248
|
if (Exit.isFailure(matchedExit)) {
|
|
251
249
|
causes.push(matchedExit.cause)
|
|
@@ -256,13 +254,13 @@ class TypeMatcherImpl<I, O, E, R> implements TypeMatcher<I, O, E, R> {
|
|
|
256
254
|
|
|
257
255
|
if (isNonEmptyReadonlyArray(causes)) {
|
|
258
256
|
const [first, ...rest] = causes
|
|
259
|
-
yield*
|
|
257
|
+
yield* sink.onFailure(reduce(rest, first, Cause.sequential))
|
|
260
258
|
} else {
|
|
261
259
|
if (previous !== undefined) {
|
|
262
|
-
yield*
|
|
260
|
+
yield* previous.interrupt
|
|
263
261
|
}
|
|
264
262
|
|
|
265
|
-
yield*
|
|
263
|
+
yield* sink.onSuccess(Option.none())
|
|
266
264
|
}
|
|
267
265
|
})
|
|
268
266
|
}
|
package/src/Pull.ts
CHANGED
|
@@ -32,7 +32,7 @@ function schedulePull<A, E, R, R2, R3>(
|
|
|
32
32
|
Cause.failureOrCause(cause).pipe(
|
|
33
33
|
Either.match({
|
|
34
34
|
onLeft: Option.match({
|
|
35
|
-
onNone: () => Effect.sync(() => resume(Effect.
|
|
35
|
+
onNone: () => Effect.sync(() => resume(Effect.void)),
|
|
36
36
|
onSome: (e: E) => sink.onFailure(Cause.fail(e))
|
|
37
37
|
}),
|
|
38
38
|
onRight: sink.onFailure
|
|
@@ -41,7 +41,7 @@ function schedulePull<A, E, R, R2, R3>(
|
|
|
41
41
|
onSuccess: (chunk: Chunk.Chunk<A>) => Effect.forEach(chunk, sink.onSuccess, { discard: true })
|
|
42
42
|
}).pipe(
|
|
43
43
|
f,
|
|
44
|
-
Effect.flatMap(() => Effect.sync(() => resume(Effect.
|
|
44
|
+
Effect.flatMap(() => Effect.sync(() => resume(Effect.void)))
|
|
45
45
|
)
|
|
46
46
|
)
|
|
47
47
|
}
|
package/src/Push.ts
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
* @since 1.20.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { Effect, Option, Pipeable, Scope } from "effect"
|
|
7
6
|
import type { Cause } from "effect/Cause"
|
|
7
|
+
import type * as Effect from "effect/Effect"
|
|
8
8
|
import { dual } from "effect/Function"
|
|
9
|
+
import type * as Option from "effect/Option"
|
|
10
|
+
import type * as Pipeable from "effect/Pipeable"
|
|
9
11
|
import { pipeArguments } from "effect/Pipeable"
|
|
12
|
+
import type * as Scope from "effect/Scope"
|
|
10
13
|
import type { Fx } from "./Fx.js"
|
|
11
14
|
import * as core from "./internal/core.js"
|
|
12
15
|
import { FxBase } from "./internal/protos.js"
|
package/src/RefArray.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type * as C from "@typed/context"
|
|
7
|
+
import * as ReadonlyArray from "effect/Array"
|
|
7
8
|
import type * as Effect from "effect/Effect"
|
|
8
9
|
import { equals } from "effect/Equal"
|
|
9
10
|
import type { Equivalence } from "effect/Equivalence"
|
|
10
11
|
import { dual } from "effect/Function"
|
|
11
12
|
import * as Option from "effect/Option"
|
|
12
13
|
import type * as Order from "effect/Order"
|
|
13
|
-
import * as ReadonlyArray from "effect/ReadonlyArray"
|
|
14
14
|
import type * as Scope from "effect/Scope"
|
|
15
15
|
import type * as Fx from "./Fx.js"
|
|
16
16
|
import * as RefSubject from "./RefSubject.js"
|
package/src/RefHashMap.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type { IdentifierConstructor, IdentifierOf } from "@typed/context"
|
|
6
|
-
import type { Scope } from "effect"
|
|
7
6
|
import * as Effect from "effect/Effect"
|
|
8
7
|
import { dual } from "effect/Function"
|
|
9
8
|
import * as HashMap from "effect/HashMap"
|
|
10
9
|
import * as HashSet from "effect/HashSet"
|
|
11
10
|
import type { Option } from "effect/Option"
|
|
11
|
+
import type * as Scope from "effect/Scope"
|
|
12
12
|
import type * as Fx from "./Fx.js"
|
|
13
13
|
import * as RefSubject from "./RefSubject.js"
|
|
14
14
|
|