1

Bluebird によって実行される 2 つのタスクがあります。

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

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

q.jsを使用すると、次のような応答がありました。

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

ということで、spread()パーツ内で各タスクの状態を確認することができました。
これはBluebirdの前に使用していたコードです

ブルーバードを使用すると、次のようになります。

remotes
ftpRemotes

私のタスクによって生成された配列だけを含みます。

必要だと思いますPromise.allSettledが、ドキュメントで見つけることができません。
各タスクの状態を取得するにはどうすればよいですか?

4

1 に答える 1

7

ケースを処理したい場合、それらは一緒に良い/悪いです:

//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
  });

両方が使用を解決または拒否するのを待ちたい場合Promise.settle:

Promise
  .settle([Git.getRemotes(), GitFtp.getFtpRemotes()])
  .spread(function(remotesStatus,ftpRemoteStatus){
        // the two are PromiseInspection objects and have:
        // isFullfilled, isRejected, value() etc.
  });
于 2014-03-26T11:28:27.837 に答える