I have function which starts many promise based functions in loop, for example:
let doSomething = (page, a, b) => {
return new Promise(async(resolve, reject) => {
eventBus.on('game::lag', () => {
throw new Error('Game lag');
});
while(a.length > 0) {
await doSomethingAsync();
await doSomething2Async();
while(b.length > 0) {
await doSomething3();
b = await getAsyncB();
}
a = await getAsyncA();
}
resolve();
});
};
Now on custom event, which come from other part of program, I want this script to die and stop every nested functions (doSomething*
functions). Additionally I have some intervals within doSomething*
functions but I want everything to stop also intervals.
I tried like in example code, error is thrown and catched in external file succesfully. However I can see doSomething*
scripts still runing.
Is it normal, that nested functions are still runinng although I thrown error from "parent"?