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

An asynchronous net_box::Conn response.

Implementations§

source§

impl<T> Promise<T>

source

pub fn state(&self) -> State

Check if the promise is kept. Returns an error if one was received or if connection is closed.

source

pub fn try_get(self) -> TryGet<T, Error>

Check if the promise is kept and return the value. Consumes self. If you only need to check the state of the promise, use the state method.

Does not yield.

Returns:

  • Ok(value) if value is available.
  • Err(error) if
    • received a response with error
    • connection was closed
  • Pending(self) otherwise
source

pub fn wait(self) -> Result<T>

Waits indefinitely until the promise is kept or the connection is closed. Consumes self.

source

pub fn wait_timeout(self, timeout: Duration) -> TryGet<T, Error>

Waits for the promise to be kept. Consumes self.

Assume this yields.

Returns:

  • Ok(value) if promise was successfully kept within time limit.
  • Err(error)
    • received a response with error
    • connection was closed
  • Pending on timeout
source

pub fn replace_cond(&mut self, cond: Rc<Cond>) -> Rc<Cond>

Replaces the contained Cond used for wait & wait_timeout methods with the provided one. Useful if several promises need to be waited on.

Example
use tarantool::{fiber::Cond, net_box::{Conn, promise::{Promise, State}}};
use std::rc::Rc;

let c1: Conn = get_conn("addr1");
let mut p1: Promise<()> = c1.call_async("foo", ()).unwrap();
let c2: Conn = get_conn("addr2");
let mut p2: Promise<()> = c2.call_async("foo", ()).unwrap();
let cond = Rc::new(Cond::new());
p1.replace_cond(cond.clone());
p2.replace_cond(cond.clone());
cond.wait();
assert!(
    matches!(p1.state(), State::Kept | State::ReceivedError) ||
    matches!(p2.state(), State::Kept | State::ReceivedError)
)

Trait Implementations§

source§

impl<T> Debug for Promise<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Promise<T>

§

impl<T> !Send for Promise<T>

§

impl<T> !Sync for Promise<T>

§

impl<T> Unpin for Promise<T>

§

impl<T> !UnwindSafe for Promise<T>

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.