문제

I have two tasks ran by Bluebird:

// Require bluebird...
var Promise = require("bluebird");

// Run two tasks together
Promise
  .all([Git.getRemotes(), GitFtp.getFtpRemotes()])
  .spread(function (remotes, ftpRemotes) {
    // Something cool
  });

With q.js I had as response:

remotes.value (the response of my task)
remotes.state ("fullfilled" or "rejected" depending if the task thrown an error or not)
ftpRemotes.value
ftpRemotes.state

So inside the spread() part I was able to check the state of each task.
This is the code I was using before Bluebird

With bluebird I get just:

remotes
ftpRemotes

Containing just the array generated by my tasks.

I think I need Promise.allSettled but I can't find it in the documentation.
How can I get the state of each task?

도움이 되었습니까?

해결책

If you want to handle the case they're good/bad together:

//Require bluebird...
var Promise = require("bluebird");

// Run two tasks together
Promise
  .all([Git.getRemotes(), GitFtp.getFtpRemotes()])
  .spread(function (remotes, ftpRemotes) {
    // Something cool
  }).catch(function(err){
    // handle errors on both
  });

If you want to wait for both to either resolve or reject use Promise.settle:

Promise
  .settle([Git.getRemotes(), GitFtp.getFtpRemotes()])
  .spread(function(remotesStatus,ftpRemoteStatus){
        // the two are PromiseInspection objects and have:
        // isFullfilled, isRejected, value() etc.
  });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top