Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ crossbeam-queue = { version = "0.3", default-features = false, features = [
] }

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

[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]
async-task = { version = "4.4.0", default-features = false, features = [
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ mod executor;
pub mod futures;
mod iter;
mod slice;
mod task;
mod usages;

cfg::async_executor! {
Expand All @@ -86,9 +85,9 @@ cfg::async_executor! {
}

// Exports
pub use async_task::Task;
pub use iter::ParallelIterator;
pub use slice::{ParallelSlice, ParallelSliceMut};
pub use task::Task;
pub use usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};

pub use futures_lite;
Expand Down
12 changes: 5 additions & 7 deletions crates/bevy_tasks/src/single_threaded_task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,21 @@ impl TaskPool {
{
crate::cfg::switch! {{
crate::cfg::web => {
Task::wrap_future(future)
web_task::spawn_local(future)
}
crate::cfg::std => {
LOCAL_EXECUTOR.with(|executor| {
let task = executor.spawn(future);
// Loop until all tasks are done
while executor.try_tick() {}

Task::new(task)
task
})
}
_ => {
let task = LOCAL_EXECUTOR.spawn(future);
// Loop until all tasks are done
while LOCAL_EXECUTOR.try_tick() {}

Task::new(task)
task
}
}}
}
Expand Down Expand Up @@ -330,13 +328,13 @@ crate::cfg::std! {
if {
pub trait MaybeSend {}
impl<T> MaybeSend for T {}

pub trait MaybeSync {}
impl<T> MaybeSync for T {}
} else {
pub trait MaybeSend: Send {}
impl<T: Send> MaybeSend for T {}

pub trait MaybeSync: Sync {}
impl<T: Sync> MaybeSync for T {}
}
Expand Down
212 changes: 0 additions & 212 deletions crates/bevy_tasks/src/task.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/bevy_tasks/src/task_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl TaskPool {
where
T: Send + 'static,
{
Task::new(self.executor.spawn(future))
self.executor.spawn(future)
}

/// Spawns a static future on the thread-local async executor for the
Expand All @@ -578,7 +578,7 @@ impl TaskPool {
where
T: 'static,
{
Task::new(TaskPool::LOCAL_EXECUTOR.with(|executor| executor.spawn(future)))
TaskPool::LOCAL_EXECUTOR.with(|executor| executor.spawn(future))
}

/// Runs a function with the local executor. Typically used to tick
Expand Down
6 changes: 6 additions & 0 deletions release-content/migration-guides/web_tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Dropping Tasks in Web Builds
pull_requests: [21795]
---

Dropping a `Task<T>` in a web build now cancels it, call `Task<T>::detach()` to keep the old behavior.
8 changes: 8 additions & 0 deletions release-content/release-notes/web_tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Cancellable Web Tasks
authors: ["@NthTensor","@Gingeh"]
pull_requests: [21795]
---

Async Tasks can now be cancelled in web builds,
this brings the web implementation's behavior into line with native builds.