rivetkit-client 2.3.1

Rust client for RivetKit - the Stateful Serverless Framework for building AI agents, realtime apps, and game servers
Documentation
use std::{cmp, time::Duration};

pub struct Backoff {
	max_delay: Duration,
	delay: Duration,
}

impl Backoff {
	pub fn new(initial: Duration, max_delay: Duration) -> Self {
		Self {
			max_delay,
			delay: initial,
		}
	}

	pub fn delay(&self) -> Duration {
		self.delay
	}

	pub async fn tick(&mut self) {
		tokio::time::sleep(self.delay).await;
		self.delay = cmp::min(self.delay * 2, self.max_delay);
	}
}