What does this code do?
await new Promise((resolve) => (Bugsnag.notify(ex, eventCallback), resolve));
function eventCallback(event) {
addMetadata(event, md);
addMetadata(event, ex.bugsnagMetadata);
}
function addMetadata(event, md) {
if(!md) return;
for (let mdKey in md) {
let mdValue = md[mdKey];
if(typeof(mdValue) === 'object')
event.addMetadata(mdKey, mdValue);
else
event.addMetadata(mdKey, mdKey, mdValue);
}
}
Feel free to ignore eventCallback
, addMetadata
. I've included them for extra context.
I originally asked Bugsnag how to use async/await on Bugsnag.notify and they responded with the above first line of code.
The code works great most of the time, but when I'm debugging a test within mocha, it hangs indefinitely on the await.
How does the resolve eventually get called and in the correct order--after notify has asynchronously completed?