Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Nov 2, 2024
1 parent bf34d51 commit 420aaf0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![Version](https://img.shields.io/badge/rustc-1.75+-lightgray.svg)](https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html)
![License](https://img.shields.io/crates/l/ntex.svg)
[![codecov](https://codecov.io/gh/ntex-rs/ntex/branch/master/graph/badge.svg)](https://codecov.io/gh/ntex-rs/ntex)
[![Chat on Discord](https://img.shields.io/discord/919288597826387979?label=chat&logo=discord)](https://discord.com/channels/919288597826387979/919288597826387982)
[![Chat on Discord](https://img.shields.io/discord/919288597826387979?label=chat&logo=discord)](https://discord.gg/4GtaeP5Uqu)

</p>
</div>
Expand Down
9 changes: 2 additions & 7 deletions ntex-util/src/services/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ impl Counter {
fn poll_available(&self, cx: &mut task::Context<'_>) -> bool {
self.0.available(cx)
}

/// Get total number of acquired counts
pub fn total(&self) -> usize {
self.0.count.get()
}
}

#[derive(Debug)]
Expand All @@ -90,8 +85,8 @@ impl Drop for CounterGuard {

impl CounterInner {
fn inc(&self) {
let num = self.count.get();
self.count.set(num + 1);
let num = self.count.get() + 1;
self.count.set(num);
if num == self.capacity {
self.task.wake();
}
Expand Down
1 change: 1 addition & 0 deletions ntex-util/src/services/inflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mod tests {

let srv = Pipeline::new(InFlightService::new(1, SleepService(rx))).bind();
assert_eq!(lazy(|cx| srv.poll_ready(cx)).await, Poll::Ready(Ok(())));
assert_eq!(lazy(|cx| srv.poll_not_ready(cx)).await, Poll::Pending);

let srv2 = srv.clone();
ntex::rt::spawn(async move {
Expand Down
9 changes: 7 additions & 2 deletions ntex-util/src/services/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ macro_rules! variant_impl ({$mod_name:ident, $enum_type:ident, $srv_type:ident,

impl<V1: fmt::Debug, V1C, $($T: fmt::Debug,)+ V1R, $($R,)+> fmt::Debug for $fac_type<V1, V1C, $($T,)+ V1R, $($R,)+> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(stringify!(fac_type))
f.debug_struct("Variant")
.field("V1", &self.V1)
$(.field(stringify!($T), &self.$T))+
.finish()
Expand Down Expand Up @@ -295,11 +295,16 @@ mod tests {

#[ntex_macros::rt_test2]
async fn test_variant() {
let factory = variant(fn_factory(|| async { Ok::<_, ()>(Srv1) }))
let factory = variant(fn_factory(|| async { Ok::<_, ()>(Srv1) }));
assert!(format!("{:?}", factory).contains("Variant"));

let factory = factory
.v2(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
.clone()
.v3(fn_factory(|| async { Ok::<_, ()>(Srv2) }))
.clone();
assert!(format!("{:?}", factory).contains("Variant"));

let service = factory.pipeline(&()).await.unwrap().clone();

let mut f = pin::pin!(service.not_ready());
Expand Down
6 changes: 6 additions & 0 deletions ntex-util/src/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ impl Deadline {
}
}

#[inline]
/// Wait when `Sleep` instance get elapsed.
pub async fn wait(&self) {
poll_fn(|cx| self.poll_elapsed(cx)).await
}

/// Resets the `Deadline` instance to a new deadline.
///
/// Calling this function allows changing the instant at which the `Deadline`
Expand Down

0 comments on commit 420aaf0

Please sign in to comment.