GithubHelp home page GithubHelp logo

Comments (2)

chenmnkken avatar chenmnkken commented on June 18, 2024

谢谢你的反馈,最近比较忙,没看到,我会尽快排查。

from easyjs.

chenmnkken avatar chenmnkken commented on June 18, 2024

@acelan86 你上面的Demo代码在使用上有点问题,easy.js 的 promise 设计的 E.when 方法只接受 promise 实例的参数,而你的 Demo 代码中传递给 when 方法的并不是 promise 实例。then 方法返回的并不是一个 promise 实例,then 方法返回的 this 是为了便于链式调用,这种错误的使用方法导致的 pmeCahce 中的列表被清除就不足为奇了。

正确的使用方法应该是这样的:

var showMsg1 = function(){
    var promise = new E.Promise();
    setTimeout(function(){
        alert( 'ok1' );
        promise.resolve( 'hello1' );
    }, 2000 );

    return promise;
};

var showMsg2 = function(){
    var promise = new E.Promise();
    setTimeout(function(){
        alert( 'ok2' );
        promise.resolve( 'hello2' );
    }, 8000 );

    return promise;
};


E.when( showMsg1(), showMsg2() ).then(function( str1, str2 ){
    alert( str1 + ' ' + str2 );
}).then(function(){
    alert( 'all promise is done' );
});

from easyjs.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.