effect-machine 0.2.2 → 0.2.4
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/package.json +1 -1
- package/src/actor.ts +4 -2
- package/src/inspection.ts +24 -15
package/package.json
CHANGED
package/src/actor.ts
CHANGED
|
@@ -520,8 +520,10 @@ export const createActor = Effect.fn("effect-machine.actor.spawn")(function* <
|
|
|
520
520
|
return buildActorRefCore(id, machine, stateRef, eventQueue, stoppedRef, listeners, stop);
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
// Start the event loop
|
|
524
|
-
|
|
523
|
+
// Start the event loop — use forkScoped so the event loop fiber's lifetime
|
|
524
|
+
// is tied to the provided Scope, not the calling fiber. This prevents the
|
|
525
|
+
// event loop from being interrupted when a transient caller completes.
|
|
526
|
+
const loopFiber = yield* Effect.forkScoped(
|
|
525
527
|
eventLoop(
|
|
526
528
|
machine,
|
|
527
529
|
stateRef,
|
package/src/inspection.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
1
|
+
import { Context, type Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Type-level helpers
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a type param: if it's a Schema, extract `.Type`; otherwise use as-is.
|
|
9
|
+
*/
|
|
10
|
+
type ResolveType<T> = T extends Schema.Schema<infer A, infer _I, infer _R> ? A : T;
|
|
2
11
|
|
|
3
12
|
// ============================================================================
|
|
4
13
|
// Inspection Events
|
|
@@ -113,15 +122,15 @@ export const Inspector = Context.GenericTag<Inspector<any, any>>("@effect/machin
|
|
|
113
122
|
|
|
114
123
|
/**
|
|
115
124
|
* Create an inspector from a callback function.
|
|
116
|
-
*
|
|
117
|
-
*
|
|
125
|
+
*
|
|
126
|
+
* Type params accept either raw tagged types or Schema constructors:
|
|
127
|
+
* - `makeInspector(cb)` — defaults to `AnyInspectionEvent`
|
|
128
|
+
* - `makeInspector<MyState, MyEvent>(cb)` — explicit tagged types
|
|
129
|
+
* - `makeInspector<typeof MyState, typeof MyEvent>(cb)` — schema constructors (auto-extracts `.Type`)
|
|
118
130
|
*/
|
|
119
|
-
export const makeInspector = <
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
>(
|
|
123
|
-
onInspect: (event: InspectionEvent<S, E>) => void,
|
|
124
|
-
): Inspector<S, E> => ({ onInspect });
|
|
131
|
+
export const makeInspector = <S = { readonly _tag: string }, E = { readonly _tag: string }>(
|
|
132
|
+
onInspect: (event: InspectionEvent<ResolveType<S>, ResolveType<E>>) => void,
|
|
133
|
+
): Inspector<ResolveType<S>, ResolveType<E>> => ({ onInspect });
|
|
125
134
|
|
|
126
135
|
// ============================================================================
|
|
127
136
|
// Built-in Inspectors
|
|
@@ -130,11 +139,11 @@ export const makeInspector = <
|
|
|
130
139
|
/**
|
|
131
140
|
* Console inspector that logs events in a readable format
|
|
132
141
|
*/
|
|
133
|
-
export const consoleInspector = <
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
>
|
|
137
|
-
makeInspector
|
|
142
|
+
export const consoleInspector = (): Inspector<
|
|
143
|
+
{ readonly _tag: string },
|
|
144
|
+
{ readonly _tag: string }
|
|
145
|
+
> =>
|
|
146
|
+
makeInspector((event) => {
|
|
138
147
|
const prefix = `[${event.actorId}]`;
|
|
139
148
|
switch (event.type) {
|
|
140
149
|
case "@machine.spawn":
|
|
@@ -166,4 +175,4 @@ export const collectingInspector = <
|
|
|
166
175
|
E extends { readonly _tag: string },
|
|
167
176
|
>(
|
|
168
177
|
events: InspectionEvent<S, E>[],
|
|
169
|
-
): Inspector<S, E> =>
|
|
178
|
+
): Inspector<S, E> => ({ onInspect: (event) => events.push(event) });
|