New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASM asset loading #559
WASM asset loading #559
Conversation
In diff --git a/crates/bevy_tasks/src/single_threaded_task_pool.rs b/crates/bevy_tasks/src/single_threaded_task_pool.rs
index 8899feb9..de641760 100644
--- a/crates/bevy_tasks/src/single_threaded_task_pool.rs
+++ b/crates/bevy_tasks/src/single_threaded_task_pool.rs
@@ -59,8 +59,8 @@ impl TaskPool {
/// This is similar to `rayon::scope` and `crossbeam::scope`
pub fn scope<'scope, F, T>(&self, f: F) -> Vec<T>
where
- F: FnOnce(&mut Scope<'scope, T>) + 'scope + Send,
- T: Send + 'static,
+ F: FnOnce(&mut Scope<'scope, T>) + 'scope,
+ T: 'static,
{
let executor = &async_executor::LocalExecutor::new();
let executor: &'scope async_executor::LocalExecutor<'scope> =
@@ -90,8 +90,8 @@ pub struct Scope<'scope, T> {
results: Vec<Arc<Mutex<Option<T>>>>,
}
-impl<'scope, T: Send + 'scope> Scope<'scope, T> {
- pub fn spawn<Fut: Future<Output = T> + 'scope + Send>(&mut self, f: Fut) {
+impl<'scope, T: 'scope> Scope<'scope, T> {
+ pub fn spawn<Fut: Future<Output = T> + 'scope>(&mut self, f: Fut) {
let result = Arc::new(Mutex::new(None));
self.results.push(result.clone());
let f = async move { |
Ok, removing WIP mark as I'm quite happy how it looks like now. @smokku - I've added missing ThreadPool.spawn implementation to single_threaded_task_pool with some comment - could you take a look? |
The multi-threaded implementation returns Maybe we could use oneshot channel to pass a value from inside of |
Looks promising, but I'm not sure if it will work when sender is on other executor than receiver, will try. The other thing is it will require bigger refactoring of single_threaded_task_pool - currently we create async_executor::LocalExecutor for each scope) And I would probably prefer to do that in separate PR |
Also note that I'm sorting out the future of the asset system with @kabergstrom right now, so there will likely be some breaking changes in the near future. |
// But for typical use cases it seems that current implementation should be sufficient: | ||
// caller can spawn long-running future writing results to some channel / event queue | ||
// and simply call detach on returned Task (like AssetServer does) - spawned future | ||
// can write results to some channed / event queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: channel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Sure, I'll try to keep wasm part working and up to date. |
This PR adds basic asset loading support for wasm32 target (see assets_wasm example).
Currently only AssetServer.load is implemented (
AssetServer.load_sync makes
no sense in web context, load_asset_folder is tricky, because it will need some html parsing, but it seems doable in the future).