I was trying to solve an issue for jest's detection of open handles when using async for external API. I did find a solution here that using process.nextTick
solves the problem. I understand that this adds an empty function to be executed immediately after the event loop finishes, but how does this solve the issue?
Tests fail with this code:
(async function myFunc() {
try {
let config = await s3.getObject({
Bucket: `bucketname`,
Key: `key`,
}).promise();
^ open handle is detected here
...more code
} catch (e) {
console.log(e)
}
})();
Tests pass with this code:
(async function myFunc() {
try {
await process.nextTick(() => { }) // <- added this line
let config = await s3.getObject({
Bucket: `bucketname`,
Key: `key`,
}).promise();
^ open handle is detected here
...more code
} catch (e) {
console.log(e)
}
})();