zoukankan      html  css  js  c++  java
  • 码农干货系列【20】--add gtTime to Promise.js

    使用场景

    在一些时候,希望一件task不能太快完成,需要大于多少时间才可以执行,就可以使用Promise的gtTime方法.

    使用方式

            Promise.gtTime(f1(), 5000).then(f2);
            function f1() {
                var promise = Promise();
                setTimeout(function () {
    
                    console.log(1);
                    promise.resolve("from f1");
                }, 1500)
    
                return promise;
            }
    
            function f2() {
                var promise = Promise();
                setTimeout(function () {
    
                    console.log(2);
                    promise.resolve();
                }, 1500)
    
                return promise;
            }

    f1执行只需要1.5秒,但是希望至少5秒后再执行f2,所以使用Promise.gtTime(f1(), 5000).then(f2)。如果f1需要8秒,则无视5秒的限制,8秒后才执行f2。

    你可以点击这里下载最新版本。

    有关promise更多信息你可以访问:

    getting started with Promise.js(总)

  • 相关阅读:
    ubuntu开机挂载磁盘盘出现:Metadata kept in Windows cache, unable to mount
    ubuntuaptgetoldversion
    evince 41.2ubuntu 16.04snap
    ubuntu坚果云安装deb后启动不了
    电影票分析
    jieba分词讲解2
    期末总结建议
    软件架构师工作看法
    jieba分词讲解1
    1
  • 原文地址:https://www.cnblogs.com/iamzhanglei/p/3146139.html
Copyright © 2011-2022 走看看