Skip to main content

Installation

Install Tryo using your favorite package manager:
npm install tryo

Basic Usage

Tryo provides a simple way to handle async operations safely.

Using run directly

For simple use cases, you can use the run function directly:
import { run } from "tryo";

const result = await run(
  () => fetch("https://api.example.com/data").then((res) => res.json()),
  {
    retry: { maxRetries: 3, strategy: RetryStrategies.fixed(1000) },
    timeout: 5000,
  }
);

if (result.ok) {
  console.log("Success:", result.data);
} else {
  console.error("Failed:", result.error);
}

Using tryo

For more advanced configurations and reuse, create a Runner instance:
import tryo from "tryo";

// Create a reusable runner with default configuration
const runner = tryo({
  retry: {
    maxRetries: 2,
    strategy: RetryStrategies.fixed(1000),
  },
  timeout: 10000,
  hooks: {
    onError: (error) => {
      console.error("Global error handler:", error);
    },
  },
});

// Use it across your application
const result = await runner.run(() => complexOperation());

Next Steps

Now that you have Tryo installed, explore these key features: