Expand description
Bevy impulse is an extension to the Bevy game engine that allows you to transform bevy systems into services and workflows that can be used for reactive service-oriented programming.
§Services
One primitive element of reactive programming is a service.
In bevy impulse, a Service
is a bevy system that is associated with an
entity and can be created using Commands::spawn_service
or App::add_service
.
When you spawn a service you will immediately receive a Service
object
which references the newly spawned service. If you do not want to hang onto the Service
object, you can find previously spawned services later using the ServiceDiscovery
system parameter.
Sometimes Service
is not quite the right fit for your use case, so bevy impulse
offers a generalization of services callled Provider
which has some
more options for defining a reactive element.
§Workflows
For complex async workflows, a single bevy system may not be sufficient.
You can instead build workflows using .spawn_workflow
on Commands
or World
.
A workflow lets you create a graph of nodes where each node is a
service (or more generally a provider) with an input,
an output, and possibly streams.
There are various operations that can be performed between nodes, such as
forking and joining. These operations are built using Chain
.
When you spawn your workflow, you will receive a Service
object that
lets you use the workflow as if it’s an ordinary service.
§Impulses
Services and workflows are reusable building blocks for creating a reactive
application. In order to actually run them, call Commands::request
which will provide you with an Impulse
. An impulse is a one-time-use
reaction to a request which you can chain to subsequent reactions using
Impulse::then
. Any impulse chain that you create will only run exactly
once.
Once you’ve finished building your chain, use Impulse::detach
to let it
run freely, or use Impulse::take
to get a Recipient
of the final
result.
Re-exports§
pub use buffer::*;
pub use builder::*;
pub use callback::*;
pub use cancel::*;
pub use chain::*;
pub use channel::*;
pub use disposal::*;
pub use errors::*;
pub use flush::*;
pub use gate::*;
pub use impulse::*;
pub use input::*;
pub use map::*;
pub use map_once::*;
pub use node::*;
pub use operation::*;
pub use promise::*;
pub use provider::*;
pub use request::*;
pub use service::*;
pub use stream::*;
pub use workflow::*;
pub use trim::*;
Modules§
- buffer
- builder
- callback
- cancel
- chain
- channel
- disposal
- errors
- flush
- gate
- impulse
- input
- map
- map_
once - node
- operation
- prelude
- promise
- provider
- request
- service
- stream
- testing
- trim
- workflow
Structs§
- Async
Callback - Use AsyncCallback to indicate that your system or function is meant to define
an async
Callback
. An async callback is not associated with any entity, and it must return aFuture<Output=Response>
that will be polled by the async task pool. - Async
Map - Use AsyncMap to indicate that your function is an async map. A Map is not associated with any entity, and it cannot be a Bevy System. These restrictions allow them to be processed more efficiently.
- Async
Service - Use
AsyncService
to indicate that your system is an asyncService
. Being async means it must return aFuture<Output=Response>
which will be processed by a task pool. - Blocking
Callback - Use BlockingCallback to indicate that your system is meant to define a
blocking
Callback
. Callbacks are different from services because they are not associated with any entity. - Blocking
Map - Use `BlockingMap`` to indicate that your function is a blocking map. A map is not associated with any entity, and it cannot be a Bevy System. These restrictions allow them to be processed more efficiently.
- Blocking
Service - Use
BlockingService
to indicate that your system is a blockingService
. - Continuous
Service - Use
ContinuousService
to indicate that your system is aService
that runs incrementally inside of a schedule with each update of the Bevy ECS. - Impulse
Plugin - This plugin simply adds
flush_impulses()
to theUpdate
schedule of your applicatation. For more fine-grained control you can callflush_impulses
yourself and configure its relationship to other systems as you see fit.
Traits§
- Sendish
- This trait is used as a trait bound that is equivalent to
Send
except when thesingle_threaded_async
feature is active, in which case it is no longer a bound at all because the single threaded async executor does not require tasks to beSend
.
Type Aliases§
- Async
Callback Input - Use this to reduce bracket noise when you need
In<
AsyncCallback<R, S>
>
. - Async
Service Input - Use this to reduce backet noise when you need
In<
AsyncService<R, S>
>
. - Blocking
Callback Input - Use this to reduce bracket noise when you need
In<
BlockingCallback<R, S>
>
. - Blocking
Service Input - Use this to reduce bracket noise when you need
In<BlockingService<R>>
. - Continuous
Service Input - Use this to reduce the bracket noise when you need
In<
ContinuousService
>
.