diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index 3d397e9d..4a5ec485 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [1.0.6] - 2020-01-08 + +* Add `Clone` impl for `condition::Waiter` + ## [1.0.5] - 2020-01-08 * Add `Condition` type. diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index 5470ef01..62207b36 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-utils" -version = "1.0.5" +version = "1.0.6" authors = ["Nikolay Kim "] description = "Actix utils - various actix net related services" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-utils/src/condition.rs b/actix-utils/src/condition.rs index 4d32f010..8830453d 100644 --- a/actix-utils/src/condition.rs +++ b/actix-utils/src/condition.rs @@ -14,6 +14,12 @@ struct Inner { data: Slab>, } +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, } +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, ()); } }