Code Explainers

Code explainers tagged #async

rust
use axum::{
    response::sse::{Event, KeepAlive, Sse},
    routing::get,
    Router,

Streaming live price ticks with SSE in Axum

server-sent-events broadcast-channel streaming
Advanced 8 steps
typescript
type SearchResult = {
  id: string;
  title: string;
};

Cancelling stale searches with AbortController

abortcontroller cancellation async
Intermediate 7 steps
rust
use std::time::Duration;
 
use axum::{routing::get, Router};
use tokio::net::TcpListener;

Graceful shutdown in an Axum server

graceful-shutdown signal-handling async
Intermediate 8 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    response::IntoResponse,

An async job queue handler in Axum

background-jobs async http-202
Intermediate 9 steps
typescript
import { useState, useEffect, useRef, useCallback } from "react";
 
interface SearchResult {
  id: string;

A debounced search hook in React

debounce custom-hooks abortcontroller
Intermediate 7 steps
typescript
interface RetryOptions {
  retries?: number;
  baseDelayMs?: number;
  maxDelayMs?: number;

Retrying async tasks with exponential backoff

retry exponential-backoff async
Intermediate 8 steps
javascript
const PENDING = 'pending';
const FULFILLED = 'fulfilled';
const REJECTED = 'rejected';
 

Building a Promise from scratch

promises state-machine microtasks
Advanced 10 steps