danielgerlag / danielgerlag/workflow-es

Output for "waitFor" is executed twice

Open
#53 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
218
Forks
52
PR merge metrics
No merged PRs in 30d

Description

Hi,

It seems that when I set the output for a "waitFor" step, the output function is being called twice;

Execution log:

Started workflow: c41127b43cef0
Waiting for event...
**event function**
Publishing event...
Published event
**event function**
The event data is hi!

The sample code:
````
const workflow_es = require('workflow-es');

class LogMessage extends workflow_es.StepBody {
run(context) {
console.log(this.message);
return workflow_es.ExecutionResult.next();
}
}

class EventSample_Workflow {
constructor() {
this.id = 'event-sample';
this.version = 1;
}

build(builder) {
builder
.startWith(LogMessage)
.input((step, data) => step.message = 'Waiting for event...')
.waitFor('myEvent', (data) => '0')
.output((step, data) => {
console.log('event function');
data.externalValue = step.eventData;
})
.then(LogMessage)
.input((step, data) => step.message = 'The event data is ' + data.externalValue);
}
}

async function main() {
const config = workflow_es.configureWorkflow();
const host = config.getHost();

host.registerWorkflow(EventSample_Workflow);
await host.start();

let id = await host.startWorkflow('event-sample', 1, {});
console.log('Started workflow: ' + id);

await new Promise(resolve => setTimeout(() => resolve(), 5000));

console.log('Publishing event...');
await host.publishEvent('myEvent', '0', 'hi!', new Date());
console.log('Published event');
}

main();
````
Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.