Skip to content

Commit a0fdfc8

Browse files
fix spawn scope
1 parent d0c5c10 commit a0fdfc8

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/imex/transfer.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,7 @@ async fn run_get_request(
543543
};
544544

545545
let start = start.next(blob.hash);
546-
547-
// `iroh_io` io needs to be done on a local spawn
548-
let ticket = ticket.clone();
549-
let context = context.clone();
550-
let name = blob.name.clone();
551-
let jobs = jobs.clone();
552-
let done = rt
553-
.local_pool()
554-
.spawn_pinned(move || {
555-
Box::pin(async move { on_blob(context, jobs, ticket, start, &name).await })
556-
})
557-
.await??;
546+
let done = on_blob(context, &rt, &jobs, &ticket, start, &blob.name).await?;
558547

559548
next = done.next();
560549
};
@@ -568,9 +557,10 @@ async fn run_get_request(
568557
/// This writes the blobs to the blobdir. If the blob is the database it will import it to
569558
/// the database of the current [`Context`].
570559
async fn on_blob(
571-
context: Context,
572-
jobs: Arc<Mutex<JoinSet<()>>>,
573-
ticket: Ticket,
560+
context: &Context,
561+
rt: &runtime::Handle,
562+
jobs: &Arc<Mutex<JoinSet<()>>>,
563+
ticket: &Ticket,
574564
state: fsm::AtBlobHeader,
575565
name: &str,
576566
) -> Result<fsm::AtEndBlob> {
@@ -592,12 +582,23 @@ async fn on_blob(
592582
context.get_blobdir().join(blobname)
593583
};
594584

585+
// `iroh_io` io needs to be done on a local spawn
595586
let file_path = path.clone();
596-
let mut file = iroh_io::File::create(move || std::fs::File::create(&file_path)).await?;
597-
// TODO: ProgressEmitter doesn't support writers :(
598-
// let mut wrapped_file = progress.wrap_async_write(&mut file);
599-
let done = state.write_all(&mut file).await?;
600-
file.sync().await?;
587+
let done = rt
588+
.local_pool()
589+
.spawn_pinned(move || {
590+
let file_path = file_path.clone();
591+
Box::pin(async move {
592+
let mut file =
593+
iroh_io::File::create(move || std::fs::File::create(&file_path)).await?;
594+
// TODO: ProgressEmitter doesn't support writers :(
595+
// let mut wrapped_file = progress.wrap_async_write(&mut file);
596+
let done = state.write_all(&mut file).await?;
597+
file.sync().await?;
598+
anyhow::Ok(done)
599+
})
600+
})
601+
.await??;
601602

602603
if name.starts_with("db/") {
603604
let context = context.clone();

0 commit comments

Comments
 (0)