Skip to content

sebinsua/xstate-awaitable-send

Repository files navigation

xstate-awaitable-send

Build Status NPM version

An awaitable xstate Interpreter#send made for use in backend applications with request-response communication (e.g. Node servers such as fastify, express and koa).

It will wait until any internal invocations of services have completed and resolve either (a) when it reaches a StateNode that is 'final', (b) when it is waiting for further events from the user, or (c) when the current StateNode has no more events that can cause transitions.

Usage

import { createAwaitableSend } from "xstate-awaitable-send";

import { asyncMachine } from "./asyncMachine";

export async function doThing(currentState) {
  const send = createAwaitableSend(
    interpret(asyncMachine).start(State.create(currentState))
  );

  const [state] = await send("YOUR_EVENT");

  // ...
}

// ...

About

Fire an event into an XState `Machine` and then wait for it to resolve.

Resources

License

Stars

Watchers

Forks

Packages

No packages published