FutureQueue

Struct FutureQueue 

Source
pub struct FutureQueue { /* private fields */ }
Expand description

A queue for polling futures. It is stored in here until FutureQueue::poll is run.

Implementations§

Source§

impl FutureQueue

Source

pub fn new() -> Self

Creates a new Arc<FutureQueue>.

Source

pub fn push<F, T>(&self, future: F) -> FutureHandle
where F: Future<Output = T> + Send + 'static, T: Send + Sync + 'static,

Pushes a future to the FutureQueue. It will sit and wait to be processed until FutureQueue::poll is called.

Source

pub fn poll(&self)

Polls all the futures in the future queue and resolves the handles.

This function spawns a new async thread for each item inside the thread and sends updates to the Handle’s receiver.

Source

pub fn exchange(&self, handle: &FutureHandle) -> Option<AnyResult>

Exchanges the future for the result.

When the handle is not successful, it will return nothing. When the handle is successful, it will return the result. The result is cached and can be retrieved multiple times.

Source

pub fn exchange_owned(&self, handle: &FutureHandle) -> Option<AnyResult>

Exchanges the future for the result, taking ownership and consuming the cached result.

When the handle is not successful, it will return nothing. When the handle is successful, it will return the result and remove it from the cache, allowing Arc::try_unwrap to succeed. This method can only be called once per completed future.

Source

pub fn exchange_as<T: Any + Send + Sync + 'static>( &self, handle: &FutureHandle, ) -> Option<T>

Exchanges the handle and safely downcasts it into a specific type.

Source

pub fn exchange_owned_as<T: Any + Send + Sync + 'static>( &self, handle: &FutureHandle, ) -> Option<T>

Exchanges the handle taking ownership and safely downcasts it into a specific type. This method consumes the cached result, allowing Arc::try_unwrap to succeed.

Source

pub fn get_status(&self, handle: &FutureHandle) -> Option<FutureStatus>

Get status of a handle

Source

pub fn cleanup(&self)

Cleans up any completed handles and removes them from the registry.

You can do this manually, however this is typically done at the end of the frame.

Trait Implementations§

Source§

impl Default for FutureQueue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.