Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 10, 2022

  1. Add await to createTimeSeries so that onMetricUploadError can take ef…

    …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();
    /////////////////////////////////////////////////////
    ywangjl committed May 10, 2022
    Configuration menu
    Copy the full SHA
    e3ae7fd View commit details
    Browse the repository at this point in the history