Class: Trigger<T>
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
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
T
T
Implements
PromiseLike<T>
Constructors
Constructor
new Trigger<
T>():Trigger<T>
Returns
Trigger<T>
Properties
reject
readonlyreject: (reason?) =>void
Parameters
reason?
any
Returns
void
resolve
readonlyresolve: (value) =>void
Parameters
value
T | PromiseLike<T>
Returns
void
Methods
then()
then<
TResult1,TResult2>(onfulfilled?,onrejected?):PromiseLike<TResult1|TResult2>
Attaches callbacks for the resolution and/or rejection of the Promise.
Type Parameters
TResult1
TResult1 = T
TResult2
TResult2 = never
Parameters
onfulfilled?
((value) => TResult1 | PromiseLike<TResult1>) | null
The callback to execute when the Promise is resolved.
onrejected?
((reason) => TResult2 | PromiseLike<TResult2>) | null
The callback to execute when the Promise is rejected.
Returns
PromiseLike<TResult1 | TResult2>
A Promise for the completion of which ever callback is executed.
Implementation of
PromiseLike.then