#bevy #background-task #bevy-plugin #task-pool #events #future #callback

bevy_background_compute

Bevy plugin for better task handling

8 releases (4 breaking)

0.5.0 Nov 18, 2023
0.4.1 Nov 13, 2023
0.3.0 Nov 12, 2023
0.2.1 Nov 12, 2023
0.1.1 Sep 12, 2022

#734 in Game dev

Download history 13/week @ 2024-02-16 10/week @ 2024-02-23 1/week @ 2024-03-01 1/week @ 2024-03-08 75/week @ 2024-03-29 14/week @ 2024-04-05

89 downloads per month

MIT license

13KB
163 lines

Bevy background compute

This bevy plugin provides improvements to handling of background tasks. It adds a Commands extension to more easily place a Future onto bevy's TaskPool and upon completion it will send a callback in the form of an event containing the result.

Full usage example

Check out the basic_usage example with

cargo run --example basic_usage

Registering a type as background computable

In order to keep track of running tasks and to produce completion events every type returned by your Futures has to be registered using the BackgroundComputePlugin<T>.

app.add_plugins(BackgroundComputePlugin::<MyType>::default())

Computing a Future in background

commands.compute_in_background(async {
    // Your code here
});

Getting the result

// Create a system consuming BackgroundComputeComplete<T> events
fn my_callback_sys(
    mut events: EventReader<BackgroundComputeComplete<MyType>>
) {
    // Handle like any other bevy event
}

Version compatibility

Plugin Bevy
0.1 0.8
0.2 0.9
0.3 0.10
0.4 0.11

Dependencies

~10MB
~187K SLoC