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

The document of "send!" is inaccurate #12

Open
deftsp opened this issue Jan 17, 2022 · 3 comments
Open

The document of "send!" is inaccurate #12

deftsp opened this issue Jan 17, 2022 · 3 comments

Comments

@deftsp
Copy link
Contributor

deftsp commented Jan 17, 2022

The current the document of send! said: "The method must take &mut self as the receiver."

I tried the method likes this async fn get_count(&self) -> ActorResult<usize>, it pass the compler.

Then I found the following words at https://old.reddit.com/r/rust/comments/hu10wh/actzero_asyncawait_compatible_actor_system/

Actor methods can have &self, &mut self or self: Addr<Local> receiver types, and this controls whether these methods can execute concurrently or not.

How about putting these words into the document of send!?

@deftsp
Copy link
Contributor Author

deftsp commented Jan 17, 2022

I did further reading. The design of act-zero is very beautiful, thank you @Diggsey

Both call! and send! internal will call send_mut, and always passed the &mut the_actor to MutItem , no matter the actor method is &self or &mut self, like the name imply "mutex". So the method as "&self" also can pass the compile.

I love the idea of:

Actor methods can have &self, &mut self or self: Addr receiver types, and this controls whether these methods can execute concurrently or not.

However call! and send! is not mean to it for v0.4. So how can I call the methods concurrently?

@Diggsey
Copy link
Owner

Diggsey commented Jan 17, 2022

Yeah, at the moment only &mut self is usable with send! and/or call!. To run things concurrently you should use send_fut_with or send_fut.

There's a more complicated example here: https://github.com/Diggsey/raft-zero

Originally the idea was that &self methods could run concurrently with each other, but it complicated the implementation quite a bit, and I found they were not that useful in practice.

The current idea is that you run whatever you like concurrently using send_fut, and then when you are ready to update the actor state, you can call! or send! a method on the actor. send_fut_with is a convenience that makes it easier to pass the actor address into the future.

I'd be happy to accept PRs to fix issues in the documentation :)

@deftsp
Copy link
Contributor Author

deftsp commented Jan 17, 2022

I have tried to restructure a project with act-zero. I found the majority of the function just gets data, more precisely, gets the part of the actor state. It's expensive to archive it with the exclusive call!. send_fut_with can not access the actor state (or the fields of the struct). call! nested in the send_fut_with " is expensive even more.

deftsp added a commit to deftsp/act-zero that referenced this issue Jan 17, 2022
deftsp added a commit to deftsp/act-zero that referenced this issue Jan 17, 2022
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

No branches or pull requests

2 participants