1
0
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:
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

@ -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.

View File

@ -1,6 +1,6 @@
[package]
name = "actix-utils"
version = "1.0.5"
version = "1.0.6"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix utils - various actix net related services"
keywords = ["network", "framework", "async", "futures"]

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, ());
}
}