eventual
eventual copied to clipboard
Broadcast Event
To go with Event (https://github.com/functionless/eventual/issues/49), which has Singlecast semantics via execution.send, we should support a broadcast semantic.
const ping = new Event<string>("ping");
const pong = new Event<string>("pong");
const worker = workflow(({ id: number }, { execution: { parentId } }) => {
const parent = controller.ref(parentId);
const sub = event.on(() => {
parent.send(pong, { ack: 1 });
});
await sleep(3 * 60);
if(id === 1) {
sub.dispose(); // unsubscribe;
}
})
const controller = workflow(() => {
const workers = [1,2,3].map((i) => worker.startWorkflow());
let resposnes = 0;
pong.on(() => { response++ });
// send to specific executions
ping.sendMany(workers, "hello");
await condition(() => responses === workers.len);
// send to anyone listening
ping.broadcast("hello");
})