Creates a fallible operator implementation from supplied logic constructor. If the `Future` resolves to an error it will be emitted in the returned error stream and then the operator will wait indefinitely until the shutdown button is pressed. # Capability handling Unlike [`OperatorBuilder::build`], this method does not give owned capabilities to the constructor. All initial capabilities are wra
(
mut self,
constructor: F,
)
| 683 | /// })); |
| 684 | /// ``` |
| 685 | pub fn build_fallible<E: 'static, F>( |
| 686 | mut self, |
| 687 | constructor: F, |
| 688 | ) -> (Button, StreamVec<'scope, T, Rc<E>>) |
| 689 | where |
| 690 | F: for<'a> FnOnce( |
| 691 | &'a mut [CapabilitySet<T>], |
| 692 | ) -> Pin<Box<dyn Future<Output = Result<(), E>> + 'a>> |
| 693 | + 'static, |
| 694 | { |
| 695 | // Create a new completely disconnected output |
| 696 | let (error_output, error_stream) = self.new_output::<CapacityContainerBuilder<_>>(); |
| 697 | let button = self.build(|mut caps| async move { |
| 698 | let error_cap = caps.pop().unwrap(); |
| 699 | let mut caps = caps |
| 700 | .into_iter() |
| 701 | .map(CapabilitySet::from_elem) |
| 702 | .collect::<Vec<_>>(); |
| 703 | if let Err(err) = constructor(&mut *caps).await { |
| 704 | error_output.give(&error_cap, Rc::new(err)); |
| 705 | drop(error_cap); |
| 706 | // IMPORTANT: wedge this operator until the button is pressed. Returning would drop |
| 707 | // the capabilities and could produce incorrect progress statements. |
| 708 | std::future::pending().await |
| 709 | } |
| 710 | }); |
| 711 | (button, error_stream) |
| 712 | } |
| 713 | |
| 714 | /// Creates operator info for the operator. |
| 715 | pub fn operator_info(&self) -> OperatorInfo { |
no test coverage detected