#linear #async #panic #unwind #web-server

pending_unwind

A library for converting unwindings into pending

1 unstable release

Uses new Rust 2024

0.1.0 Mar 8, 2025

#585 in Asynchronous

Download history 112/week @ 2025-03-05 14/week @ 2025-03-12

126 downloads per month

MIT/Apache

9KB
134 lines

pending_unwind

Make any future non-unwinding. If Future::poll panics, it will be converted to Poll::Pending. One of the biggest problems with linear types is unwinding - what should you do duriing panic? They cannot be dropped, thus you cannot continue unwinding, and abort the program. This crate provides a way to convert unwinding to Poll::Pending, so you can handle it in your own way.

A web server may use this to cancel all futures associated with a thread that panicked without having catch_unwind.

let fut = pending_unwind(async { panic!() });
let mut fut = Box::pin(fut);
let mut cx = Context::from_waker(Waker::noop());
let poll = fut.as_mut().poll(&mut cx);
assert_eq!(poll, Poll::Pending);

lib.rs:

Make any future non-unwinding. If Future::poll panics, it will be converted to Poll::Pending. One of the biggest problems with linear types is unwinding - what should you do duriing panic? They cannot be dropped, thus you cannot continue unwinding, and abort the program. This crate provides a way to convert unwinding to Poll::Pending, so you can handle it in your own way.

A web server may use this to cancel all futures associated with a thread that panicked without having catch_unwind.

Dependencies

~47KB