Documentation
  • Coverage
  • 0%
    0 out of 9 items documented0 out of 6 items with examples
  • Size
  • Source code size: 10.36 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.9 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mira-merkell

tpx

Schedule and run coroutines.

  • WIP
  • Use a thread pool to spawn lightweight coroutines
  • Meant for CPU-bound tasks that work cooperatively
  • Continuation-passing style: callbacks automatically scheduled to run in a pool of work-stealing threads
  • Super simple and fast. No async runtime.

Example

use std::{thread::sleep, time::Duration};
use tpx::{continue_with, Ctn::DONE, Executor};


fn main() {
    let exec = Executor::init();

    // Spawn 3 tasks: each task schedules its own continuation
    for i in 0..3 {
        exec.spawn(move || {
            println!("Hello from task {i}");

            // Some data to passed to  the continuation
            let j = i * 3;
            sleep(Duration::from_millis(123));

            // Yield to the executor.
            continue_with(move || {
                println!("Hello from continuation {i}:  Result: {j}");
                DONE
            })
        });
    }

    // TODO: block on the executor until all tasks are done.
    sleep(Duration::from_secs(3));
}