在每个
then回调中,您都需要 返回 新的Promise:
exports.viewFile = function(req, res) { var fileId = req.params.id; boxContentRequest('files/' + fileId + '/content', req.user.box.accessToken) .then(function(response) { return boxViewerRequest('documents', {url: response.request.href}, 'POST'); }) .then(function(response) { return boxViewerRequest('sessions', {document_id: response.body.id}, 'POST'); }) .then(function(response) { console.log(response); });};
.then()调用返回的承诺然后将使用“内部”承诺中的值进行解析,以便您可以轻松地链接它们。
通用模式:
somePromise.then(function(r1) { return nextPromise.then(function(r2) { return anyValue; });}) // resolves with anyValue || ||/ /somePromise.then(function(r1) { return nextPromise;}).then(function(r2) { return anyValue;}) // resolves with anyValue as well
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)