-
error is like this: #[tauri::command]
| ^^^^^^^^^^^^^^^^^ future returned by `add_new_task` is not `Send`
|
= help: within `tendril::tendril::NonAtomic`, the trait `Sync` is not implemented for `std::cell::Cell<usize>`
= note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicUsize` instead
note: future is not `Send` as this value is used across an await
--> src/antbyw.rs:174:77
|
96 | let document = scraper::Html::parse_document(&html_content);
| -------- has type `scraper::Html` which is not `Send`
...
174 | let results: Vec<HandleHtmlRes> = join_all(group_tasks).await;
| ^^^^^ await occurs here, with `document` maybe used later code is like this: let all_tasks: Vec<String> = (1..=task_count)
.map(|index| value.get(index - 1).unwrap().href.clone())
.collect();
for group in all_tasks.chunks(GROUP_SIZE) {
let group_tasks = group
.iter()
.map(|current_url| handle_current_html(current_url.to_string().clone()));
let results: Vec<HandleHtmlRes> = join_all(group_tasks).await;
concurrent_results.extend(results);
} in when use futures::future::join_all to handle the concurrent async task, there must have this problem: |
Beta Was this translation helpful? Give feedback.
Answered by
hahazexia
Feb 2, 2025
Replies: 1 comment
-
rust-scraper/scraper#206 (comment) async fn worker() {
let html = reqwest::get("https://www.rust-lang.org").await.unwrap();
let html = html.text().await.unwrap();
let links = {
let document = scraper::Html::parse_document(&html);
let selector = scraper::Selector::parse("a").unwrap();
document.select(&selector).map(|element| element.attr("href").unwrap().to_owned()).collect::<Vec<_>>()
};
for href in links {
let html = reqwest::get(href).await.unwrap();
let html = html.text().await.unwrap();
let document = scraper::Html::parse_document(&html);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hahazexia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rust-scraper/scraper#206 (comment)