Skip to content

Actor scheduler #81

Closed Answered by slawlor
EnvOut asked this question in Q&A
Discussion options

You must be logged in to vote

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

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(m…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by slawlor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants