← Writing

No Time To Die

Threads, Lifetimes, and Async Rust.

This post serves as a live preview for our new typography pairing: clean sans-serif prose coupled with JetBrains Mono code listings styled in the Regehr aesthetic.

Concurrency in systems programming often forces a choice between raw speed and safety guarantees. Async Rust pushes this further by introducing lifetime constraints across task boundaries.

use std::sync::{Arc, Mutex};
use std::thread;

pub struct TaskExecutor {
    pool_size: usize,
}

impl TaskExecutor {
    pub const fn new(pool_size: usize) -> Self {
        Self { pool_size }
    }

    pub fn run<F>(&self, task: F) 
    where
        F: FnOnce() + Send + 'static,
    {
        thread::spawn(task);
    }
}

When referencing symbols inline like Arc<Mutex<T>> or tokio::spawn, the monospace typeface keeps technical terms distinct from the surrounding prose without feeling heavy.

Here is another sample showing how indentation, comments, and long identifiers render inside our borderless code blocks:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let listener = tokio::net::TcpListener::bind("127.0.0.1:8080").await?;
    
    loop {
        let (socket, _) = listener.accept().await?;
        tokio::spawn(async move {
            process_connection(socket).await;
        });
    }
}

async fn process_connection(mut socket: tokio::net::TcpStream) {
    // Handle async stream operations safely.
}