Combination of async function + await + setTimeout

前端 未结 12 1591
予麋鹿
予麋鹿 2020-11-22 04:34

I am trying to use the new async features and I hope solving my problem will help others in the future. This is my code which is working:

  async function as         


        
12条回答
  •  清歌不尽
    2020-11-22 05:10

    The following code works in Chrome and Firefox and maybe other browsers.

    function timeout(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
    async function sleep(fn, ...args) {
        await timeout(3000);
        return fn(...args);
    }
    

    But in Internet Explorer I get a Syntax Error for the "(resolve **=>** setTimeout..."

提交回复
热议问题