@@ -20,24 +20,13 @@ use crate::{
20
20
ModifiersUnset , AddOperation , Noop , IntoAsyncMap ,
21
21
} ;
22
22
23
- use bevy:: {
24
- prelude:: Commands ,
25
- utils:: define_label,
26
- } ;
23
+ use bevy:: prelude:: Commands ;
27
24
28
25
use std:: future:: Future ;
29
26
30
27
mod internal;
31
28
pub use internal:: { ApplyLabel , BuildLabel } ;
32
29
33
- define_label ! (
34
- /// A strongly-typed class of labels used to identify requests that have been
35
- /// issued to a service.
36
- RequestLabel ,
37
- /// Strongly-typed identifier for a [`RequestLabel`].
38
- RequestLabelId ,
39
- ) ;
40
-
41
30
pub trait RequestExt < ' w , ' s > {
42
31
/// Call this on [`Commands`] to begin building a impulse chain by submitting
43
32
/// a request to a provider.
@@ -130,97 +119,6 @@ async fn async_server<T: Future>(value: T) -> T::Output {
130
119
value. await
131
120
}
132
121
133
- /// By default when a service provider receives a new request with the same
134
- /// label as an earlier request, the earlier request will be cancelled,
135
- /// whether it is already being executed or whether it is sitting in a
136
- /// queue. If the earlier request was already delivered then the labeling
137
- /// has no effect.
138
- ///
139
- /// To change the default behavior there are two modifiers you can apply to
140
- /// this label:
141
- /// - `.queue()` asks for the request to be queued up to run after all
142
- /// other requests with this same label have been fulfilled and not cancel
143
- /// any of them.
144
- /// - `.ensure()` asks for this request to not be cancelled even if another
145
- /// request comes in with the same label. The new request will instead be
146
- /// queued after this one.
147
- ///
148
- /// You can choose to use either, both, or neither of these modifiers in
149
- /// whatever way fits your use case. No matter what modifiers you choose
150
- /// (or don't choose) the same service provider will never simultaneously
151
- /// execute its service for two requests with the same label value. To that
152
- /// extent, applying a label always guarantees mutual exclusivity between
153
- /// requests.
154
- ///
155
- /// This mutual exclusivity can be useful if the service involves making
156
- /// modifications to the world which would conflict with each other when two
157
- /// related requests are being delivered at the same time.
158
- pub struct LabelBuilder < Q , E > {
159
- label : RequestLabelId ,
160
- queue : bool ,
161
- ensure : bool ,
162
- _ignore : std:: marker:: PhantomData < ( Q , E ) > ,
163
- }
164
-
165
- pub struct Chosen ;
166
-
167
- impl LabelBuilder < ( ) , ( ) > {
168
- /// Begin building a label for a request. You do not need to call this
169
- /// function explicitly. You can instead use `.queue()` or `.ensure()`
170
- /// directly on a `RequestLabel` instance.
171
- pub fn new ( label : impl RequestLabel ) -> LabelBuilder < ( ) , ( ) > {
172
- LabelBuilder {
173
- label : label. as_label ( ) ,
174
- queue : false ,
175
- ensure : false ,
176
- _ignore : Default :: default ( )
177
- }
178
- }
179
- }
180
-
181
- impl < E > LabelBuilder < ( ) , E > {
182
- /// Queue this labeled request to be handled **after** all other requests
183
- /// with the same label have been fulfilled. Do not automatically cancel
184
- /// pending requests that have the same label.
185
- ///
186
- /// The default behavior, if you do **not** trigger this method, is for this
187
- /// new labeled request to supplant all prior requests that share the same
188
- /// label, sending them to the cancelled state (unless the prior request was
189
- /// marked with [`ensure()`]).
190
- ///
191
- /// This modifer can only be applied to a labeled request because it does
192
- /// not make sense for unlabeled requests.
193
- pub fn queue ( self ) -> LabelBuilder < Chosen , E > {
194
- LabelBuilder {
195
- label : self . label ,
196
- queue : true ,
197
- ensure : self . ensure ,
198
- _ignore : Default :: default ( ) ,
199
- }
200
- }
201
- }
202
-
203
- impl < Q > LabelBuilder < Q , ( ) > {
204
- /// Ensure that this request is resolved even if another request with the
205
- /// same label arrives.
206
- ///
207
- /// Ordinarily a new labeled request would supplant all earlier requests
208
- /// with the same label, sending them into the cancelled state. But any
209
- /// of those requests that are "ensured" will remain queued and finish
210
- /// executing, one at a time.
211
- ///
212
- /// This modifier can only be applied to labeled requests because it does
213
- /// not make sense for unlabeled requests.
214
- pub fn ensure ( self ) -> LabelBuilder < Q , Chosen > {
215
- LabelBuilder {
216
- label : self . label ,
217
- queue : self . queue ,
218
- ensure : true ,
219
- _ignore : Default :: default ( ) ,
220
- }
221
- }
222
- }
223
-
224
122
#[ cfg( test) ]
225
123
mod tests {
226
124
use crate :: { * , testing:: * } ;
0 commit comments