-
I need to change the value of every tick. Are there any actors that implement this approach, or do I need to use the scheduler separately and pass the message to the actor? |
Beta Was this translation helpful? Give feedback.
Answered by
slawlor
Apr 9, 2023
Replies: 1 comment
-
So you could set it up relatively basically with impl Actor for DynamicTimeActor {
type Msg = Duration;
type State = ();
type Arguments = Duration;
async fn pre_start(&self, myself: ActorRef<Self>, startup_delay: Self::Arguments) -> Result<Self::State, ActorProcessingErr> {
myself.send_after(startup_delay, || Duration::from_millis(random_time()));
Ok(())
}
async fn handle(&self, myself: ActorRef<Self>, message: Self::Msg, _: &mut Self::State) -> Result<(), ActorProcessingErr> {
myself.send_after(message, || Duration::from_millis(random_time()));
Ok(())
}
} This isn't a functional example, but hopefully it demonstrates the idea |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
slawlor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So you could set it up relatively basically with
time::send_after
which will just send a single message after a delay. It's equivalent of like "sleeping" in a loop without blocking the actor however. So something like