forked from StrafesNET/asset-tool
optimize backoff math
This commit is contained in:
parent
61c2026bff
commit
f5d50a0de2
10
src/main.rs
10
src/main.rs
@ -626,7 +626,8 @@ async fn get_asset_exp_backoff(
|
||||
context:&CloudContext,
|
||||
asset_operation:&rbx_asset::cloud::AssetOperation
|
||||
)->Result<rbx_asset::cloud::AssetResponse,rbx_asset::cloud::AssetOperationError>{
|
||||
let mut backoff:u16=0;
|
||||
const BACKOFF_MUL:f32=1.3956124250860895286;//exp(1/3)
|
||||
let mut backoff=1000f32;
|
||||
loop{
|
||||
match asset_operation.try_get_asset(&context).await{
|
||||
//try again when the operation is not done
|
||||
@ -634,10 +635,9 @@ async fn get_asset_exp_backoff(
|
||||
//return all other results
|
||||
other_result=>return other_result,
|
||||
}
|
||||
let wait=f32::exp(backoff as f32/3.0)*1000f32;
|
||||
println!("Operation not complete; waiting {:.0}ms...",wait);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(wait as u64)).await;
|
||||
backoff+=1;
|
||||
println!("Operation not complete; waiting {:.0}ms...",backoff);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(backoff as u64)).await;
|
||||
backoff*=BACKOFF_MUL;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user