Skip to content

Commit 815ee1d

Browse files
committed
pass mut ref to spawn_load_task and dedup code
1 parent 314592d commit 815ee1d

File tree

1 file changed

+17
-18
lines changed
  • crates/bevy_asset/src/server

1 file changed

+17
-18
lines changed

crates/bevy_asset/src/server/mod.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,7 @@ impl AssetServer {
383383
);
384384

385385
if should_load {
386-
let task = self.spawn_load_task(handle.clone().untyped(), path, guard);
387-
388-
#[cfg(not(any(target_arch = "wasm32", not(feature = "multi_threaded"))))]
389-
infos.pending_tasks.insert(handle.id().untyped(), task);
390-
391-
#[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))]
392-
task.detach();
386+
self.spawn_load_task(handle.clone().untyped(), path, &mut *infos, guard);
393387
}
394388

395389
handle
@@ -413,13 +407,7 @@ impl AssetServer {
413407
);
414408

415409
if should_load {
416-
let task = self.spawn_load_task(handle.clone(), path, guard);
417-
418-
#[cfg(not(any(target_arch = "wasm32", not(feature = "multi_threaded"))))]
419-
infos.pending_tasks.insert(handle.id(), task);
420-
421-
#[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))]
422-
task.detach();
410+
self.spawn_load_task(handle.clone(), path, &mut *infos, guard);
423411
}
424412

425413
handle
@@ -429,15 +417,26 @@ impl AssetServer {
429417
&self,
430418
handle: UntypedHandle,
431419
path: AssetPath<'static>,
420+
infos: &mut AssetInfos,
432421
guard: G,
433-
) -> Task<()> {
422+
) {
423+
let owned_handle = handle.clone();
434424
let server = self.clone();
435-
IoTaskPool::get().spawn(async move {
436-
if let Err(err) = server.load_internal(Some(handle), path, false, None).await {
425+
let task = IoTaskPool::get().spawn(async move {
426+
if let Err(err) = server
427+
.load_internal(Some(owned_handle), path, false, None)
428+
.await
429+
{
437430
error!("{}", err);
438431
}
439432
drop(guard);
440-
})
433+
});
434+
435+
#[cfg(not(any(target_arch = "wasm32", not(feature = "multi_threaded"))))]
436+
infos.pending_tasks.insert(handle.id(), task);
437+
438+
#[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))]
439+
task.detach();
441440
}
442441

443442
/// Asynchronously load an asset that you do not know the type of statically. If you _do_ know the type of the asset,

0 commit comments

Comments
 (0)