Type Alias zng_var::ResponseVar

source ·
pub type ResponseVar<T> = ReadOnlyVar<Response<T>, ArcVar<Response<T>>>;
Expand description

Variable used to listen to a one time signal that an async operation has completed.

Use response_var or response_done_var to init.

Aliased Type§

struct ResponseVar<T>(/* private fields */);

Implementations§

source§

impl<T: VarValue> ResponseVar<T>

source

pub fn with_rsp<R>(&self, read: impl FnOnce(&T) -> R) -> Option<R>

Visit the response, if present.

source

pub fn with_new_rsp<R>(&self, read: impl FnOnce(&T) -> R) -> Option<R>

Visit the response, if present and new.

source

pub fn is_done(&self) -> bool

If the response is received.

source

pub fn is_waiting(&self) -> bool

If the response is not received yet.

source

pub fn rsp(&self) -> Option<T>

Clone the response value, if present.

source

pub async fn wait_rsp(&self) -> T

Returns a future that awaits until a response is received and then returns a clone.

source

pub async fn wait_into_rsp(self) -> T

Returns a future that awaits until a response is received and then returns it.

Will clone the value if the variable is shared.

Note that ResponseVar<T> implements IntoFuture so you can also just .await the variable.

source

pub async fn wait_done(&self)

Returns a future that awaits until a response is received.

source

pub fn rsp_new(&self) -> Option<T>

Clone the response, if present and new.

source

pub fn into_rsp(self) -> Option<T>

Into response, if received.

Clones if the variable is has more than one strong reference.

source

pub fn map_rsp<O, I, M>(&self, waiting_value: I, map: M) -> impl Var<O>
where O: VarValue, I: Fn() -> O + Send + Sync + 'static, M: FnOnce(&T) -> O + Send + 'static,

Map the response value using map, if the variable is awaiting a response uses the waiting_value first.

source

pub fn map_response<O, M>(&self, map: M) -> ResponseVar<O>
where O: VarValue, M: FnMut(&T) -> O + Send + 'static,

Map to another response variable.

Trait Implementations§

source§

impl<T: VarValue> IntoFuture for ResponseVar<T>

source§

type Output = T

The output that the future will produce on completion.
source§

type IntoFuture = Pin<Box<dyn Future<Output = T> + Sync + Send>>

Which kind of future are we turning this into?
source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more