Code Explainers
Code explainers tagged #concurrency
rust
use axum::{extract::{Path, State}, http::StatusCode, Json}; use dashmap::DashMap; use serde::Serialize; use std::sync::Arc;
Request coalescing in an Axum handler
caching
concurrency
request-coalescing
Advanced
8 steps
go
package config import ( "fmt"
A thread-safe config singleton in Go
singleton
concurrency
environment-variables
Intermediate
7 steps
rust
use std::sync::mpsc; use std::thread; use std::time::Duration;
Running work with a timeout in Rust
concurrency
channels
timeout
Intermediate
7 steps
go
package cache import ( "sync"
A thread-safe TTL cache in Go
concurrency
mutex
caching
Intermediate
9 steps
python
import signal import time import logging
Graceful shutdown in a queue worker
signals
graceful-shutdown
message-queue
Intermediate
7 steps
php
<?php namespace App\Storage;
A race-free file counter in PHP
file-locking
concurrency
atomicity
Intermediate
7 steps
go
package sse import ( "encoding/json"
Server-Sent Events streaming in Go
server-sent-events
channels
http-streaming
Intermediate
8 steps
go
package middleware import ( "bytes"
Idempotent requests in Gin with Redis
idempotency
caching
middleware
Advanced
10 steps
go
package middleware import ( "context"
A deadline-enforcing HTTP middleware in Go
middleware
context
goroutines
Advanced
7 steps
go
package logbuffer import ( "bufio"
A buffered logger with background flushing in Go
concurrency
buffering
context
Intermediate
8 steps
ruby
class ThumbnailPool def initialize(worker_count: 4, capacity: 100) @queue = SizedQueue.new(capacity) @running = true
A thread pool for thumbnail jobs in Ruby
concurrency
thread-pool
bounded-queue
Advanced
7 steps
java
public class RequestCoalescer<K, V> { private final ConcurrentHashMap<K, CompletableFuture<V>> inFlight = new ConcurrentHashMap<>(); private final Function<K, V> loader;
Coalescing duplicate requests in Java
concurrency
caching
completablefuture
Advanced
6 steps
javascript
async function uploadInBatches(records, uploadFn, { batchSize = 100, concurrency = 3 } = {}) { const batches = []; for (let i = 0; i < records.length; i += batchSize) { batches.push(records.slice(i, i + batchSize));
Uploading records with bounded concurrency
concurrency
worker-pool
async-await
Advanced
8 steps
ruby
class CircuitBreaker class OpenCircuitError < StandardError; end def initialize(failure_threshold: 5, reset_timeout: 30, half_open_max: 1)
How a circuit breaker guards failing calls
state-machine
fault-tolerance
concurrency
Advanced
9 steps
go
package middleware import ( "crypto/sha256"
Deduplicating concurrent requests in Gin
singleflight
request-coalescing
middleware
Advanced
8 steps
rust
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread; use std::time::Duration;
Graceful thread shutdown with an atomic flag
concurrency
atomics
memory-ordering
Advanced
7 steps
php
<?php namespace App\Http\Middleware;
Idempotency keys in Laravel middleware
idempotency
middleware
caching
Advanced
8 steps
rust
use std::sync::Arc; use std::time::Duration; use axum::{
Long-polling with Axum and Tokio Notify
long-polling
concurrency
shared-state
Advanced
8 steps