mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 21:22:57 +01:00
register current task in counters available method.
This commit is contained in:
parent
fa72975f34
commit
9982a9498d
@ -1,5 +1,10 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.4.6] - 2019-10-08
|
||||||
|
|
||||||
|
* Refactor `Counter` type. register current task in available method.
|
||||||
|
|
||||||
|
|
||||||
## [0.4.5] - 2019-07-19
|
## [0.4.5] - 2019-07-19
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-utils"
|
name = "actix-utils"
|
||||||
version = "0.4.5"
|
version = "0.4.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"]
|
||||||
|
@ -25,11 +25,13 @@ impl Counter {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get counter guard.
|
||||||
pub fn get(&self) -> CounterGuard {
|
pub fn get(&self) -> CounterGuard {
|
||||||
CounterGuard::new(self.0.clone())
|
CounterGuard::new(self.0.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if counter is not at capacity
|
/// Check if counter is not at capacity. If counter at capacity
|
||||||
|
/// it registers notification for current task.
|
||||||
pub fn available(&self) -> bool {
|
pub fn available(&self) -> bool {
|
||||||
self.0.available()
|
self.0.available()
|
||||||
}
|
}
|
||||||
@ -57,11 +59,7 @@ impl Drop for CounterGuard {
|
|||||||
|
|
||||||
impl CounterInner {
|
impl CounterInner {
|
||||||
fn inc(&self) {
|
fn inc(&self) {
|
||||||
let num = self.count.get() + 1;
|
self.count.set(self.count.get() + 1);
|
||||||
self.count.set(num);
|
|
||||||
if num == self.capacity {
|
|
||||||
self.task.register();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dec(&self) {
|
fn dec(&self) {
|
||||||
@ -73,6 +71,11 @@ impl CounterInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn available(&self) -> bool {
|
fn available(&self) -> bool {
|
||||||
self.count.get() < self.capacity
|
if self.count.get() < self.capacity {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
self.task.register();
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user