The workflow module provides a set of static extension methods that can be called from within a workflow function. In this example, the waitFor extension method is called to add collation to the workflow, only continuing once both outside signals have been received.

//waitForWorkflow.ts
import { MeshFlow } from '@hotmeshio/hotmesh';

export async function waitForExample(): Promise<[boolean, number]> {
const [s1, s2] = await Promise.all([
Meshflow.workflow.waitFor<boolean>('my-sig-nal-1'),
Meshflow.workflow.waitFor<number>('my-sig-nal-2')
]);
//do something with the signal payloads (s1, s2)
return [s1, s2];
}

Methods

  • Spawns a child workflow and awaits the return.

    Type Parameters

    • T

      the result type

    Parameters

    Returns Promise<T>

    • the result of the child workflow
    const result = await MeshFlow.workflow.execChild<typeof resultType>({ ...options });
    
  • Spawns a hook from either the main thread or a hook thread with the provided options; worflowId/TaskQueue/Name are optional and will default to the current workflowId/WorkflowTopic if not provided

    Parameters

    Returns Promise<string>

  • Executes a function once and caches the result. If the function is called again, the cached result is returned. This is useful for wrapping expensive activity calls that should only be run once, but which might not require the cost and safety provided by proxyActivities.

    Type Parameters

    • T

      the result type

    Parameters

    • fn: ((...args: any[]) => Promise<T>)
        • (...args): Promise<T>
        • Parameters

          • Rest...args: any[]

          Returns Promise<T>

    • Rest...args: any[]

    Returns Promise<T>

  • Returns a random number between 0 and 1. This number is deterministic and will never vary for a given seed. This is useful for randomizing pathways in a workflow that can be safely replayed.

    Returns number

    • a random number between 0 and 1
  • Returns a search session for use when reading/writing to the workflow HASH. The search session provides access to methods like get, mget, set, del, and incr.

    Returns Promise<Search>

    • a search session
  • Sends signal data into any other paused thread (which is currently awaiting the signal)

    Parameters

    • signalId: string

      the signal id

    • data: Record<any, any>

      the signal data

    Returns Promise<string>

    • the stream id
  • Sleeps the workflow for a duration. As the function is reentrant, upon reentry, the function will traverse prior execution paths up until the sleep command and then resume execution thereafter.

    Parameters

    • duration: string

      See the ms package for syntax examples: '1 minute', '2 hours', '3 days'

    Returns Promise<number>

    • resolved duration in seconds
  • Spawns a child workflow and returns the child Job ID. This method guarantees the spawned child has reserved the Job ID, returning a 'DuplicateJobError' error if not. Otherwise, this is a fire-and-forget method.

    Parameters

    Returns Promise<string>

    • the childJobId
    const childJobId = await MeshFlow.workflow.startChild({ ...options });
    
  • Pauses the workflow until signalId is received.

    Type Parameters

    • T

      the result type

    Parameters

    • signalId: string

      a unique, shareable guid (e.g, 'abc123')

    Returns Promise<T>

    const result = await MeshFlow.workflow.waitFor<typeof resultType>('abc123');