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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom event loop #97

Merged
merged 15 commits into from
Jun 24, 2022
Merged

Custom event loop #97

merged 15 commits into from
Jun 24, 2022

Conversation

Restioson
Copy link
Owner

@Restioson Restioson commented Jun 22, 2022

This is a POC for custom event loops. I purposefully have not addressed #91 in this draft, as this is simply the minimal set of changes that provide custom event loops, and may serve as a jumping-off point for a PR to address #91. This is a spiritual successor to #51 in a way 馃槃

Closes #89

@Restioson Restioson added the enhancement New feature or request label Jun 22, 2022
@Restioson
Copy link
Owner Author

CC @thomaseizinger, for some reason it won't let me request a review from anyone?

@thomaseizinger
Copy link
Collaborator

CC @thomaseizinger, for some reason it won't let me request a review from anyone?

That is because I am not listed as a maintainer, I think :)

Copy link
Collaborator

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Cool!

Thanks for giving this a go! :)
Left a few comments!

src/context.rs Outdated Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
src/context.rs Show resolved Hide resolved
src/context.rs Outdated Show resolved Hide resolved
@Restioson
Copy link
Owner Author

Ahh, I see. I can add you as a collaborator if you'd like?

Also, do you think it makes sense to tighten up this PR and get it merged soon, and after that tackle modularisation?

@thomaseizinger
Copy link
Collaborator

Ahh, I see. I can add you as a collaborator if you'd like?

Sure! Much appreciated :)

Also, do you think it makes sense to tighten up this PR and get it merged soon, and after that tackle modularisation?

Yes to both.

@Restioson Restioson marked this pull request as ready for review June 23, 2022 07:29
@Restioson
Copy link
Owner Author

One last thing to be done here: I think now that the future from tick can be cancelled and therefore the catty::Sender dropped without the actor stopping, mapping it to Disconnected doesn't really make sense. Something like Interrupted would make more sense. Maybe an error enum could be made:

enum Error {
    ActorShutdown,
    Disconnected,
    Interrupted,
}

We could also tackle #89 here and maybe remove the ActorShutdown if it's unnecessary.

A possible usecase for how senders could interpret Interrupted as differently from Disconnected would be if they had handler timeouts and wanted to check if the message send failed due to timeout (Interrupted) or the actor being stopped (Disconnected).

# Conflicts:
#	src/context.rs
#	src/inbox/rx.rs
Copy link
Collaborator

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Nice!

@Restioson
Copy link
Owner Author

Restioson commented Jun 23, 2022

I'll merge this after I make CI pass

EDIT: holding off on merge until the latest change has been reviewed

@Restioson
Copy link
Owner Author

One last thing to be done here: I think now that the future from tick can be cancelled and therefore the catty::Sender dropped without the actor stopping, mapping it to Disconnected doesn't really make sense. Something like Interrupted would make more sense

I've added a new Error enum to address this now. In doing so, I also removed ActorShutdown, so this PR would close #89 too. It's not technically so well scoped but it felt like a good time since Error needed to be made into an enum to support the dual possible causes of send failure.

Copy link
Collaborator

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Looks good apart from the removal of -> Self::Stopped :)

examples/send_interval.rs Show resolved Hide resolved
Comment on lines +200 to +201
/// The actor is no longer running and disconnected from the sending address.
Disconnected,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we include the actor name via std::any::type_name in here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We would need a constructor for this to avoid the type parameter:

impl Error {
	pub fn disconnected::<A: Any>() - Self {
		Self::Disconnected(std::any::type_name::<A>())
	}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

For encapsulation purposes, we could make this enum private and encapsulating it in an opaque error, similar to std::io::Error but we'd lose exhaustive matching then because users can only check of the types via Error::is_interrupted() etc.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think that having exhaustive matching is probably useful, so I would rather leave it as it is now, unless there is a compelling reason to encapsulate it

Copy link
Owner Author

Choose a reason for hiding this comment

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

Also, should the interrupted variant also have the name?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, should the interrupted variant also have the name?

I guess so? The name is useful because this error may often be question-marked and then appear in an error chain from anyhow or something. Without the actor name, it is really hard to debug where it came from.

Copy link
Owner Author

Choose a reason for hiding this comment

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

In that case, I wonder if it should be extracted as a field:

struct Error {
    act: &'static str,
    kind: ErrorKind,
}

with the current Error renamed to ErrorKind

Copy link
Owner Author

@Restioson Restioson Jun 24, 2022

Choose a reason for hiding this comment

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

I've been working on this and it's kinda outgrown this PR, so would you be ok with merging this now and having this feature in a followup? I've pushed my work on that to custom-event-loop-error

tests/basic.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/inbox/rx.rs Outdated Show resolved Hide resolved
@Restioson
Copy link
Owner Author

Strange... the line the CI is failing on doesn't exist??

@thomaseizinger
Copy link
Collaborator

Strange... the line the CI is failing on doesn't exist??

Merge with master. The CI is running on pull_request meaning it is running on a merge commit with latest master.

@Restioson
Copy link
Owner Author

Ah, I see!

# Conflicts:
#	src/address.rs
@Restioson Restioson merged commit ed05509 into master Jun 24, 2022
@Restioson Restioson deleted the custom-event-loop branch June 24, 2022 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge Disconnected and ActorShutdown
2 participants