Skip to content

Commit ce43f1c

Browse files
committed
fix: more time fixes
1 parent bd3b62a commit ce43f1c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/provider.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
//! Note that while using this API directly is fine, the standard way
44
//! to provide data is to just register a [`crate::BlobsProtocol`] protocol
55
//! handler with an [`iroh::Endpoint`](iroh::protocol::Router).
6-
use std::{
7-
fmt::Debug,
8-
future::Future,
9-
io,
10-
time::{Duration, Instant},
11-
};
6+
use std::{fmt::Debug, future::Future, io, time::Duration};
127

138
use anyhow::Result;
149
use bao_tree::ChunkRanges;
1510
use iroh::endpoint::{self, ConnectionError, VarInt};
1611
use iroh_io::{AsyncStreamReader, AsyncStreamWriter};
17-
use n0_future::StreamExt;
12+
use n0_future::{time::Instant, StreamExt};
1813
use serde::{Deserialize, Serialize};
1914
use snafu::Snafu;
2015
use tokio::select;

src/store/mem.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::{
1414
num::NonZeroU64,
1515
ops::Deref,
1616
sync::Arc,
17-
time::SystemTime,
1817
};
1918

2019
use bao_tree::{
@@ -29,12 +28,13 @@ use bao_tree::{
2928
};
3029
use bytes::Bytes;
3130
use irpc::channel::mpsc;
32-
use n0_future::future::yield_now;
33-
use range_collections::range_set::RangeSetRange;
34-
use tokio::{
35-
sync::watch,
31+
use n0_future::{
32+
future::yield_now,
3633
task::{JoinError, JoinSet},
34+
time::SystemTime,
3735
};
36+
use range_collections::range_set::RangeSetRange;
37+
use tokio::sync::watch;
3838
use tracing::{error, info, instrument, trace, Instrument};
3939

4040
use super::util::{BaoTreeSender, PartialMemStorage};

src/store/util.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use std::{borrow::Borrow, fmt, time::SystemTime};
1+
use std::{borrow::Borrow, fmt};
22

33
use bao_tree::io::mixed::EncodedItem;
44
use bytes::Bytes;
55
use derive_more::{From, Into};
6+
use n0_future::time::SystemTime;
67

78
mod sparse_mem_file;
89
use irpc::channel::mpsc;
@@ -68,6 +69,13 @@ impl fmt::Display for Tag {
6869
impl Tag {
6970
/// Create a new tag that does not exist yet.
7071
pub fn auto(time: SystemTime, exists: impl Fn(&[u8]) -> bool) -> Self {
72+
// On wasm, SystemTime is web_time::SystemTime, but we need a std system time
73+
// to convert to chrono.
74+
// TODO: Upstream to n0-future or expose SystemTimeExt on wasm
75+
#[cfg(wasm_browser)]
76+
let time = std::time::SystemTime::UNIX_EPOCH
77+
+ time.duration_since(SystemTime::UNIX_EPOCH).unwrap();
78+
7179
let now = chrono::DateTime::<chrono::Utc>::from(time);
7280
let mut i = 0;
7381
loop {

0 commit comments

Comments
 (0)