@@ -36,23 +36,12 @@ pub use fork_clone_builder::*;
36
36
pub mod unzip;
37
37
pub use unzip:: * ;
38
38
39
- /// After submitting a service request, use [`Chain`] to describe how
40
- /// the response should be handled. At a minimum, for the response to be
41
- /// delivered, you must choose one of:
42
- /// - `.detach()`: Let the service run to completion and then discard the
43
- /// response data.
44
- /// - `.take()`: As long as the [`Promise`] or one of its clones is alive,
45
- /// the service will continue running to completion and you will be able to
46
- /// view the response (or take the response, but only once). If all clones of
47
- /// the [`Promise`] are dropped before the service is delivered, it will
48
- /// be cancelled.
49
- /// - `.detach_and_take()`: As long as the [`Promise`] or one of its clones is
50
- /// alive, you will be able to view the response (or take the response, but
51
- /// only once). The service will run to completion even if every clone of the
52
- /// [`Promise`] is dropped.
39
+ /// Chain operations onto the output of a workflow node.
53
40
///
54
- /// If you do not select one of the above then the service request will be
55
- /// cancelled without ever attempting to run.
41
+ /// Make sure to use [`Self::connect`] when you're done chaining so that the
42
+ /// final output of the chain gets connected into another node. If the final
43
+ /// output of the chain is meant to be the final output of your workflow then
44
+ /// you should connect it to [`Scope::terminate`].
56
45
#[ must_use]
57
46
pub struct Chain < ' w , ' s , ' a , ' b , T > {
58
47
target : Entity ,
@@ -65,10 +54,8 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
65
54
/// use this to resume building this chain later.
66
55
///
67
56
/// Note that if you do not connect some path of your workflow into the
68
- /// `terminate` slot of your [`Scope`][1] then the workflow will not be able
57
+ /// `terminate` slot of your [`Scope`] then the workflow will not be able
69
58
/// to run.
70
- ///
71
- /// [1]: crate::Scope
72
59
#[ must_use]
73
60
pub fn output ( self ) -> Output < T > {
74
61
Output :: new ( self . scope ( ) , self . target )
@@ -217,8 +204,8 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
217
204
218
205
/// Build a workflow scope to be used as an element in this chain.
219
206
///
220
- /// If you want to connect to the stream outputs, use
221
- /// [`Self::then_scope_node`] instead.
207
+ /// If you want to connect to the stream outputs or be able to loop back
208
+ /// to the input of this scope, use [`Self::then_scope_node`] instead.
222
209
#[ must_use]
223
210
pub fn then_scope < Response , Streams , Settings > (
224
211
self ,
@@ -236,14 +223,13 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
236
223
}
237
224
238
225
/// Simplified version of [`Self::then_scope`] limited to a simple input and
239
- /// output. This does not support streams and only uses default scope
240
- /// settings.
226
+ /// output.
241
227
///
242
228
/// Unlike `then_scope`, this function can infer the types for the generics
243
229
/// so you don't need to explicitly specify them.
244
230
pub fn then_io_scope < Response , Settings > (
245
231
self ,
246
- build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) -> Settings ,
232
+ build : impl FnOnce ( Scope < T , Response > , & mut Builder ) -> Settings ,
247
233
) -> Chain < ' w , ' s , ' a , ' b , Response >
248
234
where
249
235
Response : ' static + Send + Sync ,
@@ -271,14 +257,13 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
271
257
}
272
258
273
259
/// Simplified version of [`Self::then_scope_node`] limited to a simple
274
- /// input and output. This does not support streams and only uses default
275
- /// scope settings.
260
+ /// input and output.
276
261
///
277
262
/// Unlike `then_scope_node`, this function can infer the types for the
278
263
/// generics so you don't need to explicitly specify them.
279
264
pub fn then_io_scope_node < Response , Settings > (
280
265
self ,
281
- build : impl FnOnce ( Scope < T , Response , ( ) > , & mut Builder ) -> Settings ,
266
+ build : impl FnOnce ( Scope < T , Response > , & mut Builder ) -> Settings ,
282
267
) -> Node < T , Response , ( ) >
283
268
where
284
269
Response : ' static + Send + Sync ,
@@ -288,12 +273,13 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
288
273
}
289
274
290
275
/// Apply a [`Provider`] that filters the response by returning an [`Option`].
291
- /// If the filter returns [`None`] then a cancellation is triggered.
292
- /// Otherwise the chain continues with the value given inside [`Some`].
276
+ /// If the filter returns [`None`] then a [`Cancellation`](crate::Cancellation)
277
+ /// is triggered. Otherwise the chain continues with the value that was
278
+ /// inside [`Some`].
293
279
///
294
280
/// This is conceptually similar to [`Iterator::filter_map`]. You can also
295
- /// use [`Chain::disposal_filter`] to dispose the remainder of the chain
296
- /// instead of cancelling it .
281
+ /// use [`Chain::disposal_filter`] to dispose of the value instead of
282
+ /// cancelling the entire scope .
297
283
#[ must_use]
298
284
pub fn cancellation_filter < ThenResponse , F > (
299
285
self ,
@@ -326,14 +312,14 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
326
312
327
313
/// When the response is delivered, we will make a clone of it and
328
314
/// simultaneously pass that clone along two different branches chains: one
329
- /// determined by the `build` function passed into this function and the
330
- /// other determined by the [`Chain`] that gets returned by this function .
315
+ /// determined by the `build` function passed into this operation and the
316
+ /// other determined by the [`Chain`] that gets returned.
331
317
///
332
318
/// This can only be applied when `Response` can be cloned.
333
319
///
334
320
/// See also [`Chain::fork_clone`]
335
321
#[ must_use]
336
- pub fn fork_clone_branch (
322
+ pub fn branch_clone (
337
323
self ,
338
324
build : impl FnOnce ( Chain < T > ) ,
339
325
) -> Chain < ' w , ' s , ' a , ' b , T >
@@ -410,7 +396,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
410
396
///
411
397
/// As the name suggests, a no-op will not actually do anything, but it adds
412
398
/// a new link (entity) into the chain.
413
- /// [1]: https://en.wikipedia.org/wiki/NOP_(code)
399
+ /// [1]: `< https://en.wikipedia.org/wiki/NOP_(code)>`
414
400
#[ must_use]
415
401
pub fn noop ( self ) -> Chain < ' w , ' s , ' a , ' b , T > {
416
402
let source = self . target ;
@@ -614,7 +600,7 @@ where
614
600
) -> Chain < ' w , ' s , ' a , ' b , T > {
615
601
Chain :: < Option < T > > :: new (
616
602
self . target , self . builder ,
617
- ) . branch_option_zip (
603
+ ) . fork_option (
618
604
|chain| chain. output ( ) ,
619
605
build_none,
620
606
) . 0 . chain ( self . builder )
@@ -627,8 +613,7 @@ where
627
613
///
628
614
/// The outputs of both builder functions will be zipped as the return value
629
615
/// of this function.
630
- #[ must_use]
631
- pub fn branch_option_zip < U , V > (
616
+ pub fn fork_option < U , V > (
632
617
self ,
633
618
build_some : impl FnOnce ( Chain < T > ) -> U ,
634
619
build_none : impl FnOnce ( Chain < ( ) > ) -> V ,
@@ -746,7 +731,7 @@ mod tests {
746
731
) ;
747
732
748
733
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
749
- assert ! ( promise. peek ( ) . available( ) . is_some_and( |value| * value == 6.0 ) ) ;
734
+ assert ! ( promise. take ( ) . available( ) . is_some_and( |value| value == 6.0 ) ) ;
750
735
assert ! ( context. no_unhandled_errors( ) ) ;
751
736
}
752
737
@@ -806,7 +791,7 @@ mod tests {
806
791
. with_update_count ( 100 ) ,
807
792
) ;
808
793
809
- assert_eq ! ( promise. peek ( ) . available( ) . copied ( ) , Some ( 16.0 ) ) ;
794
+ assert_eq ! ( promise. take ( ) . available( ) , Some ( 16.0 ) ) ;
810
795
assert ! ( context. no_unhandled_errors( ) ) ;
811
796
}
812
797
@@ -850,7 +835,7 @@ mod tests {
850
835
} ) ;
851
836
852
837
context. run_while_pending ( & mut promise) ;
853
- assert_eq ! ( promise. peek ( ) . available( ) . copied ( ) , Some ( 15.0 ) ) ;
838
+ assert_eq ! ( promise. take ( ) . available( ) , Some ( 15.0 ) ) ;
854
839
assert ! ( context. no_unhandled_errors( ) ) ;
855
840
}
856
841
@@ -943,7 +928,7 @@ mod tests {
943
928
} ) ;
944
929
945
930
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
946
- assert ! ( promise. peek ( ) . available( ) . is_some_and( |v| * v == 1.0 ) ) ;
931
+ assert ! ( promise. take ( ) . available( ) . is_some_and( |v| v == 1.0 ) ) ;
947
932
assert ! ( context. no_unhandled_errors( ) ) ;
948
933
949
934
let mut promise = context. command ( |commands| {
@@ -953,7 +938,7 @@ mod tests {
953
938
} ) ;
954
939
955
940
context. run_with_conditions ( & mut promise, Duration :: from_secs ( 2 ) ) ;
956
- assert ! ( promise. peek ( ) . available( ) . is_some_and( |v| * v == 5.0 ) ) ;
941
+ assert ! ( promise. take ( ) . available( ) . is_some_and( |v| v == 5.0 ) ) ;
957
942
assert ! ( context. no_unhandled_errors( ) ) ;
958
943
959
944
let mut promise = context. command ( |commands| {
0 commit comments