Code Explainers

Code explainers tagged #timeout

ruby
require "timeout"
require "net/http"
 
class RemoteInventoryClient

Bounding a slow HTTP call with Timeout in Ruby

timeout error-handling http
Intermediate 6 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
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
go
package middleware
 
import (
	"context"

How a request-timeout middleware works in Gin

middleware context goroutines
Advanced 6 steps
javascript
const DEFAULT_OPTIONS = {
  method: 'GET',
  timeout: 5000,
  retries: 3,

A resilient fetch wrapper with retries and timeout

fetch retry timeout
Intermediate 8 steps
rust
use std::time::Duration;
 
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use serde::Serialize;

A timeout-guarded health check in Axum

health-check timeout error-handling
Intermediate 6 steps
typescript
interface PollOptions<T> {
  intervalMs?: number;
  timeoutMs?: number;
  signal?: AbortSignal;

A cancellable polling helper in TypeScript

polling async-await abortsignal
Intermediate 9 steps
java
public class ThumbnailProcessor {
 
    private static final int MAX_CONCURRENCY = 4;
 

Bounded parallel thumbnail rendering in Java

concurrency thread-pool futures
Intermediate 7 steps
typescript
type RetryOptions = {
  retries?: number;
  timeoutMs?: number;
  baseDelayMs?: number;

Retry with timeout and backoff in TypeScript

promises retry exponential-backoff
Intermediate 10 steps
javascript
async function pollJobUntilComplete(jobId, { interval = 2000, timeout = 60000, signal } = {}) {
  const deadline = Date.now() + timeout;
 
  while (true) {

Polling a job until it finishes in JavaScript

polling async-await abortsignal
Intermediate 6 steps