Skip to content

Commit 869d659

Browse files
committed
fix: time and spawn
1 parent b1ad881 commit 869d659

File tree

16 files changed

+30
-29
lines changed

16 files changed

+30
-29
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/expiring-tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ async fn print_store_info(store: &Store) -> anyhow::Result<()> {
122122
}
123123

124124
async fn info_task(store: Store) -> anyhow::Result<()> {
125-
tokio::time::sleep(Duration::from_secs(1)).await;
125+
n0_future::time::sleep(Duration::from_secs(1)).await;
126126
loop {
127127
print_store_info(&store).await?;
128-
tokio::time::sleep(Duration::from_secs(5)).await;
128+
n0_future::time::sleep(Duration::from_secs(5)).await;
129129
}
130130
}
131131

132132
async fn delete_expired_tags_task(store: Store, prefix: &str) -> anyhow::Result<()> {
133133
loop {
134134
delete_expired_tags(&store, prefix, false).await?;
135-
tokio::time::sleep(Duration::from_secs(5)).await;
135+
n0_future::time::sleep(Duration::from_secs(5)).await;
136136
}
137137
}
138138

examples/limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn throttle(delay_ms: u64) -> EventSender {
156156
);
157157
// we could compute the delay from the size of the data to have a fixed rate.
158158
// but the size is almost always 16 KiB (16 chunks).
159-
tokio::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
159+
n0_future::time::sleep(std::time::Duration::from_millis(delay_ms)).await;
160160
msg.tx.send(Ok(())).await.ok();
161161
});
162162
}

src/api/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl Downloader {
342342
pub fn new(store: &Store, endpoint: &Endpoint) -> Self {
343343
let (tx, rx) = tokio::sync::mpsc::channel::<SwarmMsg>(32);
344344
let actor = DownloaderActor::new(store.clone(), endpoint.clone());
345-
tokio::spawn(actor.run(rx));
345+
n0_future::task::spawn(actor.run(rx));
346346
Self { client: tx.into() }
347347
}
348348

src/get.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
//! [iroh]: https://docs.rs/iroh
1919
use std::{
2020
fmt::{self, Debug},
21-
time::{Duration, Instant},
21+
time::Duration,
2222
};
2323

2424
use anyhow::Result;
2525
use bao_tree::{io::fsm::BaoContentItem, ChunkNum};
2626
use fsm::RequestCounters;
27+
use n0_future::time::Instant;
2728
use n0_snafu::SpanTrace;
2829
use nested_enum_utils::common_fields;
2930
use serde::{Deserialize, Serialize};

src/provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub async fn handle_connection(
308308
while let Ok(pair) = StreamPair::accept(&connection, progress.clone()).await {
309309
let span = debug_span!("stream", stream_id = %pair.stream_id());
310310
let store = store.clone();
311-
tokio::spawn(handle_stream(pair, store).instrument(span));
311+
n0_future::task::spawn(handle_stream(pair, store).instrument(span));
312312
}
313313
progress
314314
.connection_closed(|| ConnectionClosed { connection_id })

src/store/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ pub mod tests {
15611561
let ranges = ChunkRanges::all();
15621562
let (hash, bao) = create_n0_bao(&data, &ranges)?;
15631563
let obs = store.observe(hash);
1564-
let task = tokio::spawn(async move {
1564+
let task = n0_future::task::spawn(async move {
15651565
obs.await_completion().await?;
15661566
api::Result::Ok(())
15671567
});

src/store/fs/meta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl Actor {
766766
self.cmds.push_back(cmd.into()).ok();
767767
let tx = db.begin_read().context(TransactionSnafu)?;
768768
let tables = ReadOnlyTables::new(&tx).context(TableSnafu)?;
769-
let timeout = tokio::time::sleep(self.options.max_read_duration);
769+
let timeout = n0_future::time::sleep(self.options.max_read_duration);
770770
pin!(timeout);
771771
let mut n = 0;
772772
while let Some(cmd) = self.cmds.extract(Command::read_only, &mut timeout).await
@@ -784,7 +784,7 @@ impl Actor {
784784
let ftx = self.ds.begin_write();
785785
let tx = db.begin_write().context(TransactionSnafu)?;
786786
let mut tables = Tables::new(&tx, &ftx).context(TableSnafu)?;
787-
let timeout = tokio::time::sleep(self.options.max_read_duration);
787+
let timeout = n0_future::time::sleep(self.options.max_read_duration);
788788
pin!(timeout);
789789
let mut n = 0;
790790
while let Some(cmd) = self

src/store/fs/util/entity_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl<P: Params> EntityManager<P> {
723723
options.entity_response_inbox_size,
724724
options.entity_futures_initial_capacity,
725725
);
726-
tokio::spawn(actor.run());
726+
n0_future::task::spawn(actor.run());
727727
Self(send)
728728
}
729729

src/store/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub async fn run_gc(store: Store, config: GcConfig) {
221221
let mut live = HashSet::new();
222222
loop {
223223
live.clear();
224-
tokio::time::sleep(config.interval).await;
224+
n0_future::time::sleep(config.interval).await;
225225
if let Some(ref cb) = config.add_protected {
226226
match (cb)(&mut live).await {
227227
ProtectOutcome::Continue => {}

0 commit comments

Comments
 (0)