代码之家  ›  专栏  ›  技术社区  ›  Prince Hamza

这个异步javascript[closed]的firebase等价物是什么

  •  -1
  • Prince Hamza  · 技术社区  · 7 年前

    这是我的异步javascript实践

    processArray();
    
            async function processArray() {
                for (const item of Myarray) {
                    await delayedlog(item);
                }
            }
    
            function delayedlog(i) {
                setTimeout(() => {
                    console.log(i);
                }, i * 5000);
            }
    var Myarray = [1,2,3]
    

    但在使用firebase时,我们不会使用设定时间,

    1 回复  |  直到 7 年前
        1
  •  1
  •   Frank van Puffelen    7 年前

    如果你问的是如何制作 await delayedlog(item) delayedlog . 您可以通过以下方式实现:

    function delayedlog(i) {
      return new Promise(function(resolve, reject) {
        setTimeout(() => {
          console.log(i);
          resolve();
        }, i * 5000);
      });
    }
    

    这个 await 然后等待 Promise