0
Bluebird對於解析鏈有沒有任何方便的方法,其中每個元素的輸入都是前一個元素的解析值(除非它不是函數)?Bluebird的鏈接結果
我試圖鏈以下邏輯成一個單一的方法:
function getClient() {
// resolves with the client
}
function getClientProduct(client) {
// resolves with the product
}
var response = {}; // global response object;
function prepareResponse(product) {
// prepares global response object, resolves with `undefined`
}
promise.someMethod(getClient, getClientProduct, prepareResponse, response)
.then(data=> {
// data = the response object;
});
我想避免不必編寫以下的(如果可能的話):
getClient()
.then(client=>getClientProduct(client))
.then(product=>prepareResponse(product))
.then(()=>response);
好的,謝謝!我以爲我錯過了一些東西,因爲這會是一個不錯的功能;) –