This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
Add await to createTimeSeries so that onMetricUploadError can take ef… #978
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…fect
Currently the error thrown by createTimeSeries cannot be captured by onMetricUploadError, because the code is not run under the same context as the try catch block without "await".
Please see the following code illustration, toggle between "delayWithError(ms);" and "await delayWithError(ms);" to see the difference. Without await, the error is not caught and handled.
////////////////////////////////////////////////////
async function delay(ms: number): Promise {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
async function delayWithError(ms: number) {
await delay(ms);
throw("some error");
}
async function test(ms: number) {
console.log(
start first delay, waiting for ${ms}ms...
);await delay(ms);
console.log("Done first delay");
console.log(
start second delay with error, waiting for ${ms}ms...
);// await delayWithError(ms);
delayWithError(ms);
}
async function main() {
const ms = 1000;
try{
await test(ms);
}catch(err){
console.log("caugh error:" + err);
}
}
main();
/////////////////////////////////////////////////////