export type Settled<R> =
| { status: 'fulfilled'; value: R }
| { status: 'rejected'; reason: unknown };
export interface ConcurrencyOptions {
limit: number;
require "sidekiq/api"
class QueueDepthGuard
class QueueSaturated < StandardError
attr_reader :queue, :depth
import asyncio
import time
from dataclasses import dataclass, field
@dataclass
class TokenBucket {
constructor(capacity, refillPerSecond) {
this.capacity = capacity;
this.refillPerMs = refillPerSecond / 1000;
this.tokens = capacity;
this.lastRefill = Date.now();
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::Mutex;
use tokio::time::sleep;
#[derive(Debug)]
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
from rest_framework.throttling import UserRateThrottle
class BurstRateThrottle(UserRateThrottle):
"""Allow short bursts of requests."""
scope = 'burst'
require "rack/attack"
require "redis-store"
class Rack::Attack
cache.store = Redis::Store.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/1"))
class TokenBucket {
constructor(capacity, refillRatePerSec) {
this.capacity = capacity;
this.refillRate = refillRatePerSec;
this.tokens = capacity;
this.lastRefill = Date.now();
require "securerandom"
require "digest"
class SlidingWindowLimiter
Result = Struct.new(:allowed, :count, :remaining)
from django.core.cache import cache
class RateLimiter:
def __init__(self, scope, limit, window_seconds):
self.scope = scope
class LastSeenTracker
THROTTLE = 5.minutes
PENDING_KEY = "pending:last_seen".freeze
class << self
def touch(user_id, at: Time.current)