【发布时间】:2017-01-08 05:56:21
【问题描述】:
我需要做一个承诺序列。我想使用基于标准的方法(ES6?)。实现这一目标的最佳方法是什么? getToken() 和 httpReq() 返回承诺,clock.now 只是返回现在的 unix 时间戳。我的代码现在看起来像下面这样(简化/浓缩)。我知道我需要用一个单一的捕获来扁平化承诺链......有人可以说明一种干净、可读、不聪明的 ES6 方式吗?
// we don't have a good token so we need to get one first, then GET the resource.
getToken(host, port, auth).then(function(token) {
httpReq(method, host, port, path, token).then(function(data) {
console.log(data);
}, function(status) {
console.log(status);
});
}, function(status) {
console.log(status);
});
【问题讨论】:
标签: javascript