Code Explainers

Code explainers tagged #graceful-shutdown

javascript
const express = require('express');
const app = express();
 
app.get('/health', (req, res) => res.json({ status: 'ok' }));

Graceful shutdown in an Express server

graceful-shutdown signal-handling connection-tracking
Advanced 9 steps
python
import signal
import time
import logging
 

Graceful shutdown in a queue worker

signals graceful-shutdown message-queue
Intermediate 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
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
typescript
import { Injectable, Logger, OnApplicationShutdown } from '@nestjs/common';
import { InjectRedis } from '@nestjs-modules/ioredis';
import Redis from 'ioredis';
import { DataSource } from 'typeorm';

Graceful shutdown hooks in NestJS

graceful-shutdown lifecycle-hooks dependency-injection
Intermediate 7 steps
go
package main
 
import (
	"context"

Graceful shutdown for a Gin server in Go

graceful-shutdown signals goroutines
Intermediate 6 steps
python
import asyncio
import logging
from contextlib import asynccontextmanager
from datetime import datetime, timedelta, timezone

A background session cleaner in FastAPI

background-tasks asyncio lifespan
Intermediate 8 steps
rust
use std::sync::{mpsc, Arc, Mutex};
use std::thread;
use std::time::Duration;
 

Building a thread pool in Rust

concurrency channels thread-pool
Advanced 9 steps
go
package main
 
import (
	"context"

Graceful HTTP shutdown in Go

graceful-shutdown signals goroutines
Intermediate 8 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
go
package worker
 
import (
	"fmt"

A graceful worker pool in Go

concurrency goroutines channels
Intermediate 7 steps
rust
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
 

A worker thread driven by Rust channels

concurrency message-passing channels
Intermediate 8 steps