Crate async_spin_sleep

source ·
Expand description

This library provides a timer driver for scheduling and executing timed operations. The driver allows you to create handles for sleeping for a specific duration or until a specified timeout. It operates in a concurrent environment and uses a binary heap for efficient scheduling of events.

Example

use async_spin_sleep::Builder;
use std::time::Duration;

// Create a handle for sleeping for 1 second
let (handle, driver) = Builder::default().build();

// Spawn the driver on a separate thread.
// The timer will be dropped when all handles are dropped.
std::thread::spawn(driver);

let sleep_future = handle.sleep_for(Duration::from_secs(1));

// Wait for the sleep future to complete
let result = futures::executor::block_on(sleep_future);
if let Ok(overly) = result {
    println!("Slept {overly:?} more than requested");
} else {
    println!("Sleep error: {:?}", result.err());
}

Structs

Enums

Functions