pub async fn add_task<F: 'static + Future<Output = ()> + Send>(&self, future: F) {
        let id = thread_rng().gen::<u128>();
        let weak_tasks = Arc::downgrade(&self.tasks);
        let future = future.then(move |_| async move {
            // This may return None if the task list gets dropped, but the future associated
            // with the task has not stopped on the executor.
            if let Some(tasks) = weak_tasks.upgrade() {
                let _ = tasks.lock().await.remove(&id);
            }
        });
        // Acquire this lock before we spawn the future. This is to prevent a situation where
        // the future completes before we've inserted the task into the list.
        let mut locked_tasks = self.tasks.lock().await;
        let task = Task::spawn(future);
        locked_tasks.insert(id, task);
    }
/// Adds a task to this scope and executes it
Adds a task to this scope and executes it
Adds a task to this scope and executes it
pub async fn add_task<F: 'static + Future<Output = ()> + Send>(&self, future: F) {
        let id = thread_rng().gen::<u128>();
        let weak_tasks = Arc::downgrade(&self.tasks);
        let future = future.then(move |_| async move {
            // This may return None if the task list gets dropped, but the future associated
            // with the task has not stopped on the executor.
            if let Some(tasks) = weak_tasks.upgrade() {
                let _ = tasks.lock().await.remove(&id);
            }
        });
        // Acquire this lock before we spawn the future. This is to prevent a situation where
        // the future completes before we've inserted the task into the list.
        let mut locked_tasks = self.tasks.lock().await;
        let task = Task::spawn(future);
        locked_tasks.insert(id, task);
    }
pub async fn add_task < F : ' static + Future < Output = ( ) > + Send > ( & self , future : F ) { let id = thread_rng ( ) . gen :: < u128 > ( ) ; let weak_tasks = Arc :: downgrade ( & self . tasks ) ; let future = future . then ( move | _ | async move { // This may return None if the task list gets dropped, but the future associated // with the task has not stopped on the executor. if let Some ( tasks ) = weak_tasks . upgrade ( ) { let _ = tasks . lock ( ) . await . remove ( & id ) ; } } ) ; // Acquire this lock before we spawn the future. This is to prevent a situation where // the future completes before we've inserted the task into the list. let mut locked_tasks = self . tasks . lock ( ) . await ; let task = Task :: spawn ( future ) ; locked_tasks . insert ( id , task ) ; }
Adds a task to this scope and executes it
Adds a task to this scope and executes it
&self
future
F
&self
future
F