/// Perform shutdown of the Component that was used to create this ShutdownJob A Component must
/// wait to shut down until all its children are shut down.  The shutdown procedure looks at
/// the children, if any, and determines the dependency relationships of the children.
Perform shutdown of the Component that was used to create this ShutdownJob A Component must
wait to shut down until all its children are shut down.  The shutdown procedure looks at
the children, if any, and determines the dependency relationships of the children.
Perform shutdown of the Component that was used to create this ShutdownJob A Component must wait to shut down until all its children are shut down . The shutdown procedure looks at the children if any and determines the dependency relationships of the children .
pub async fn execute(&mut self) -> Result<(), ModelError> {
        // Relationship maps are maintained to track dependencies. A map is
        // maintained both from a Component to its dependents and from a Component to
        // that Component's dependencies. With this dependency tracking, the
        // children of the Component can be shut down progressively in dependency
        // order.
        //
        // The progressive shutdown of Component is performed in this order:
        // Note: These steps continue until the shutdown process is no longer
        // asynchronously waiting for any shut downs to complete.
        //   * Identify the one or more Component that have no dependents
        //   * A shutdown action is set to the identified components. During the
        //     shut down process, the result of the process is received
        //     asynchronously.
        //   * After a Component is shut down, the Component are removed from the list
        //     of dependents of the Component on which they had a dependency.
        //   * The list of Component is checked again to see which Component have no
        //     remaining dependents.
        // Look for any children that have no dependents
        let mut stop_targets = vec![];
        for moniker in self.source_to_targets.keys().map(|key| key.clone()).collect::<Vec<_>>() {
            let no_dependents = {
                let info = self.source_to_targets.get(&moniker).expect("key disappeared from map");
                info.dependents.is_empty()
            };
            if no_dependents {
                stop_targets.push(
                    self.source_to_targets.remove(&moniker).expect("key disappeared from map"),
                );
            }
        }
        let mut futs = vec![];
        // Continue while we have new stop targets or unfinished futures
        while !stop_targets.is_empty() || !futs.is_empty() {
            for target in stop_targets.drain(..) {
                futs.push(Box::pin(shutdown_component(target)));
            }
            let (moniker, _, remaining) = select_all(futs).await;
            futs = remaining;
            let moniker = moniker?;
            // Look up the dependencies of the component that stopped
            match self.target_to_sources.remove(&moniker) {
                Some(sources) => {
                    for source in sources {
                        let ready_to_stop = {
                            if let Some(info) = self.source_to_targets.get_mut(&source) {
                                info.dependents.remove(&moniker);
                                // Have all of this components dependents stopped?
                                info.dependents.is_empty()
                            } else {
                                // The component that provided a capability to
                                // the stopped component doesn't exist or
                                // somehow already stopped. This is unexpected.
                                panic!(
                                    "The component '{:?}' appears to have stopped before its \
                                     dependency '{:?}'",
                                    moniker, source
                                );
                            }
                        };
                        // This components had zero remaining dependents
                        if ready_to_stop {
                            stop_targets.push(
                                self.source_to_targets
                                    .remove(&source)
                                    .expect("A key that was just available has disappeared."),
                            );
                        }
                    }
                }
                None => {
                    // Oh well, component didn't have any dependencies
                }
            }
        }
        // We should have stopped all children, if not probably there is a
        // dependency cycle
        if !self.source_to_targets.is_empty() {
            panic!(
                "Something failed, all children should have been removed! {:?}",
                self.source_to_targets
            );
        }
        Ok(())
    }
pub async fn execute ( & mut self ) -> Result < ( ) , ModelError > { // Relationship maps are maintained to track dependencies. A map is // maintained both from a Component to its dependents and from a Component to // that Component's dependencies. With this dependency tracking, the // children of the Component can be shut down progressively in dependency // order. // // The progressive shutdown of Component is performed in this order: // Note: These steps continue until the shutdown process is no longer // asynchronously waiting for any shut downs to complete. //   * Identify the one or more Component that have no dependents //   * A shutdown action is set to the identified components. During the //     shut down process, the result of the process is received //     asynchronously. //   * After a Component is shut down, the Component are removed from the list //     of dependents of the Component on which they had a dependency. //   * The list of Component is checked again to see which Component have no //     remaining dependents. // Look for any children that have no dependents let mut stop_targets = vec ! [ ] ; for moniker in self . source_to_targets . keys ( ) . map ( | key | key . clone ( ) ) . collect :: < Vec < _ > > ( ) { let no_dependents = { let info = self . source_to_targets . get ( & moniker ) . expect ( " " ) ; info . dependents . is_empty ( ) } ; if no_dependents { stop_targets . push ( self . source_to_targets . remove ( & moniker ) . expect ( " " ) , ) ; } } let mut futs = vec ! [ ] ; // Continue while we have new stop targets or unfinished futures while ! stop_targets . is_empty ( ) || ! futs . is_empty ( ) { for target in stop_targets . drain ( .. ) { futs . push ( Box :: pin ( shutdown_component ( target ) ) ) ; } let ( moniker , _ , remaining ) = select_all ( futs ) . await ; futs = remaining ; let moniker = moniker ? ; // Look up the dependencies of the component that stopped match self . target_to_sources . remove ( & moniker ) { Some ( sources ) => { for source in sources { let ready_to_stop = { if let Some ( info ) = self . source_to_targets . get_mut ( & source ) { info . dependents . remove ( & moniker ) ; // Have all of this components dependents stopped? info . dependents . is_empty ( ) } else { // The component that provided a capability to // the stopped component doesn't exist or // somehow already stopped. This is unexpected. panic ! ( " \
 " moniker source ) ; } } ; // This components had zero remaining dependents if ready_to_stop { stop_targets . push ( self . source_to_targets . remove ( & source ) . expect ( " " ) , ) ; } } } None => { // Oh well, component didn't have any dependencies } } } // We should have stopped all children, if not probably there is a // dependency cycle if ! self . source_to_targets . is_empty ( ) { panic ! ( " " self source_to_targets ) ; } Ok ( ( ) ) }
Perform shutdown of the Component that was used to create this ShutdownJob A Component must
wait to shut down until all its children are shut down.
Perform shutdown of the Component that was used to create this ShutdownJob A Component must wait to shut down until all its children are shut down .
&mut self