safe-async-scoped 0.1.1

A minimal, safe library for scoped async tasks.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented2 out of 5 items with examples
  • Size
  • Source code size: 9.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.54 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nullchinchilla

safe-async-scoped is a minimal wrapper around FuturesUnordered in the futures crate that simulates scoped tasks. Unlike async-scoped and even crossbeam-scoped etc, safe-async-scoped

  • Is completely safe to use
  • Has no unsafe code in its implementation
  • Has no dependencies other than futures
  • Is completely runtime-agnostic

Note that "tasks" spawned with safe-async-scoped will not be sent to the executor as separate tasks, and will thus only run on one thread. On the plus side, none of the futures have to be Send.

Example

let listener = Async::new(TcpListener::bind("127.0.0.1:8080").unwrap()).unwrap();
let lala = String::from("hello");
{
   let scope = Scope::new();
   scope
       .start(async {
           loop {
               let (client, _) = listener.accept().await.unwrap();
               scope.spawn(async {
                   handle(client, &lala).await;
               });
           }
       })
       .await;
}