bevy/crates/bevy_asset
Zachary Harrold c1bb4b255d
[Adopted] Add a method for asynchronously waiting for an asset to load (#15913)
# Objective

Currently, is is very painful to wait for an asset to load from the
context of an `async` task. While bevy's `AssetServer` is asynchronous
at its core, the public API is mainly focused on being used from
synchronous contexts such as bevy systems. Currently, the best way of
waiting for an asset handle to finish loading is to have a system that
runs every frame, and either listens for `AssetEvents` or manually polls
the asset server. While this is an acceptable interface for bevy
systems, it is extremely awkward to do this in a way that integrates
well with the `async` task system. At my work we had to create our own
(inefficient) abstraction that encapsulated the boilerplate of checking
an asset's load status and waking up a task when it's done.

## Solution

Add the method `AssetServer::wait_for_asset`, which returns a future
that suspends until the asset associated with a given `Handle` either
finishes loading or fails to load.

## Testing

- CI

## Notes

This is an adoption of #14431, the above description is directly from
that original PR.

---------

Co-authored-by: Joseph <21144246+JoJoJet@users.noreply.github.com>
Co-authored-by: andriyDev <andriydzikh@gmail.com>
2024-10-15 02:50:33 +00:00
..
macros Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
src [Adopted] Add a method for asynchronously waiting for an asset to load (#15913) 2024-10-15 02:50:33 +00:00
Cargo.toml Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
README.md Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00

Bevy Asset

License Crates.io Downloads Docs Discord