1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 17:44:34 +01:00

register current task in counters available method.

This commit is contained in:
Nikolay Kim 2019-10-08 15:02:43 +06:00
parent fa72975f34
commit 9982a9498d
3 changed files with 16 additions and 8 deletions

View File

@ -1,5 +1,10 @@
# Changes
## [0.4.6] - 2019-10-08
* Refactor `Counter` type. register current task in available method.
## [0.4.5] - 2019-07-19
### Removed

View File

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

View File

@ -25,11 +25,13 @@ impl Counter {
}))
}
/// Get counter guard.
pub fn get(&self) -> CounterGuard {
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 {
self.0.available()
}
@ -57,11 +59,7 @@ impl Drop for CounterGuard {
impl CounterInner {
fn inc(&self) {
let num = self.count.get() + 1;
self.count.set(num);
if num == self.capacity {
self.task.register();
}
self.count.set(self.count.get() + 1);
}
fn dec(&self) {
@ -73,6 +71,11 @@ impl CounterInner {
}
fn available(&self) -> bool {
self.count.get() < self.capacity
if self.count.get() < self.capacity {
true
} else {
self.task.register();
false
}
}
}