About
pecs is a plugin for Bevy that allows you
to execute code asynchronously by chaining multple promises with respect
of Bevy's ecs enviroment.
pecs is acronim for Promise Entity Component System.
Resources:
Features
- promise chaining with
then(),ok_then()andor_else() - state passing (
statefor promises is likeselffor items) - complete type inference (the next promise knows tye types of previous result)
- out-of-the-box timer and http promises via
asynmod and statefulstate.asyn() - custom promise registretion (add any asyn function you want!)
system paramsfetching (promiseasyn!funcs accepts the same params the bevy systems does)- nested promises (with chaining, obviously)
- combining promises with any/all for tuple/vec of promises via stateles
Promise::any()/Promise::all()or statefulstate.any()/state.all() - state mapping via
with(value)/map(func)(change state type/value over chain calls) - result mapping via
with_ok(value)/map_ok(func)(change Ok type/value over chain calls) - error mapping via
with_err(value)/map_err(func)(change Err type over chain calls)
Example
use ;
use *;
There is otput of the above example, pay some attention to time stamps:
15:52:20.459635Z INFO bevy_render::renderer: AdapterInfo { ... }
15:52:20.643082Z INFO simple: Wait a second..
15:52:21.659898Z INFO simple: Looks like I need to know how large is the Bevy main web page!
15:52:21.775228Z INFO simple: It is 17759 bytes!
15:52:21.775319Z INFO simple: It tooks 1.13s to do this job.
15:52:21.775342Z INFO simple: Exiting now
Work in Progress
This repo is more like an experimental-proof-of-concept then a production-ready library. API could and will change. App will crash (there are some untested unsafe blocks), some promises will silently drop (there are stil no unit tests), documentation is incomplete and so on. But. But. Examples works like a charm. And this fact gives us a lot of hope.
License
The pecs is dual-licensed under either:
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are very good reasons to include both.