#future #async #main

nightly alligator

Alligator is for getting the output value from a future

1 unstable release

Uses old Rust 2015

0.1.0 Dec 7, 2018

#1171 in Asynchronous

MIT license

11KB
160 lines

alligator 🐊

Alligator is a small crate for getting the output value from a future

#![feature(async_await)]
#![feature(futures_api)]
#[macro_use] extern crate alligator;

async fn hello_world() -> &'static str {
  "Hello World"
}

fn main() {
  println!("{}", later!{ hello_world() });
}

lib.rs:

Alligator 🐊

Alligator is a small crate for getting the output value from a future

Later, the only strucutre in alligater, is a wrapper around an object that implements Future. The use of Later is for polling to completion the contained future only when the Output value is needed.

The goal of alligator is to provide an easy way to get the value from most implementations of Future. The implementation requirements for Futures wrapped by Later are under the secion Future Requirements.

Issues

There is one problem with Later, it uses Pin::new_unchecked with poll. This is so that Later works with the return of an async fn, which doesn't implement UnPin.

Future Requirements

To use Objets that implement Future with Later, the poll method needs to be implemented as follows.

  • The localWaker parameter of poll must be used by the future.
  • The call to wake on the parameter (or any Waker derived from the parameter) must only be used when the next call to poll will return Poll::Ready

Example

// `l!` and `later!` macros are just shortcuts for Later::new
let do_later = l!{ get_fut() };

// Do work that doesn't require or
// use the Output of the future returned
// by get_fut

// Prints the Output value of the future
println!("{}", do_later);

Note

Unfortunately alligator isn't #[no_std] compatable. Later uses the std thread and sync mechanics to wait for a future to poll to completion.

No runtime deps