Skip to main content

Class: Trigger<T>

workflow.Trigger

A PromiseLike helper which exposes its resolve and reject methods.

Trigger is CancellationScope aware, it is linked to the current scope on construction and throws when that scope is cancelled.

Useful for e.g. waiting for a signal from Workflow execute

example

export type Blocked = () => {  execute(): Promise<void>;  queries: {    isBlocked(): boolean;  };  signals: {    unblock(): void;  };};
import { Trigger, CancelledFailure } from '@temporalio/workflow';import { Blocked } from '../interfaces';
export const unblockOrCancel: Blocked = () => {  let blocked = true;  const unblocked = new Trigger<void>();
  return {    queries: {      isBlocked(): boolean {        return blocked;      },    },    signals: {      unblock(): void {        unblocked.resolve();      },    },    async execute(): Promise<void> {      try {        console.log('Blocked');        await unblocked;        blocked = false;        console.log('Unblocked');      } catch (err) {        if (!(err instanceof CancelledFailure)) {          throw err;        }        console.log('Cancelled');      }    },  };};

Type parameters#

Name
T

Implements#

  • PromiseLike<T>

Constructors#

constructor#

new Trigger<T>()

Type parameters#

Name
T

Properties#

reject#

Readonly reject: (reason?: any) => void

Type declaration#

▸ (reason?): void

Parameters#
NameType
reason?any
Returns#

void


resolve#

Readonly resolve: (value: T | PromiseLike<T>) => void

Type declaration#

▸ (value): void

Parameters#
NameType
valueT | PromiseLike<T>
Returns#

void


then#

Readonly then: <TResult1, TResult2>(onfulfilled?: null | (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: null | (reason: any) => TResult2 | PromiseLike<TResult2>) => PromiseLike<TResult1 | TResult2>

Type declaration#

▸ <TResult1, TResult2>(onfulfilled?, onrejected?): PromiseLike<TResult1 | TResult2>

Type parameters#
NameType
TResult1T
TResult2never
Parameters#
NameType
onfulfilled?null | (value: T) => TResult1 | PromiseLike<TResult1>
onrejected?null | (reason: any) => TResult2 | PromiseLike<TResult2>
Returns#

PromiseLike<TResult1 | TResult2>

Implementation of#

PromiseLike.then