This repository was archived by the owner on Oct 3, 2023. It is now read-only.
Add await to createTimeSeries so that onMetricUploadError can take ef…#978
Open
ywangjl wants to merge 1 commit intocensus-instrumentation:masterfrom
Open
Add await to createTimeSeries so that onMetricUploadError can take ef…#978ywangjl wants to merge 1 commit intocensus-instrumentation:masterfrom
ywangjl wants to merge 1 commit intocensus-instrumentation:masterfrom
Conversation
…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<void> {
return new Promise<void>(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();
/////////////////////////////////////////////////////
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). For more information, open the CLA check for this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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();
/////////////////////////////////////////////////////