Skip to main content

Welcome to go-go-scope

go-go-scope is a TypeScript library that brings structured concurrency to your applications using the Explicit Resource Management proposal. Write concurrent code that automatically cleans up after itself.
// Structured concurrency with automatic cleanup
await using s = scope({ timeout: 5000 });

const [err, data] = await s.task(() => fetchUser(id));
if (err) console.error("Failed:", err);
else console.log("User:", data);
// ✨ Everything cleaned up automatically

Why go-go-scope?

Traditional async/await code can leak resources when errors occur or operations timeout. go-go-scope ensures deterministic cleanup through structured concurrency patterns inspired by Go’s goroutines and channels.

Automatic Cleanup

Resources disposed in LIFO order via using/await using syntax. No more forgotten cleanup code.

Cancellation Propagation

Parent scope cancels all child tasks automatically. No fire-and-forget tasks.

Resilience Built-in

Circuit breakers, retries, timeouts, and idempotency patterns included out of the box.

Worker Thread Support

Offload CPU-intensive tasks to worker threads with the same clean API.

Key Features

Structured Concurrency

All tasks are tracked and awaitable. Parent scopes control child task lifetimes:
await using s = scope({ timeout: 3000 });

// Both tasks cancelled if parent scope times out
const task1 = s.task(() => fetchData());
const task2 = s.task(() => processData());

// Wait for both
const [err1, data] = await task1;
const [err2, result] = await task2;

Go-style Channels

Communicate between concurrent tasks using channels with backpressure:
await using s = scope();

const ch = s.channel<number>({ capacity: 10 });

// Producer
s.task(async () => {
  for (let i = 0; i < 100; i++) {
    await ch.send(i);
  }
  ch.close();
});

// Consumer
for await (const value of ch) {
  console.log("Received:", value);
}

Error Handling with Result Tuples

No try/catch needed - errors are returned as values:
const [err, user] = await s.task(() => fetchUser(id));

if (err) {
  // Handle error
  return;
}

// TypeScript knows user is defined here
console.log(user.name);

Framework Integration

go-go-scope integrates seamlessly with popular Node.js frameworks:

Fastify

Request-scoped concurrency for Fastify apps

Express

Middleware for Express.js applications

NestJS

Native NestJS module with DI support

Hono

Lightweight middleware for Hono

Koa

Context-aware Koa middleware

Hapi

Plugin for Hapi.js servers

Persistence & Observability

Database Adapters

Distributed locks, circuit breaker state, and caching for your database:
  • Redis - High-performance distributed locks
  • PostgreSQL - Advisory locks and table-based storage
  • MySQL - Named locks with table storage
  • MongoDB - Atomic operations with TTL indexes
  • DynamoDB - Conditional writes and single-table design
  • SQLite - Single-node deployments

Monitoring & Tracing

  • OpenTelemetry - Distributed tracing for all tasks
  • Prometheus - Metrics collection and export
  • Profiling - Built-in performance analysis
  • Deadlock Detection - Automatic detection of blocking cycles

Get Started

Installation

Install go-go-scope with your preferred package manager

Quick Start

Build your first concurrent application in 5 minutes

Core Concepts

Learn the principles behind structured concurrency

API Reference

Complete API documentation for all features

Community & Support

Build docs developers (and LLMs) love