1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-26 22:07:42 +02:00

Add Clone impl for condition::Waiter

This commit is contained in:
Nikolay Kim
2020-01-08 11:18:56 +06:00
parent 9f00daea80
commit 3551d6674d
3 changed files with 28 additions and 1 deletions

View File

@ -14,6 +14,12 @@ struct Inner {
data: Slab<Option<LocalWaker>>,
}
impl Default for Condition {
fn default() -> Self {
Self::new()
}
}
impl Condition {
pub fn new() -> Condition {
Condition(Cell::new(Inner { data: Slab::new() }))
@ -51,6 +57,16 @@ pub struct Waiter {
inner: Cell<Inner>,
}
impl Clone for Waiter {
fn clone(&self) -> Self {
let token = unsafe { self.inner.get_mut_unsafe() }.data.insert(None);
Waiter {
token,
inner: self.inner.clone(),
}
}
}
impl Future for Waiter {
type Output = ();
@ -98,7 +114,14 @@ mod tests {
lazy(|cx| Pin::new(&mut waiter).poll(cx)).await,
Poll::Pending
);
let mut waiter2 = waiter.clone();
assert_eq!(
lazy(|cx| Pin::new(&mut waiter2).poll(cx)).await,
Poll::Pending
);
drop(cond);
assert_eq!(waiter.await, ());
assert_eq!(waiter2.await, ());
}
}