One issue that I frequently encounter while using async/await is the following error:
RangeError: Value undefined out of range for undefined options property undefined
at Set.add (<anonymous>)
at AsyncHook.init (internal/inspector_async_hook.js:19:25)
at PromiseWrap.emitInitNative (internal/async_hooks.js:134:43)
I am unsure how to resolve this error. My code is written entirely in TypeScript and I have not created any file named 'async_hooks'.
Despite my best efforts to limit the number of simultaneous async functions (using await extensively), it seems that JavaScript fails to reduce the asyncId count efficiently, leading to a rapid exhaustion of the allowed limit.
Even when I tried reducing the use of async/await, the problem persisted. However, delaying the occurrence of the error until after the function completes successfully.
I am using Electron 7 and it appears to have a restricted async pool. This behavior can be replicated with a basic TypeScript code snippet:
class Test {
private async testCompare(a,b):Promise<boolean> {
return a == b;
}
public async testRun():Promise<void> {
for (let index = 0; index < 999999999; index++) {
for (let index2 = 0; index < 999999999; index2++) {
await this.testCompare(index,index2)
}
}
}
}
new Test().testRun();
This implementation leads to high memory consumption, similar to what I experience in my own program. It appears that the async pool gets filled up quickly until it hits its maximum capacity.