workflow-es icon indicating copy to clipboard operation
workflow-es copied to clipboard

waitFor - multiple events

Open AviFix opened this issue 6 years ago • 1 comments

Hi,

I'm trying to do as the following:

I want my workflow to have multiple paths. for example, I want to wait for 2 events. 1 named "manager" and the other named "client"

if the manager event happened then continue in 1 path and if the "client" event happened then continue in the second path.

But I need the workflow not to wait until both events happen.

I need it to continue and complete when the first (of 2) event happens

This is my example code:

export class HelloWorldWorkflow implements WorkflowBase<any> {
  public id: string = 'hello-world';
  public version: number = 1;

  public build(builder: WorkflowBuilder<any>) {
    builder
      .startWith(HelloWorld)
      .parallel()
      .do(branch1 => branch1
        .startWith(HelloWorld1)
        .waitFor('manager', data => '0')
        .output((step, data) => step.eventData && console.log(`Event manager`))

        .then(HelloWorld2),
      )
      .do(branch2 => branch2
        .startWith(HelloWorld3)
        .waitFor('client', data => '0')
        .output((step, data) => step.eventData && console.log(`Event client`))
        .then(HelloWorld4),
      )
      .join()
      .then(GoodbyeWorld);
  }
}


But in my example, the workflow will end only after both events happen.

Thanks

 

AviFix avatar Jan 23 '20 10:01 AviFix

What if you modeled it as 1 event with that carries different data depending on the origin (manager, etc...)?

danielgerlag avatar Feb 22 '20 04:02 danielgerlag