pub struct Promise<T> { /* private fields */ }
Expand description
An asynchronous net_box::Conn
response.
Implementations§
source§impl<T> Promise<T>
impl<T> Promise<T>
sourcepub fn state(&self) -> State
pub fn state(&self) -> State
Check if the promise is kept. Returns an error if one was received or if connection is closed.
sourcepub fn wait(self) -> Result<T>
pub fn wait(self) -> Result<T>
Waits indefinitely until the promise is kept or the connection is
closed. Consumes self
.
sourcepub fn wait_timeout(self, timeout: Duration) -> TryGet<T, Error>
pub fn wait_timeout(self, timeout: Duration) -> TryGet<T, Error>
sourcepub fn replace_cond(&mut self, cond: Rc<Cond>) -> Rc<Cond>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more