MCPcopy Index your code
hub / github.com/scality/cloudserver / tryConsume

Method tryConsume

lib/api/apiUtils/rateLimit/tokenBucket.js:63–70  ·  view source on GitHub ↗

* Try to consume one token (hot path - in-memory only) * * @returns {boolean} True if request allowed, false if throttled

()

Source from the content-addressed store, hash-verified

61 * @returns {boolean} True if request allowed, false if throttled
62 */
63 tryConsume() {
64 if (this.tokens > 0) {
65 this.tokens -= 1;
66 return true; // ALLOWED
67 }
68
69 return false; // THROTTLED
70 }
71
72 /**
73 * Check if refill is needed and trigger async refill

Callers 2

tokenBucket.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected