suno_core/clock.rs
1//! The clock port: the engine's only source of time.
2//!
3//! The download executor waits in two places: between polls for a server-side
4//! WAV render, and as backoff after a rate-limit or transient failure. Both go
5//! through this trait so the wait is injected, never taken from the wall clock.
6//! `now_unix` provides the current Unix timestamp for JWT expiry checks.
7//! The CLI adapter sleeps with the async runtime; tests use a double that
8//! returns immediately and records the requested delays, keeping every test
9//! deterministic with no real sleeping.
10
11use std::future::Future;
12use std::time::Duration;
13
14/// The time and delay port.
15pub trait Clock {
16 /// Wait for `duration`, then resolve.
17 fn sleep(&self, duration: Duration) -> impl Future<Output = ()> + Send;
18
19 /// Current time as seconds since the Unix epoch.
20 fn now_unix(&self) -> i64;
21}