How to handle a Signal in TypeScript
- TypeScript
- JavaScript
import { setHandler } from '@temporalio/workflow';
export async function yourWorkflow() {
const groups = new Map<string, Set<string>>();
setHandler(joinSignal, ({ userId, groupId }: JoinInput) => {
const group = groups.get(groupId);
if (group) {
group.add(userId);
} else {
groups.set(groupId, new Set([userId]));
}
});
}
import { setHandler } from '@temporalio/workflow';
export async function yourWorkflow() {
const groups = new Map();
setHandler(joinSignal, ({ userId, groupId }) => {
const group = groups.get(groupId);
if (group) {
group.add(userId);
}
else {
groups.set(groupId, new Set([userId]));
}
});
}