链接承诺和传递价值的简洁方式

Concise way of chaining promise and passing value

用 Bluebird promises 最简洁的写法是什么:

return someFunc().then(function(result) {
  return otherFunc(result).then(function(foo) {
    ...
  });
});

我看到了一些实用函数,例如 result() 但不是很清楚 how/which 我会使用。基本上我需要调用第二个函数,同时将第一个函数的结果作为参数传递。或者这是最简洁的?

你可以这样简化它:

return someFunc()
.then(otherFunc)
.then(function(foo) {
    return foo; // assuming you do more here...
});

我希望这不是您的全部代码,否则带有 return 的最后一个函数将毫无用处,整个代码将等同于

return someFunc().then(otherFunc);

.then(function(foo) { return foo; }); 是多余的。

鉴于您的示例,这就是您所需要的。

return someFunc().then(otherFunc);