承诺是在处理程序中创建的,但是在bluebird中没有从它返回

时间:2016-05-23 18:41:02

标签: javascript promise bluebird

我在我的应用中使用p,我使用babel将我的代码编译成es5。但是,我总是得到这个警告,并且我已经检查过Promise的每个部分都有bluebird值。

这是我的代码:

return

错误消息的详细信息:

Promise.promisifyAll(fs);

use.login().then((result) => {
  console.log(result);
  doSomething('../test.png');
});

function doSomething(filepath) {
  return fs.readFileAsync(filepath).then((bufs) => (
      doPost(url, bufs, filepath)
        .then((res) => (
          res.error ? Promise.reject(res.error) : Promise.resolve(res))
        )
  )).catch((err) => {
    console.error(err);
    return err;
  });
}


function doPost(url, bufs = null, filepath = null) {
  return new Promise((resolve, reject) => (
    unirest.post(url)
      .headers(config.Headers)
      .timeout(120000)
      .field(bufs)
      .attach('files', filepath)
      .end((res) => (
        res.error ? reject(res.error) : resolve(res)
      ))
  ));
}

1 个答案:

答案 0 :(得分:0)

感谢@Bergi我没有检查我呼叫doSomething的保证堆栈,所以在修改我的代码后警告消失了

use.login().then((result) => {
  console.log(result);
  doSomething('../test.png');
  return null; // Add this line to make promise return anything, then the warning gone
});