Skip to content

Instantly share code, notes, and snippets.

@TBS1996

TBS1996/thing.rs Secret

Created January 9, 2024 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TBS1996/576844f8ee11576e2a290be95f6bd017 to your computer and use it in GitHub Desktop.
Save TBS1996/576844f8ee11576e2a290be95f6bd017 to your computer and use it in GitHub Desktop.
if val
.read()
.unwrap_or_else(|e| e.into_inner())
.redis_call_in_progress
.swap(true, Ordering::SeqCst)
{
return Ok(());
}
match self.call_redis(quota, client, quantity) {
Ok((new_budget, redis_value)) => {
let mut lock = val.write().unwrap_or_else(|e| e.into_inner());
lock.update(new_budget, redis_value, current_slot);
lock.redis_call_in_progress.store(false, Ordering::SeqCst);
}
Err(e) => {
val.read()
.unwrap_or_else(|e| e.into_inner())
.redis_call_in_progress
.store(false, Ordering::SeqCst);
return Err(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment