在 q 中是否有内置函数来配置比赛?
Is there a built-in function to configure a race in q?
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) {
// ...
});
编辑:源代码中似乎有一个 race 方法,但文档中没有提及。 https://github.com/kriskowal/q/blob/v1/q.js#L738
自从 v0.9.7 there is a Q.race
method that does exactly what you want. It's still not documented yet in the API reference 虽然。
此外,由于 v1.0.1 the function is available as .race
on the ES6-compliant Q.Promise
对象。
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) {
// ...
});
编辑:源代码中似乎有一个 race 方法,但文档中没有提及。 https://github.com/kriskowal/q/blob/v1/q.js#L738
自从 v0.9.7 there is a Q.race
method that does exactly what you want. It's still not documented yet in the API reference 虽然。
此外,由于 v1.0.1 the function is available as .race
on the ES6-compliant Q.Promise
对象。