#synchronous #valid #future #convert #inefficient #function

no-std spin_future

Convert synchronous functions into valid but inefficient futures

1 unstable release

0.1.0 Oct 2, 2020

#1623 in Asynchronous

Apache-2.0 OR MIT

5KB
71 lines

spin_future

Convert synchronous functions into valid but inefficient futures.

This crate needs rust 1.46 or newer to get around an interesting issue.

The key trick to make this valid is that we always call the waker if we are going to return Pending. That way the executor is guaranteed to continue polling us. I got this trick from user HadrienG in this Rust forum post.


lib.rs:

Convert synchronous functions into valid but inefficient futures.

This crate needs rust 1.46 or newer to get around an interesting issue.

The key trick to make this valid is that we always call the waker if we are going to return Pending. That way the executor is guaranteed to continue polling us. I got this trick from user HadrienG in this Rust forum post.

No runtime deps