How to properly use scope_and_block with lifetimes?

Hello I have following simple code and I don't quite understand how to fix it:

    async fn get_statuses(
        client: reqwest::Client,
        url: Url,
        tag: String,
        from_id: u64,
    ) -> Result<HashSet<u64>> {
        let response = client
            // TODO: escape tag
            .get(format!("{}/api/v1/timelines/tag/{}", url, tag))
            .send()
            .await?;
        let json: Value = response.json().await?;
        Ok(json
            .as_array()
            .unwrap()
            .iter()
            .map(|status| status["id"].as_u64().unwrap())
            .collect())
    }

    pub(crate) async fn run(self: Arc<Self>) -> Result<()> {
        TokioScope::scope_and_block( {
             |s| {
                self.instances.iter().for_each(|instance| {
                    self.tags.iter().for_each(|tag| {
                        let instance = instance.clone();
                        let tag = tag.clone();
                        let client = self.client.clone();
                        let last_id = self.last_id;
                        let proc = move || async {
                            App::get_statuses(
                                client.clone(),
                                instance.clone(),
                                tag.clone(),
                                last_id,
                            )
                        };
                        s.spawn(proc());
                    });
                });
            }
        });
        Ok(())
    }

Getting following error:

72 |                           let proc = move || async {
   |  ____________________________________-------_^
   | |                                    |     |
   | |                                    |     return type of closure `{async block@src/app.rs:72:44: 79:26}` contains a lifetime `'2`
   | |                                    lifetime `'1` represents this closure's body
73 | |                             App::get_statuses(
74 | |                                 client.clone(),
75 | |                                 instance.clone(),
...  |
78 | |                             )
79 | |                         };
   | |_________________________^ returning this value requires that `'1` must outlive `'2`

Btw TokioScope struct is from async-scoped crate.
How can I pass values to get_statuses method successfully?

Ok it works I guess, still I do not quite, understand why this works if provided by parameter to closure. Maybe there is difference between move || async and || async move also ..?

    pub(crate) async fn run(self: Arc<Self>) -> Result<()> {
        let my_self = Arc::clone(&self);
        let ((), results) = TokioScope::scope_and_block({
            |s| {
                my_self.instances.iter().for_each(|instance| {
                    my_self.tags.iter().for_each(|tag| {
                        let instance = (*instance).clone();
                        let tag = (*tag).clone();
                        let last_id = my_self.last_id;
                        // Guess this works, but why?
                        let proc = |instance: Url, tag: String| async move {
                            App::get_statuses(instance.clone(), tag.clone(), last_id)
                        };
                        s.spawn(proc(instance, tag));
                    });
                });
            }
        });

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.