Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ExecutionPromise<T>

Provides normal Promise functionality plus the ability to update, cancel, or stop a running process.

NOTE: The update method is primarily used to change conditions for a running process.

example
import { start } from '../path/to/machine';
import { dispatch } from '../path/to/workflow';

const execution = start(); // default start state, no conditions
// OR:
// const execution = dispatch(); // no args for workflow

// update the running conditions:
execution.update({ condition: 'value' });

// cancel the state machine early (rejects the promise):
execution.cancel();
execution.cancel({ error: 'property' });

// stop the machine early (resolves the promise):
execution.stop();

// of course, we can also chain off the execution promise:
execution.then(console.log, console.error);

Type parameters

  • T: Record<string, any>

Hierarchy

Index

Properties

[toStringTag]: string

Methods

  • Invoked to stop the running process, immediately rejecting the promise. No further actions will be run.

    Parameters

    • Optional data: Properties

      Optional data to merge into the Error the promise will be rejected with.

    Returns void

  • catch<TResult>(onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>
  • Attaches a callback for only the rejection of the Promise.

    Type parameters

    • TResult = never

    Parameters

    • Optional onrejected: (reason: any) => TResult | PromiseLike<TResult>

      The callback to execute when the Promise is rejected.

        • (reason: any): TResult | PromiseLike<TResult>
        • Parameters

          • reason: any

          Returns TResult | PromiseLike<TResult>

    Returns Promise<T | TResult>

    A Promise for the completion of the callback.

  • finally(onfinally?: () => void): Promise<T>
  • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

    Parameters

    • Optional onfinally: () => void

      The callback to execute when the Promise is settled (fulfilled or rejected).

        • (): void
        • Returns void

    Returns Promise<T>

    A Promise for the completion of the callback.

  • stop(): void
  • Invoked to stop the running process, immediately resolving the promise. No further actions will be run.

    Returns void

  • then<TResult1, TResult2>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>
  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type parameters

    • TResult1 = T

    • TResult2 = never

    Parameters

    • Optional onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>

      The callback to execute when the Promise is resolved.

        • (value: T): TResult1 | PromiseLike<TResult1>
        • Parameters

          • value: T

          Returns TResult1 | PromiseLike<TResult1>

    • Optional onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>

      The callback to execute when the Promise is rejected.

        • (reason: any): TResult2 | PromiseLike<TResult2>
        • Parameters

          • reason: any

          Returns TResult2 | PromiseLike<TResult2>

    Returns Promise<TResult1 | TResult2>

    A Promise for the completion of which ever callback is executed.

  • update(conditions?: Record<string, any>): void
  • Invoked to update the set of conditions used within the running process.

    NOTE: This method updates the conditions used by the ProcessLogic returned by dependencies.

    Parameters

    • Optional conditions: Record<string, any>

      The conditions to merge into the process' internal set of conditions.

    Returns void