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
impl FutureQueue
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Arc<FutureQueue>.
Sourcepub fn push<F, T>(&self, future: F) -> FutureHandle
pub fn push<F, T>(&self, future: F) -> FutureHandle
Pushes a future to the FutureQueue. It will sit and wait
to be processed until FutureQueue::poll is called.
Sourcepub fn poll(&self)
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.
Sourcepub fn exchange(&self, handle: &FutureHandle) -> Option<AnyResult>
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.
Sourcepub fn exchange_owned(&self, handle: &FutureHandle) -> Option<AnyResult>
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.
Sourcepub fn exchange_as<T: Any + Send + Sync + 'static>(
&self,
handle: &FutureHandle,
) -> Option<T>
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.
Sourcepub fn exchange_owned_as<T: Any + Send + Sync + 'static>(
&self,
handle: &FutureHandle,
) -> Option<T>
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.
Sourcepub fn get_status(&self, handle: &FutureHandle) -> Option<FutureStatus>
pub fn get_status(&self, handle: &FutureHandle) -> Option<FutureStatus>
Get status of a handle