Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
Scope and conventions
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
No comparison
Compare with TypeScript
Compare with Go
Compare with C++
Async & concurrency
TypeScript promises, Go goroutines/context, Rust futures with Tokio where named, and C++ threads/futures. Runtime and cancellation rules differ; optional setup is identified in each entry.
Tokio features are opt-in. These examples need an active runtime and relevant macros/time/sync features. The shown dependency settings belong in Cargo.toml.
Fragment
Add imports such as std::time::Duration and std::sync::Arc in examples that use them. Enable net/fs features when using those APIs.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
// Cargo.toml: tokio = { version = "1", features = [// "rt-multi-thread", "macros", "time", "sync", "io-util"// ] }#[tokio::main]async fn main() { tokio::task::yield_now().await;}
JoinSet owns spawned tasks. On a failure, abort remaining tasks and drain their completions before returning the owner’s error.
Fragment
This assumes task outputs are Result values and the app defines consume/report_failure. Handle join failure and operation failure as distinct outcomes.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
while let Some(outcome) = tasks.join_next().await { match outcome { Ok(Ok(value)) => consume(value), other => { tasks.abort_all(); while tasks.join_next().await.is_some() {} return report_failure(other); } }}
A rolling JoinSet bounds both outstanding tasks and undrained task outputs. Join while launching once the window fills.
Fragment
This bounds retained task slots, not the memory already held by items or the outputs retained by consume. Supply an operation-error policy as well as a join-error policy.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
let mut tasks = tokio::task::JoinSet::new();for item in items { if tasks.len() >= 4 { if let Some(result) = tasks.join_next().await { consume(result?); } } tasks.spawn(async move { work(item).await });}while let Some(result) = tasks.join_next().await { consume(result?);}
Tokio mpsc Receiver::recv is cancellation safe: if another select branch wins, that receive has not consumed a message. read_exact can partially fill a buffer before cancellation.
Fragment
Cancellation safety is specific to the API and operation, not a property of all async I/O.
src/main.rs
Follow appearance
✓GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
tokio::select! { message = rx.recv() => handle(message), _ = shutdown() => {}}// Do not restart read_exact blindly after dropping// a partially progressing read without tracking protocol state.