Open deftsp opened 2 years ago
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?
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 :)
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.
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/
How about putting these words into the document of
send!
?