You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: session.rs
    path of file: ./repos/pants/src/rust/engine/src
    
    the code of the file until where you have to start completion: // Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

use std::collections::HashMap;
use std::future::Future;
use std::sync::atomic::{self, AtomicU32};
use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};

use crate::context::{Core, SessionCore};
use crate::nodes::{NodeKey, Root};
use crate::python::{Failure, Value};

use async_latch::AsyncLatch;
use futures::future::{self, FutureExt};
use graph::{Context, LastObserved};
use log::warn;
    
    pub async fn shutdown(&self, timeout: Duration) -> Result<(), String> {
        let sessions_opt = self.sessions.lock().take();
        if let Some(sessions) = sessions_opt {
            // Collect clones of the cancellation tokens for each Session, which allows us to watch for
            // them to have been dropped.
            let (build_ids, cancellation_latches): (Vec<_>, Vec<_>) = sessions
                .into_iter()
                .filter_map(|weak_handle| weak_handle.upgrade())
                .map(|handle| {
                    let build_id = handle.build_id.clone();
                    let cancelled = handle.cancelled.clone();
                    let cancellation_triggered = async move {
                        cancelled.triggered().await;
                        log::info!("Shutdown completed: {:?}", build_id)
                    };
                    (handle.build_id.clone(), cancellation_triggered)
                })
                .unzip();

            if !build_ids.is_empty() {
                log::info!("Waiting for shutdown of: {:?}", build_ids);
                tokio::time::timeout(timeout, future::join_all(cancellation_latches))
                    .await
                    .map_err(|_| format!("Some Sessions did not shutdown within {timeout:?}."))?;
            }
        }
        Ok(())
    }