rust
13 lines · 1 tab
Marcus Chen
Jan 2026
1 tab
use crossbeam::channel::unbounded;
use std::thread;
fn main() {
let (tx, rx) = unbounded();
thread::spawn(move || {
tx.send("message").unwrap();
});
let msg = rx.recv().unwrap();
println!("Received: {}", msg);
}
1 file · rust
Explain with highlit
Crossbeam provides lock-free data structures and utilities for concurrent programming. The crossbeam-channel crate offers multi-producer multi-consumer channels with better performance than std::sync::mpsc. crossbeam-utils has scoped threads (borrow data without 'static). crossbeam-epoch enables lock-free memory reclamation. I use crossbeam when the standard library's concurrency primitives aren't enough: MPMC channels, work stealing, or lock-free algorithms. The scoped threads are especially handy for parallelizing work that borrows local data. Crossbeam is battle-tested and used in high-performance systems. It's the next step after mastering std::sync.
Related snips
rust
struct Config<'a> {
name: &'a str,
value: &'a str,
}
fn parse_config(line: &str) -> Config {
Lifetime annotations for flexible borrowing in structs
rust
lifetimes
borrowing
by Marcus Chen
1 tab
javascript
// Creating a Promise
const myPromise = new Promise((resolve, reject) => {
const success = true;
setTimeout(() => {
if (success) {
Promises and async/await patterns for asynchronous JavaScript
javascript
promises
async-await
by Alex Chang
1 tab
rust
use tracing::{info, instrument};
#[instrument]
fn process_request(user_id: u64) {
info!(user_id, "Processing request");
// Work happens here
tracing for structured logging and distributed tracing
rust
observability
tracing
by Marcus Chen
1 tab
rust
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
Channels (mpsc) for message passing between threads
rust
concurrency
channels
by Marcus Chen
1 tab
rust
use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Args {
#[arg(short, long)]
clap for CLI argument parsing with derive macros
rust
cli
clap
by Marcus Chen
1 tab
typescript
export type Settled<R> =
| { status: 'fulfilled'; value: R }
| { status: 'rejected'; reason: unknown };
export interface ConcurrencyOptions {
limit: number;
Simple concurrency limiter for batch operations
node
concurrency
async
by codesnips
2 tabs
Share this code
Here's the card — post it anywhere.