Skip to content

Commit 776b59f

Browse files
shadajbikeshedder
authored andcommitted
Don't use Instant::now on WASM
1 parent 694b311 commit 776b59f

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ jobs:
134134
- postgres
135135
feature:
136136
- --features rt_tokio_1
137-
- --features rt_async-std_1
138137
- --features serde --features rt_tokio_1
139-
- --features serde --features rt_async-std_1
140138
runs-on: ubuntu-latest
141139
steps:
142140
- uses: actions/checkout@v3

postgres/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ tokio = { version = "1.29", features = ["rt"] }
3131
tokio-postgres = { version = "0.7.9", default-features = false }
3232
tracing = "0.1.37"
3333

34+
[target.'cfg(target_arch = "wasm32")'.dependencies]
35+
getrandom = { version = "0.2", features = ["js"] }
36+
3437
[dev-dependencies]
3538
config = { version = "0.14", features = ["json"] }
3639
dotenvy = "0.15.0"

src/managed/metrics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
#[cfg(not(target_arch = "wasm32"))]
12
use std::time::{Duration, Instant};
23

34
/// Statistics regarding an object returned by the pool
45
#[derive(Clone, Copy, Debug)]
56
#[must_use]
67
pub struct Metrics {
8+
#[cfg(not(target_arch = "wasm32"))]
79
/// The instant when this object was created
810
pub created: Instant,
11+
#[cfg(not(target_arch = "wasm32"))]
912
/// The instant when this object was last used
1013
pub recycled: Option<Instant>,
1114
/// The number of times the objects was recycled
1215
pub recycle_count: usize,
1316
}
1417

1518
impl Metrics {
19+
#[cfg(not(target_arch = "wasm32"))]
1620
/// Access the age of this object
1721
pub fn age(&self) -> Duration {
1822
self.created.elapsed()
1923
}
24+
#[cfg(not(target_arch = "wasm32"))]
2025
/// Get the time elapsed when this object was last used
2126
pub fn last_used(&self) -> Duration {
2227
self.recycled.unwrap_or(self.created).elapsed()
@@ -26,7 +31,9 @@ impl Metrics {
2631
impl Default for Metrics {
2732
fn default() -> Self {
2833
Self {
34+
#[cfg(not(target_arch = "wasm32"))]
2935
created: Instant::now(),
36+
#[cfg(not(target_arch = "wasm32"))]
3037
recycled: None,
3138
recycle_count: 0,
3239
}

src/managed/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,12 @@ use std::{
6666
atomic::{AtomicUsize, Ordering},
6767
Arc, Mutex, Weak,
6868
},
69-
time::{Duration, Instant},
69+
time::Duration,
7070
};
7171

72+
#[cfg(not(target_arch = "wasm32"))]
73+
use std::time::Instant;
74+
7275
use deadpool_runtime::Runtime;
7376
use tokio::sync::{Semaphore, TryAcquireError};
7477

@@ -409,7 +412,10 @@ impl<M: Manager, W: From<Object<M>>> Pool<M, W> {
409412
}
410413

411414
inner.metrics.recycle_count += 1;
412-
inner.metrics.recycled = Some(Instant::now());
415+
#[cfg(not(target_arch = "wasm32"))]
416+
{
417+
inner.metrics.recycled = Some(Instant::now());
418+
}
413419

414420
Ok(Some(unready_obj.ready()))
415421
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy