是否有内置函数在q
JavaScript库中配置竞赛?
示例:
function fnThatReturnsAPromise1() { /*...*/ }
function fnThatReturnsAPromise2() { /*...*/ }
//Pseudocode: I want to have the first one of these functions that resolves, be the result
q.race([fnThatReturnsAPromise1,fnThatReturnsAPromise2])
.then(function(resultOfWinner) {
// ...
});
编辑:源中似乎有一种竞争方法,但文档中未提及。 https://github.com/kriskowal/q/blob/v1/q.js#L738