eventual icon indicating copy to clipboard operation
eventual copied to clipboard

Broadcast Event

Open thantos opened this issue 3 years ago • 0 comments

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");
})

thantos avatar Nov 25 '22 18:11 thantos