Code Explainers
Code explainers tagged #throttling
ruby
class Api::MessagesController < ApiController before_action :authenticate_api_key! rate_limit to: 100,
Layered API rate limiting in Rails
rate-limiting
api-authentication
throttling
Intermediate
9 steps
javascript
const IDLE_TIMEOUT = 15 * 60 * 1000; const WARNING_BEFORE = 60 * 1000; const ACTIVITY_EVENTS = ['mousemove', 'keydown', 'scroll', 'touchstart', 'click'];
How an idle-session monitor logs you out
timers
throttling
broadcastchannel
Intermediate
8 steps
ruby
class DatasetImportJob < ApplicationJob queue_as :default def perform(import)
Streaming import progress with a Rails job
background-jobs
turbo-streams
progress-tracking
Intermediate
9 steps
php
<?php function fetchAll(array $urls, int $concurrency = 10, int $timeout = 15): array {
Bounded-concurrency HTTP fetching with curl_multi
concurrency
http
curl
Advanced
8 steps
javascript
import { useRef, useCallback, useEffect, useState } from "react"; function useThrottle(callback, delay) { const lastRun = useRef(0);
Building a throttle hook in React
throttling
custom-hooks
refs
Intermediate
8 steps
php
final class TokenBucketLimiter { private float $tokens; private float $lastRefill;
How a token bucket rate limiter works
rate-limiting
token-bucket
throttling
Intermediate
7 steps
python
from django.core.cache import cache from rest_framework.throttling import SimpleRateThrottle
A login rate throttle in Django REST Framework
rate-limiting
caching
throttling
Intermediate
8 steps
typescript
function throttle<T extends (...args: any[]) => void>( fn: T, limit: number ): (...args: Parameters<T>) => void {
Building a trailing-edge throttle in TypeScript
throttling
closures
generics
Intermediate
7 steps
javascript
function debounce(fn, delay) { let timeoutId = null; function debounced(...args) {
Building a debounce function in JavaScript
closures
timers
higher-order-functions
Intermediate
6 steps