Skip to content

Rust based Async Executor which executes woken tasks only when it is ticked

License

Notifications You must be signed in to change notification settings

coder137/ticked-async-executor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ticked Async Executor

Async Local Executor which executes woken tasks only when it is ticked

Usage

Default Local Executor

use ticked_async_executor::*;

const DELTA: f64 = 1000.0 / 60.0;

let 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);

Split Local Executor

use ticked_async_executor::*;

const DELTA: f64 = 1000.0 / 60.0;

let (spawner, 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);

Limit the number of woken tasks run per tick

use ticked_async_executor::*;

const DELTA: f64 = 1000.0 / 60.0;

let 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);

Caveats

  • Uses the smol ecosystem
  • Ensure that tasks are spawned on the same thread as the one that initializes the executor

Roadmap

  • TickedAsyncExecutor
  • SplitTickedAsyncExecutor
    • Similar to the channel API, but spawner and ticker cannot be moved to different threads
  • Tracing

About

Rust based Async Executor which executes woken tasks only when it is ticked

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages