Skip to content

Commit 59cdbb9

Browse files
committed
use web_task for cancellable wasm tasks
1 parent be4114b commit 59cdbb9

File tree

5 files changed

+9
-225
lines changed

5 files changed

+9
-225
lines changed

crates/bevy_tasks/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ crossbeam-queue = { version = "0.3", default-features = false, features = [
5454
] }
5555

5656
[target.'cfg(target_arch = "wasm32")'.dependencies]
57-
pin-project = "1"
58-
async-channel = { version = "2.3.0", default-features = false }
57+
web-task = "1"
5958

6059
[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
6160
async-task = { version = "4.4.0", default-features = false, features = [

crates/bevy_tasks/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ mod executor;
7676
pub mod futures;
7777
mod iter;
7878
mod slice;
79-
mod task;
8079
mod usages;
8180

8281
cfg::async_executor! {
@@ -86,9 +85,9 @@ cfg::async_executor! {
8685
}
8786

8887
// Exports
88+
pub use async_task::Task;
8989
pub use iter::ParallelIterator;
9090
pub use slice::{ParallelSlice, ParallelSliceMut};
91-
pub use task::Task;
9291
pub use usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};
9392

9493
pub use futures_lite;

crates/bevy_tasks/src/single_threaded_task_pool.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,23 +194,21 @@ impl TaskPool {
194194
{
195195
crate::cfg::switch! {{
196196
crate::cfg::web => {
197-
Task::wrap_future(future)
197+
web_task::spawn_local(future)
198198
}
199199
crate::cfg::std => {
200200
LOCAL_EXECUTOR.with(|executor| {
201201
let task = executor.spawn(future);
202202
// Loop until all tasks are done
203203
while executor.try_tick() {}
204-
205-
Task::new(task)
204+
task
206205
})
207206
}
208207
_ => {
209208
let task = LOCAL_EXECUTOR.spawn(future);
210209
// Loop until all tasks are done
211210
while LOCAL_EXECUTOR.try_tick() {}
212-
213-
Task::new(task)
211+
task
214212
}
215213
}}
216214
}
@@ -330,13 +328,13 @@ crate::cfg::std! {
330328
if {
331329
pub trait MaybeSend {}
332330
impl<T> MaybeSend for T {}
333-
331+
334332
pub trait MaybeSync {}
335333
impl<T> MaybeSync for T {}
336334
} else {
337335
pub trait MaybeSend: Send {}
338336
impl<T: Send> MaybeSend for T {}
339-
337+
340338
pub trait MaybeSync: Sync {}
341339
impl<T: Sync> MaybeSync for T {}
342340
}

crates/bevy_tasks/src/task.rs

Lines changed: 0 additions & 212 deletions
This file was deleted.

crates/bevy_tasks/src/task_pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl TaskPool {
560560
where
561561
T: Send + 'static,
562562
{
563-
Task::new(self.executor.spawn(future))
563+
self.executor.spawn(future)
564564
}
565565

566566
/// Spawns a static future on the thread-local async executor for the
@@ -578,7 +578,7 @@ impl TaskPool {
578578
where
579579
T: 'static,
580580
{
581-
Task::new(TaskPool::LOCAL_EXECUTOR.with(|executor| executor.spawn(future)))
581+
TaskPool::LOCAL_EXECUTOR.with(|executor| executor.spawn(future))
582582
}
583583

584584
/// Runs a function with the local executor. Typically used to tick

0 commit comments

Comments
 (0)