optimize backoff math

This commit is contained in:
Quaternions 2024-08-17 10:10:31 -07:00
parent 61c2026bff
commit f5d50a0de2

View File

@ -626,7 +626,8 @@ async fn get_asset_exp_backoff(
context:&CloudContext, context:&CloudContext,
asset_operation:&rbx_asset::cloud::AssetOperation asset_operation:&rbx_asset::cloud::AssetOperation
)->Result<rbx_asset::cloud::AssetResponse,rbx_asset::cloud::AssetOperationError>{ )->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{ loop{
match asset_operation.try_get_asset(&context).await{ match asset_operation.try_get_asset(&context).await{
//try again when the operation is not done //try again when the operation is not done
@ -634,10 +635,9 @@ async fn get_asset_exp_backoff(
//return all other results //return all other results
other_result=>return other_result, other_result=>return other_result,
} }
let wait=f32::exp(backoff as f32/3.0)*1000f32; println!("Operation not complete; waiting {:.0}ms...",backoff);
println!("Operation not complete; waiting {:.0}ms...",wait); tokio::time::sleep(std::time::Duration::from_millis(backoff as u64)).await;
tokio::time::sleep(std::time::Duration::from_millis(wait as u64)).await; backoff*=BACKOFF_MUL;
backoff+=1;
} }
} }