Skip to content
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

Add ability to spawn actor from any logic #4724

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

davidkpiano
Copy link
Member

This PR adds the ability for any actor logic to spawn an actor, which is a core tenet of the actor model.

@davidkpiano davidkpiano requested a review from Andarist February 4, 2024 03:06
Copy link

changeset-bot bot commented Feb 4, 2024

⚠️ No Changeset found

Latest commit: 9a69517

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codesandbox-ci bot commented Feb 4, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

packages/core/src/types.ts Outdated Show resolved Hide resolved
packages/core/src/types.ts Outdated Show resolved Hide resolved
Comment on lines +192 to +194
if (this._processingStatus === ProcessingStatus.Running) {
actor.start();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the actors spawned when this._processingStatus === ProcessingStatus.NotStarted?

},
spawnChild: <T extends AnyActorLogic>(
logic: T,
actorOptions?: ActorOptions<T>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should reuse the type tricks from here:

...[options]: ConditionalRequired<
[
options?: ActorOptions<TLogic> & {
[K in RequiredOptions<TLogic>]: unknown;
}
],
IsNotNever<RequiredOptions<TLogic>>
>

@@ -2106,6 +2106,10 @@ export interface ActorScope<
defer: (fn: () => void) => void;
system: TSystem;
stopChild: (child: AnyActorRef) => void;
spawnChild: <T extends AnyActorLogic>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -73,6 +75,7 @@ export type InvokeCallback<
* the listener is then called whenever events are received by the callback actor
*/
receive: Receiver<TEvent>;
spawn: ActorScope<any, any>['spawnChild'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't all of those actor logics receive stopChild as well?

Copy link
Member

@Andarist Andarist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a substantial problem with this PR that is somewhat mentioned in this comment here:

// TODO: atm children don't belong entirely to the actor so
// in a way - it's not even super aware of them
// so we can't stop them from here but we really should!
// right now, they are being stopped within the machine's transition
// but that could throw and leave us with "orphaned" active actors

When the parent actor gets stopped its children should get stopped too. There is no mechanism implemented here that would achieve this for this new functionality.

@davidkpiano
Copy link
Member Author

There is a substantial problem with this PR that is somewhat mentioned in this comment here:

// TODO: atm children don't belong entirely to the actor so
// in a way - it's not even super aware of them
// so we can't stop them from here but we really should!
// right now, they are being stopped within the machine's transition
// but that could throw and leave us with "orphaned" active actors

When the parent actor gets stopped its children should get stopped too. There is no mechanism implemented here that would achieve this for this new functionality.

831aeec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants