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 unblocking a Workflow from a Signal.

Example

<!--SNIPSTART typescript-trigger-workflow-->
```ts
import { defineSignal, setHandler, sleep, Trigger } from '@temporalio/workflow';

const completeUserInteraction = defineSignal('completeUserInteraction');

export async function waitOnUser(userId: string): Promise<void> {
const userInteraction = new Trigger<boolean>();

// programmatically resolve Trigger
setHandler(completeUserInteraction, () => userInteraction.resolve(true));

const userInteracted = await Promise.race([userInteraction, sleep('30 days')]);
if (!userInteracted) {
await sendReminderEmail(userId);
}
}

## 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

| Name | Type |
| :------ | :------ |
| `reason?` | `any` |

##### Returns

`void`

___

### resolve

• `Readonly` **resolve**: (`value`: `T` \| `PromiseLike`<`T`\>) => `void`

#### Type declaration

▸ (`value`): `void`

##### Parameters

| Name | Type |
| :------ | :------ |
| `value` | `T` \| `PromiseLike`<`T`\> |

##### Returns

`void`

## Methods

### then

▸ **then**<`TResult1`, `TResult2`\>(`onfulfilled?`, `onrejected?`): `PromiseLike`<`TResult1` \| `TResult2`\>

#### Type parameters

| Name | Type |
| :------ | :------ |
| `TResult1` | `T` |
| `TResult2` | `never` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `onfulfilled?` | ``null`` \| (`value`: `T`) => `TResult1` \| `PromiseLike`<`TResult1`\> |
| `onrejected?` | ``null`` \| (`reason`: `any`) => `TResult2` \| `PromiseLike`<`TResult2`\> |

#### Returns

`PromiseLike`<`TResult1` \| `TResult2`\>

#### Implementation of

PromiseLike.then