| Crates.io | ticked_async_executor |
| lib.rs | ticked_async_executor |
| version | 0.3.0 |
| created_at | 2025-04-16 06:47:17.252039+00 |
| updated_at | 2025-05-17 05:40:06.192702+00 |
| description | Local executor that runs woken async tasks when it is ticked |
| homepage | |
| repository | https://github.com/coder137/ticked-async-executor |
| max_upload_size | |
| id | 1636050 |
| size | 71,277 |
Async Local Executor which executes woken tasks only when it is ticked
MSRV: 1.87
use ticked_async_executor::*;
const DELTA: f64 = 1000.0 / 60.0;
let mut executor = TickedAsyncExecutor::default();
executor.spawn_local("MyIdentifier", async move {}).detach();
// Tick your executor to run the tasks
assert_eq!(executor.num_tasks(), 1);
executor.tick(DELTA, None);
assert_eq!(executor.num_tasks(), 0);
use ticked_async_executor::*;
const DELTA: f64 = 1000.0 / 60.0;
let (spawner, mut ticker) = SplitTickedAsyncExecutor::default();
spawner.spawn_local("MyIdentifier", async move {}).detach();
// Tick your ticker to run the tasks
assert_eq!(spawner.num_tasks(), 1);
ticker.tick(DELTA, None);
assert_eq!(spawner.num_tasks(), 0);
use ticked_async_executor::*;
const DELTA: f64 = 1000.0 / 60.0;
let mut executor = TickedAsyncExecutor::default();
executor.spawn_local("MyIdentifier1", async move {}).detach();
executor.spawn_local("MyIdentifier2", async move {}).detach();
// Runs upto 1 woken tasks per tick
assert_eq!(executor.num_tasks(), 2);
executor.tick(DELTA, Some(1));
assert_eq!(executor.num_tasks(), 1);
executor.tick(DELTA, Some(1));
assert_eq!(executor.num_tasks(), 0);
tick_eventtimer_registration#[cfg(feature = "timer_registration")]
{
use ticked_async_executor::*;
const DELTA: f64 = 1000.0 / 60.0;
let mut executor = TickedAsyncExecutor::default();
// These APIs are gated under the `timer_registration` feature
let timer = executor.create_timer_from_timer_registration();
executor.spawn_local("MyIdentifier1", async move {
timer.sleep_for(10.0).await;
}).detach();
executor.wait_till_completed(1.0);
assert_eq!(executor.num_tasks(), 0);
}
#[cfg(feature = "tick_event")]
{
use ticked_async_executor::*;
const DELTA: f64 = 1000.0 / 60.0;
let mut executor = TickedAsyncExecutor::default();
// These APIs are gated under the `tick_event` feature
let _delta_tick_rx = executor.tick_channel();
let timer = executor.create_timer_from_tick_event();
executor.spawn_local("MyIdentifier1", async move {
timer.sleep_for(10.0).await;
}).detach();
executor.wait_till_completed(1.0);
assert_eq!(executor.num_tasks(), 0);
}
executor.spawn_localSpawn 10000 tasks
time: [1.3711 ms 1.3713 ms 1.3715 ms]
executor.create_timer_from_timer_registration under feature timer_registrationSpawn 1000 timers from timer registration
time: [336.10 µs 336.42 µs 336.93 µs]
executor.create_timer_from_tick_event under feature tick_eventSpawn 1000 timers from tick event
time: [1.5688 ms 1.5692 ms 1.5697 ms]
smol ecosystem