#rust, #actix, #actor-model
First, ActorFuture is Actix's version of future, it's not the traditional futures.
We run the ActorFuture by calling the wait
method of its Context
. This method will block the message stream, to prevent any further messages being processed until the current Message is finished processing.
I stumped upon a case where I need to send multiple messages in sequence, this kind of task can be done by using a normal future:
let fut = async move {
Server::from_registry().send(MessageA{}).await?;
Server::from_registry().send(MessageB{}).await
};
And then, convert the future into ActorFuture (because we need to use wait
method), by doing either:
let run = fut.into_actor(self);
Or
let run = actix::fut::wrap_future::<_, Self>(fut);
After that, we can consume the ActorFuture just like how we do it for single message cases:
run.map(|result, actor, context} { ... }).wait(ctx);
How to create a SystemService in Actix
#rust, #actix, #actor-model In Actix Framework , an actor can be registered as a service, which help it run automatically. There are two…
Home Page
Welcome! Look like you've found my personal notebook. This is the place where you can take a peek into my mind to see what I've been…
If you think this note resonated, be it positive or negative, please feel free to send me an email and we can talk.