zephyr::work::futures

Struct Answer

Source
pub struct Answer<T> { /* private fields */ }
Expand description

An answer to a completed Future.

The are two times we need to wait on a future running to completion: the outer initial executor invocation from the main thread, and running an async thread which will have a join method.

For both cases, we will use a Semaphore to indicate when the data is available.

The main issue is that this type is intended to be one shot. Trying to load a second value will invalidate the data structure (the item will be replaced, but there is a race with the semaphore).

TODO: Currently, the data is stored inside of a Mutex. This isn’t actually necessary (the semaphore already manages the coordination), and only a memory barrier would be needed, which would be provided by the semaphore. So, this should be changed to just unsafely share the data, similar to how a mutex is implemented.

Implementations§

Source§

impl<T> Answer<T>

Source

pub fn new() -> Self

Construct a new Answer that does not have the result.

Source

pub fn place(&self, item: T)

Place the item into the Answer.

§Panic

If the answer already contains an item, this will panic.

§TODO

We could check that the Answer has ever been used, not just that it has an answer in it.

Source

pub fn take(&self) -> T

Synchronously wait for an Answer.

Blocks the current thread until an answer is available, returning it.

Source

pub async fn take_async(&self) -> T

Asynchronously wait for an answer.

Auto Trait Implementations§

§

impl<T> !Freeze for Answer<T>

§

impl<T> !RefUnwindSafe for Answer<T>

§

impl<T> Send for Answer<T>
where T: Send,

§

impl<T> Sync for Answer<T>
where T: Send,

§

impl<T> Unpin for Answer<T>
where T: Unpin,

§

impl<T> UnwindSafe for Answer<T>
where T: UnwindSafe,

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.