Installation
Install the package
Section titled “Install the package”npm install awaitlyOr with your preferred package manager:
pnpm add awaitlyyarn add awaitlyTypeScript configuration
Section titled “TypeScript configuration”The library requires TypeScript 4.7 or later. Enable strict mode for best results:
{ "compilerOptions": { "strict": true, "moduleResolution": "bundler" }}Import paths
Section titled “Import paths”Import from the main entry point. For minimal bundle use awaitly/result (Result types only, named exports). For best DX (including the Awaitly namespace and functional utilities) use awaitly. You can use named exports (tree-shake friendly) or the Awaitly namespace:
// Named exports (recommended for tree-shaking)import { ok, err, type AsyncResult } from 'awaitly';import { createWorkflow } from 'awaitly/workflow';
// Awaitly namespace (Effect-style: one object with ok, err, pipe, map, etc.)import { Awaitly } from 'awaitly';Awaitly.ok(1);Awaitly.err('E');Awaitly.pipe(value, fn1, fn2);Or use tree-shakable subpaths for smaller bundles:
// Minimal: Result types only (smallest)import { ok, err, map, andThen, type AsyncResult } from 'awaitly/result';
// Full package: named exportsimport { ok, err, map, andThen } from 'awaitly';
// run() for workflow compositionimport { run } from 'awaitly/run';
// Workflow orchestrationimport { createWorkflow } from 'awaitly/workflow';
// Visualization (separate package)// npm install awaitly-visualizerimport { createVisualizer } from 'awaitly-visualizer';
// Batch processing (~2KB gzipped)import { processInBatches } from 'awaitly/batch';
// Resource management (~1KB gzipped)import { withScope, createResource } from 'awaitly/resource';Browser support
Section titled “Browser support”awaitly is fully platform-agnostic and works identically in Node.js and browser environments. No special configuration is needed - the same code runs everywhere.
// Works in both Node.js and browserimport { ok, err } from 'awaitly';import { createWorkflow } from 'awaitly/workflow';For visualization in browsers, use the awaitly-visualizer package; it has browser-specific exports that exclude Node-only features like live terminal output:
// awaitly-visualizer has browser-specific exports for createVisualizer, etc.import { createVisualizer } from 'awaitly-visualizer';
const viz = createVisualizer({ workflowName: 'checkout' });Verify installation
Section titled “Verify installation”Create a file and run it to verify everything works:
import { ok, err, type AsyncResult } from 'awaitly';
const divide = (a: number, b: number): AsyncResult<number, 'DIVIDE_BY_ZERO'> => b === 0 ? err('DIVIDE_BY_ZERO') : ok(a / b);
const result = await divide(10, 2);
if (result.ok) { console.log('Result:', result.value); // Result: 5} else { console.log('Error:', result.error);}npx tsx test.ts