Is it safe to resolve a promise multiple times?

前端 未结 7 844
旧时难觅i
旧时难觅i 2021-01-31 06:33

I have an i18n service in my application which contains the following code:

var i18nService = function() {
  this.ensureLocaleIsLoaded = function() {
    if( !th         


        
7条回答
  •  粉色の甜心
    2021-01-31 07:33

    If you need to change the return value of promise, simply return new value in then and chain next then/catch on it

    var p1 = new Promise((resolve, reject) => { resolve(1) });
        
    var p2 = p1.then(v => {
      console.log("First then, value is", v);
      return 2;
    });
        
    p2.then(v => {
      console.log("Second then, value is", v);
    });

提交回复
热议问题