[−][src]Macro pasts::poll
Create a future that polls multiple futures concurrently.
Takes an array of types that implement Future
and
Unpin
. If you're dealing with futures that don't
implement Unpin
, you can use the
task!()
macro to make it implement
Unpin
. The resulting type will be the same as
other futures created with task!()
.
Examples
Await on The Fastest Future
poll!()
will always poll the first future in the array first.
use pasts::prelude::*; async fn async_main() { task!(let hello = async { "Hello" }); task!(let world = async { "World!"}); // Hello is ready, so returns with index and result. assert_eq!((0, "Hello"), poll!(hello, world).await); } exec!(async_main());
Await the Outputs of Two Futures Concurrently
use pasts::prelude::*; async fn async_main() { task!(let hello = async { (0, "Hello") }); task!(let world = async { (1, "World!") }); let mut task_queue = vec![hello, world]; while !task_queue.is_empty() { let (index, output) = poll!(task_queue).await; task_queue.remove(index); match output { (0, a) => assert_eq!(a, "Hello"), (1, a) => assert_eq!(a, "World!"), _ => unreachable!(), } } } exec!(async_main());