-
Notifications
You must be signed in to change notification settings - Fork 3
Pass typed parent data to ActorHost factories #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "effect-machine": minor | ||
| --- | ||
|
|
||
| Allow ActorHost factories to receive typed data from the hosting parent as a second argument. Call host(request, hostInput) to bind parent input to a generation while consumers continue to call acquire(request). Existing one-argument factories keep their current behavior. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,37 @@ describe("ActorHost", () => { | |
| }).pipe(Effect.provide(ActorSystemDefault)), | ||
| ); | ||
|
|
||
| it.scoped("keeps typed host data with its generation across consumers and reentry", () => | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The actual machine receives Full gate: 396 tests, 909 assertions, types, lint, format, build, and example gates passed. |
||
| Effect.gen(function* () { | ||
| const host = yield* ActorHost.make({ | ||
| identity: (input: { session: object; request: string }) => input.session, | ||
| spawn: (input, owner: { destination: string }) => | ||
| Machine.spawn(child, { input: { value: `${owner.destination}:${input.request}` } }), | ||
| }); | ||
| const session = {}; | ||
| const waiting = yield* host.acquire({ session, request: "early" }).pipe(Effect.forkScoped); | ||
| yield* yieldFibers; | ||
| const firstOwner = yield* ownerScope; | ||
| const firstHosted = yield* host | ||
| .host({ session, request: "registration" }, { destination: "rewards" }) | ||
| .pipe(Scope.provide(firstOwner), Effect.forkScoped); | ||
| const first = yield* Fiber.join(waiting); | ||
| expect(yield* first.snapshot).toEqual(ChildState.Ready({ value: "rewards:early" })); | ||
| expect(yield* Fiber.join(firstHosted)).toBe(first); | ||
| expect(yield* host.acquire({ session, request: "later" })).toBe(first); | ||
| yield* Scope.close(firstOwner, Exit.void); | ||
| expect((yield* first.call(ChildEvent.Finish)).transitioned).toBe(false); | ||
| const nextOwner = yield* ownerScope; | ||
| const nextHosted = yield* host | ||
| .host({ session, request: "registration" }, { destination: "history" }) | ||
| .pipe(Scope.provide(nextOwner), Effect.forkScoped); | ||
| const next = yield* host.acquire({ session, request: "next" }); | ||
| expect(next).not.toBe(first); | ||
| expect(yield* Fiber.join(nextHosted)).toBe(next); | ||
| expect(yield* next.snapshot).toEqual(ChildState.Ready({ value: "history:next" })); | ||
| }), | ||
| ); | ||
|
|
||
| it.scoped("keeps actual recovery running when an acquiring consumer cancels", () => | ||
| Effect.gen(function* () { | ||
| const system = yield* ActorSystemService; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host closure supplies the second argument. A consumer cannot replace it. Existing request matching and scope cleanup stay intact. This call trace comes from source; calldiff is unavailable in this environment.