npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@async-kit/workflowx

v0.2.0

Published

Lightweight async workflow engine with sequential steps, parallel branches, conditional logic, per-step retry and timeout for JavaScript/TypeScript

Readme

@async-kit/workflowx

Lightweight async workflow engine with step sequencing, retry, timeout, parallel branches, conditional steps, and AbortSignal support.

Install

npm install @async-kit/workflowx

Quick start

import { createWorkflow } from '@async-kit/workflowx';

interface OrderCtx extends WorkflowContext {
  orderId: string;
  user?: User;
  inventory?: Item[];
}

const workflow = createWorkflow<OrderCtx>()
  .step('validate',  validateOrder)
  .parallel([fetchUser, fetchInventory])
  .if((ctx) => ctx.user?.isPremium, applyDiscount)
  .step('charge',    chargeCard)
  .step('notify',    sendConfirmation);

const { ctx, durationMs } = await workflow.run({ orderId: 'ord_123' });

Features

| Feature | Description | |---|---| | Step sequencing | Steps run in declaration order, sharing a typed context | | Parallel branches | .parallel([...]) — all steps run concurrently, then rejoin | | Conditional steps | .if(predicate, step) — skip steps based on context | | Retry | Per-step retries with automatic re-execution | | Timeout | Per-step timeoutMs — throws WorkflowTimeoutError | | AbortSignal | Cancels between steps via WorkflowRunOptions.signal | | Hooks | onStepStart, onStepComplete, onStepError | | Context threading | All steps mutate/return the same typed context |

API

createWorkflow<TCtx>()

Returns a Workflow<TCtx> builder.

.step(name?, fn, options?)

wf.step('fetchUser', async (ctx) => {
  ctx.user = await getUser(ctx.userId);
}, { retries: 2, timeoutMs: 5_000 });

.parallel(steps)

wf.parallel([
  async (ctx) => { ctx.user = await getUser(ctx.id); },
  async (ctx) => { ctx.items = await getCart(ctx.id); },
]);

.if(predicate, step)

wf.if(
  (ctx) => ctx.total > 100,
  (ctx) => { ctx.discount = 0.1; }
);

workflow.run(initialCtx, options?)

const { ctx, durationMs, stepsExecuted } = await workflow.run(
  { orderId: 'x', currentStep: 0 },
  {
    signal: abortController.signal,
    onStepStart: (i, name) => console.log(`▶ ${i} ${name}`),
    onStepComplete: (i, name, ms) => console.log(`✓ ${name} (${ms}ms)`),
    onStepError: (i, name, err, attempt) => {
      logger.warn({ name, attempt, err });
      return attempt < 2; // true = swallow and continue
    },
  }
);

WorkflowContext

Every workflow context must extend WorkflowContext:

interface WorkflowContext {
  signal: AbortSignal;   // checked between steps
  currentStep: number;   // 0-based node index
  [key: string]: unknown;
}

You only need to provide your own fields — signal and currentStep are injected by run().

Errors

| Error | When | |---|---| | WorkflowError | Step fails after exhausting retries (.cause = original error) | | WorkflowAbortError | AbortSignal fires between steps | | WorkflowTimeoutError | Step exceeds timeoutMs |

import { WorkflowError, WorkflowAbortError, WorkflowTimeoutError } from '@async-kit/workflowx';

try {
  await wf.run(ctx);
} catch (err) {
  if (err instanceof WorkflowError) {
    console.error(err.stepName, err.cause);
  }
}

Examples

Retry + timeout

wf.step('callExternal', callThirdPartyApi, { retries: 3, timeoutMs: 2_000 });

Aborting mid-workflow

const ac = new AbortController();
setTimeout(() => ac.abort(), 5_000); // cancel after 5 s

await wf.run(ctx, { signal: ac.signal });

Observability hooks

await wf.run(ctx, {
  onStepStart: (i, name) => metrics.startTimer(`step.${name}`),
  onStepComplete: (i, name, ms) => metrics.recordDuration(`step.${name}`, ms),
  onStepError: (i, name, err, attempt) => {
    logger.warn('step failed', { name, attempt, err });
  },
});

License

MIT