Skip to main content
Logo Light

Welcome to Tryo

A modern, type-safe error handling library that makes async operations predictable and resilient.

Quick Start

Get up and running in less than 5 minutes

API Reference

Explore the complete API documentation

Examples

Real-world examples and patterns

GitHub

View source code and contribute

Features

No more try-catch blocks. Get discriminated unions with full TypeScript support.
const result = await runner.run(() => apiCall());
if (result.ok) {
  // TypeScript knows data is available
  console.log(result.data);
}
Built-in exponential backoff with jitter to prevent thundering herd.
await runner.run(() => unstableApi(), {
  retry: {
    maxRetries: 3,
    strategy: RetryStrategies.exponential(1000),
  }
});
Run multiple operations with controlled parallelism.
await runner.all(tasks, { 
  concurrency: 5 
});
First-class support for AbortController and graceful cancellation.
await runner.run(() => fetch('/api', { signal }), {
  ignoreAbort: true
});

Installation

npm install tryo

Quick Example

import tryo from "tryo";

const runner = tryo();

const result = await runner.run(() => fetch("https://api.example.com/users"), {
  retry: {
    maxRetries: 3,
    strategy: RetryStrategies.fixed(1000),
  },
  hooks: {
    onError: (error) => console.error(error),
  }
});

if (result.ok) {
  const users = await result.data.json();
  console.log(users);
}
Pro tip: Use tryo() once and reuse it across your app for consistent error handling.

Next Steps

Core Concepts

Learn about Result types and error normalization

React Integration

See how to use it with React hooks