mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Avoid race condition in network request scheduling
oops
This commit is contained in:
parent
1aa28f0d00
commit
1610db4c3c
12
src/main.rs
12
src/main.rs
@ -89,10 +89,16 @@ lazy_static!{
|
||||
|
||||
fn process_gracefully(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl Future<Output = ()> + Send { async move {
|
||||
*TASKS_QUEUED.lock() += 1;
|
||||
while *TASKS_RUNNING.lock() >= ilias.opt.jobs {
|
||||
tokio::time::delay_for(Duration::from_millis(100)).await;
|
||||
loop {
|
||||
{ // limit scope of lock
|
||||
let mut running = TASKS_RUNNING.lock();
|
||||
if *running < ilias.opt.jobs {
|
||||
*running += 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokio::time::delay_for(Duration::from_millis(50)).await;
|
||||
}
|
||||
*TASKS_RUNNING.lock() += 1;
|
||||
let path_text = path.to_string_lossy().into_owned();
|
||||
if let Err(e) = process(ilias, path, obj).await.context("failed to process URL") {
|
||||
println!("Syncing {}: {:?}", path_text, e);
|
||||
|
Loading…
Reference in New Issue
Block a user