xstate-awaitable-send

0.0.10 • Public • Published

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");

  // ...
}

// ...

Package Sidebar

Install

npm i xstate-awaitable-send

Weekly Downloads

19

Version

0.0.10

License

MIT

Unpacked Size

947 kB

Total Files

36

Last publish

Collaborators

  • sebinsua