@@ -85,28 +85,17 @@ pub mod testing;
85
85
86
86
use bevy:: prelude:: { Entity , In } ;
87
87
88
- /// Use BlockingService to indicate that your system is a blocking service and
89
- /// to specify its input request type. For example:
88
+ /// Use `BlockingService` to indicate that your system is a blocking [`Service`].
90
89
///
91
- /// ```
92
- /// use bevy::prelude::*;
93
- /// use bevy_impulse::*;
90
+ /// A blocking service will have exclusive world access while it runs, which
91
+ /// means no other system will be able to run simultaneously. Each service is
92
+ /// associated with its own unique entity which can be used to store state or
93
+ /// configuration parameters.
94
94
///
95
- /// #[derive(Component, Resource)]
96
- /// struct Precision(i32);
97
- ///
98
- /// fn rounding_service(
99
- /// In(input): InBlockingService<f64>,
100
- /// global_precision: Res<Precision>,
101
- /// ) -> f64 {
102
- /// (input.request * 10_f64.powi(global_precision.0)).floor() * 10_f64.powi(-global_precision.0)
103
- /// }
104
- /// ```
105
- ///
106
- /// The systems of more complex services might need to know what entity is
107
- /// providing the service, e.g. if the service provider is configured with
108
- /// additional components that need to be queried when a request comes in. For
109
- /// that you can check the `provider` field of `BlockingService`:
95
+ /// Some services might need to know what entity is providing the service, e.g.
96
+ /// if the service provider is configured with additional components that need
97
+ /// to be queried when a request comes in. For that you can check the `provider`
98
+ /// field of `BlockingService`:
110
99
///
111
100
/// ```
112
101
/// use bevy::prelude::*;
@@ -141,9 +130,9 @@ pub struct BlockingService<Request, Streams: StreamPack = ()> {
141
130
/// Use this to reduce bracket noise when you need `In<BlockingService<R>>`.
142
131
pub type InBlockingService < Request , Streams = ( ) > = In < BlockingService < Request , Streams > > ;
143
132
144
- /// Use AsyncService to indicate that your system is an async service and to
145
- /// specify its input request type. Being async means it must return a
146
- /// `Future<Output=Response>` which will be processed by a task pool.
133
+ /// Use AsyncService to indicate that your system is an async [`Service`]. Being
134
+ /// async means it must return a [`Future<Output=Response>`](std::future::Future)
135
+ /// which will be processed by a task pool.
147
136
///
148
137
/// This comes with a [`Channel`] that allows your Future to interact with Bevy's
149
138
/// ECS asynchronously while it is polled from inside the task pool.
@@ -169,6 +158,10 @@ pub type InAsyncService<Request, Streams = ()> = In<AsyncService<Request, Stream
169
158
/// Use BlockingCallback to indicate that your system is meant to define a
170
159
/// blocking [`Callback`]. Callbacks are different from services because they are
171
160
/// not associated with any entity.
161
+ ///
162
+ /// Alternatively any Bevy system with an input of `In<Request>` can be converted
163
+ /// into a blocking callback by applying
164
+ /// [`.into_blocking_callback()`](crate::IntoBlockingCallback).
172
165
#[ non_exhaustive]
173
166
pub struct BlockingCallback < Request , Streams : StreamPack = ( ) > {
174
167
/// The input data of the request
@@ -199,9 +192,9 @@ pub struct AsyncCallback<Request, Streams: StreamPack = ()> {
199
192
pub session : Entity ,
200
193
}
201
194
202
- /// Use BlockingMap to indicate that your function is meant to define a blocking
203
- /// [`Map`]. A Map is not associated with any entity, and it cannot be a Bevy
204
- /// System. These limited traits allow them to be processed more efficiently.
195
+ /// Use ` BlockingMap`` to indicate that your function is a blocking map. A map
196
+ /// is not associated with any entity, and it cannot be a Bevy System. These
197
+ /// restrictions allow them to be processed more efficiently.
205
198
#[ non_exhaustive]
206
199
pub struct BlockingMap < Request , Streams : StreamPack = ( ) > {
207
200
/// The input data of the request
@@ -214,11 +207,11 @@ pub struct BlockingMap<Request, Streams: StreamPack = ()> {
214
207
pub session : Entity ,
215
208
}
216
209
217
- /// Use AsyncMap to indicate that your function is meant to define an async
218
- /// [`Map`]. A Map is not associated with any entity, and it cannot be a Bevy
219
- /// System. These limited traits allow them to be processed more efficiently.
210
+ /// Use AsyncMap to indicate that your function is an async map. A Map is not
211
+ /// associated with any entity, and it cannot be a Bevy System. These
212
+ /// restrictions allow them to be processed more efficiently.
220
213
///
221
- /// An async Map must return a [`Future<Output=Response>`](std::future::Future)
214
+ /// An async map must return a [`Future<Output=Response>`](std::future::Future)
222
215
/// that will be polled by the async task pool.
223
216
#[ non_exhaustive]
224
217
pub struct AsyncMap < Request , Streams : StreamPack = ( ) > {
0 commit comments