mirror of
https://github.com/fafhrd91/actix-net
synced 2025-01-31 09:12:08 +01:00
Add Clone impl for condition::Waiter
This commit is contained in:
parent
9f00daea80
commit
3551d6674d
@ -1,5 +1,9 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [1.0.6] - 2020-01-08
|
||||||
|
|
||||||
|
* Add `Clone` impl for `condition::Waiter`
|
||||||
|
|
||||||
## [1.0.5] - 2020-01-08
|
## [1.0.5] - 2020-01-08
|
||||||
|
|
||||||
* Add `Condition` type.
|
* Add `Condition` type.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-utils"
|
name = "actix-utils"
|
||||||
version = "1.0.5"
|
version = "1.0.6"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix utils - various actix net related services"
|
description = "Actix utils - various actix net related services"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@ -14,6 +14,12 @@ struct Inner {
|
|||||||
data: Slab<Option<LocalWaker>>,
|
data: Slab<Option<LocalWaker>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Condition {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Condition {
|
impl Condition {
|
||||||
pub fn new() -> Condition {
|
pub fn new() -> Condition {
|
||||||
Condition(Cell::new(Inner { data: Slab::new() }))
|
Condition(Cell::new(Inner { data: Slab::new() }))
|
||||||
@ -51,6 +57,16 @@ pub struct Waiter {
|
|||||||
inner: Cell<Inner>,
|
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 {
|
impl Future for Waiter {
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
@ -98,7 +114,14 @@ mod tests {
|
|||||||
lazy(|cx| Pin::new(&mut waiter).poll(cx)).await,
|
lazy(|cx| Pin::new(&mut waiter).poll(cx)).await,
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
);
|
);
|
||||||
|
let mut waiter2 = waiter.clone();
|
||||||
|
assert_eq!(
|
||||||
|
lazy(|cx| Pin::new(&mut waiter2).poll(cx)).await,
|
||||||
|
Poll::Pending
|
||||||
|
);
|
||||||
|
|
||||||
drop(cond);
|
drop(cond);
|
||||||
assert_eq!(waiter.await, ());
|
assert_eq!(waiter.await, ());
|
||||||
|
assert_eq!(waiter2.await, ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user