Skip to content

Conversation

@NthTensor
Copy link
Owner

This unifies ThreadPool::spawn, ThreadPool::spawn_future and ThreadPool::spawn_async into a single generic ThreadPool::spawn function, and does the same for Scope::spawn, Scope::spawn_future and Scope::spawn_async.

This brings the api closer to bevy_tasks (which only supports async spawns) without sacrificing the rayon-style blocking spawns.

All of these are now valid:

// Spawn a blocking task
THREAD_POOL.spawn(|| {
    for i in 0..100 {
        blocking_work(i);
    }
});

// Spawn a future
let task = THREAD_POOL.spawn(async {
    let mut result = None;
    for i in 0..100 {
        result = async_work(i).await;
    }
    result
});

// Spawn an async function
THREAD_POOL.spawn(do_something).detach();

async fn do_something() {
    for i in 0..100 {
        result = async_work(i).await;
    }
}

@NthTensor NthTensor marked this pull request as ready for review August 25, 2025 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants