#async #safe #scoped #scope


A minimal, safe library for scoped async tasks

2 releases

0.1.1 Jul 27, 2020
0.1.0 Jul 27, 2020

#1193 in Asynchronous

24 downloads per month

MIT OR BSD-2-Clause OR Apache-2.0

60 lines

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.


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


~16K SLoC