目前我这样做很糟糕:
//start the initial request
request({
...
}).then(function(response1) {
//Start a second request once the first has finished as it is dependent on the original request finishing
request({
...
}).then(function(response2) {
...
}).catch(function(reason) {
...
});
}).catch(function(reason){
...
});
如何避免嵌入式请求并将其包含在原始流中并避免嵌套?
答案 0 :(得分:2)
返回对then语句的promise,它将等待并在下一个链接then
中使用它。
request({
...
}).then(function(response1) {
return request({
...
});
}).then(function(response2){
}).catch(function(reason){
...
});