Code Explainers
Code explainers tagged #concurrency
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
rust
use axum::{ async_trait, extract::{FromRequestParts, State}, http::{request::Parts, StatusCode},
Idempotent payments with an Axum extractor
idempotency
extractors
shared-state
Intermediate
8 steps
go
package middleware import ( "bytes"
Building a response cache middleware in Gin
middleware
caching
concurrency
Intermediate
8 steps
java
@RestController @RequestMapping("/api/notifications") public class NotificationStreamController {
Server-Sent Events per user in Spring
server-sent-events
concurrency
event-driven
Advanced
8 steps
ruby
class InventoryItem < ApplicationRecord belongs_to :warehouse validates :quantity, numericality: { greater_than_or_equal_to: 0 }
Safe inventory updates in Rails
concurrency
pessimistic-locking
optimistic-locking
Advanced
7 steps
typescript
type Task<T> = () => Promise<T>; export class Mutex { private queue: Array<() => void> = [];
Building an async mutex in TypeScript
concurrency
promises
locking
Advanced
7 steps
go
package middleware import ( "net/http"
Per-IP rate limiting middleware in Gin
rate-limiting
token-bucket
concurrency
Intermediate
7 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; use chrono::{Duration, Utc}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, sync::Arc};
Refresh token rotation in Axum
authentication
token-rotation
reuse-detection
Advanced
9 steps
php
<?php namespace App\Jobs;
Serializing balance reconciliation in Laravel
queues
concurrency
idempotency
Intermediate
7 steps
rust
use axum::{extract::{Path, State}, http::StatusCode, Json}; use serde::Serialize; use std::sync::Arc;
Concurrent dashboard aggregation in Axum
concurrency
error-handling
graceful-degradation
Intermediate
7 steps
java
public final class TokenBucketRateLimiter { private final long capacity; private final double refillTokensPerNano;
How a token bucket rate limiter works
rate-limiting
concurrency
token-bucket
Intermediate
8 steps
python
from decimal import Decimal from django.db import transaction from django.core.exceptions import ValidationError
Placing an order atomically in Django
transactions
row-locking
concurrency
Advanced
9 steps
go
package fetcher import ( "context"
Bounded-concurrency HTTP fetching in Go
concurrency
semaphore
context-cancellation
Advanced
9 steps
php
<?php namespace App\Services;
Placing an order atomically in Laravel
transactions
pessimistic-locking
concurrency
Advanced
8 steps
java
@Aspect @Component public class IdempotencyAspect {
How an idempotency aspect works in Spring
aop
idempotency
caching
Advanced
9 steps
typescript
import { Injectable } from '@angular/core'; import { HttpInterceptor, HttpHandler,
Refreshing tokens with an Angular HttpInterceptor
http-interceptor
token-refresh
rxjs
Advanced
8 steps
go
package ratelimit import ( "context"
A token bucket rate limiter in Go
rate-limiting
concurrency
goroutines
Intermediate
7 steps
typescript
type Fetcher<T> = (key: string) => Promise<T>; export class RequestDeduplicator<T> { private inFlight = new Map<string, Promise<T>>();
Deduplicating in-flight requests in TypeScript
deduplication
promises
caching
Intermediate
7 steps