Bevy Async Task
A minimum crate for ergonomic abstractions to async programming in Bevy for all platforms. This crate helps to run async tasks in the background with timeout support and retrieve results in the same system, and helps to block on futures within synchronous contexts.
There is full API support for wasm and native. Android and iOS are untested (Help needed).
Bevy version support
bevy | bevy_async_task |
---|---|
0.13 | 0.1, main |
<= 0.13 | Unsupported |
Usage
Please see examples for more.
Polling in systems
Poll one task at a time with AsyncTaskRunner<T>
:
async
Poll many similar tasks simultaneously with AsyncTaskPool<T>
:
Also, you may use timeouts or block on an AsyncTask<T>
:
// Blocking:
let task = new;
assert_eq!;
// Timeout:
let task = pending.with_timeout;
assert!;
Need to steer manually? Break the task into parts.
let task = new;
// Break the task into a runnable future and a receiver
let = task.into_parts;
// The receiver will always be `None` until it is polled by Bevy.
assert_eq!;
// Run the future
let task_pool = get;
let task = task_pool.spawn;
task.detach; // Forget and run in background
// Spin-lock, waiting for the result
let result = loop ;
assert_eq!;
Community
All Loopy projects and development happens in the Loopy Discord. The discord is open to the public.
Contributions are welcome by pull request. The Rust code of conduct applies.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.