engine.execute() does not wait all the async service to be resolved
See original GitHub issueHi, I have a chart like below, each service will run an async function. I expect they will be run one by one, and then finish. But what I get is it finished before the second service is done. Do I mis-understand something which is basic?
console output
### before execute
### before serviceFn1 await
### after serviceFn1 await
### before serviceFn2 await
### after execute // I expect this line will be at the last line, but it isn't.
### after serviceFn2 await
### inside execute callback
chart
sample code
const { Engine } = require('bpmn-engine');
const source = `
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions id="Definitions_0cz8kjv" targetNamespace="http://bpmn.io/schema/bpmn"
xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL">
<bpmn:process id="Process_0x60oya" isExecutable="true">
<bpmn:startEvent id="StartEvent">
<bpmn:outgoing>Flow1</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow1" sourceRef="StartEvent" targetRef="ServiceTask1" />
<bpmn:serviceTask id="ServiceTask1" implementation="\${environment.services.serviceFn1}" >
<bpmn:incoming>Flow1</bpmn:incoming>
<bpmn:outgoing>Flow2</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow2" sourceRef="ServiceTask1" targetRef="ServiceTask2" />
<bpmn:serviceTask id="ServiceTask2" implementation="\${environment.services.serviceFn2}" >
<bpmn:incoming>Flow2</bpmn:incoming>
<bpmn:outgoing>Flow3</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="EndEvent">
<bpmn:incoming>Flow3</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow3" sourceRef="ServiceTask2" targetRef="EndEvent" />
</bpmn:process>
</bpmn:definitions>
`;
(async () => {
const engine = Engine({ source });
console.log('### before execute');
await engine.execute({
services: {
serviceFn1: async (scope, callback) => {
console.log('### before serviceFn1 await');
await (async () => {})();
console.log('### after serviceFn1 await');
return callback(null, 12345);
},
serviceFn2: async (scope, callback) => {
console.log('### before serviceFn2 await');
await (async () => {})();
console.log('### after serviceFn2 await');
return callback(null, 23456);
},
},
}, () => {
console.log('### inside execute callback');
});
console.log('### after execute');
})();
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why doesn't the code after await run right away? Isn't it ...
Just as its name implies, the await keyword will cause the function to "wait" until its promise resolves before executing the next line....
Read more >Nodejs does not wait for promise resolution - exits instead
js process will exit when there is no work scheduled, but a listener registered on the 'beforeExit' event can make asynchronous calls, and ......
Read more >Async Methods - Testing Library
Several utilities are provided for dealing with asynchronous code. These can be useful to wait for an element to appear or disappear in ......
Read more >Control startup and shutdown order in Compose
However, for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it's...
Read more >javascript - await does not wait for Promise to finish
This is standard for asynchronous events in JavaScript. async functions always return a Promise which is not guaranteed to be resolved before ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That was true for an older version of the engine. I have updated the documentation.
Hi, thank you for the advice, I’ll try to think more about event-driven programing 😃
By the way, I found that it says that
at here Execution listener. Is that mean I can listen like this? (which I’ve tried but not work…)