1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crateId;
/// Represents the result of attempting to generate a new ID.
///
/// This type models the outcome of generator polling APIs such as
/// [`crate::generator::SnowflakeGenerator::try_poll_id`] and
/// [`crate::generator::UlidGenerator::try_poll_id`]:
///
/// - [`Poll::Ready`] indicates a new ID was successfully generated.
/// - [`Poll::Pending`] means the generator is throttled and cannot produce a
/// new ID until the time source advances past `yield_for`.
///
/// This allows non-blocking generation loops and clean backoff strategies.
///
/// # Example
/// ```
/// use ferroid::{
/// generator::{BasicSnowflakeGenerator, Poll},
/// id::{SnowflakeId, SnowflakeTwitterId},
/// };
///
/// struct FixedTime;
/// impl ferroid::time::TimeSource<u64> for FixedTime {
/// fn current_millis(&self) -> u64 {
/// 1
/// }
/// }
///
/// let generator = BasicSnowflakeGenerator::<SnowflakeTwitterId, _>::from_components(
/// 0,
/// 1,
/// SnowflakeTwitterId::max_sequence(),
/// FixedTime,
/// );
/// match generator.poll_id() {
/// Poll::Ready { id } => println!("ID: {}", id.timestamp()),
/// Poll::Pending { yield_for } => println!("Back off for: {yield_for}"),
/// }
/// ```