链接没有返回值的承诺的最佳实践

时间:2021-05-12 22:48:50

标签: javascript node.js promise es6-promise

长短 - 我有大约 4 或 5 个不同的功能在一个快速服务器上的一个 promise 中运行。大数据集让我在 Heroku 上超时,所以我试图将其分解为不同的步骤。承诺不返回任何内容,只是异步更新服务器上的文件。

问题是触发承诺解决的最佳实践是什么?现在我只是发送 undefined 因为它们没有被触发,但我很好奇最佳实践是什么。

运行带有节点后端的快速服务器

app.post("/pdf", (req, res) => {
res.contentType("application/json");
req.body.layout.callsheet ?

toPNG.pdfToPNG(req.body.layout.callsheet, pdfPath)
  .then( async () => {
  
  await generatePDf(req.body.data, pdfPath, req.body.layout.selected)
    .then(() => {

      console.log()
      layout === "landscape" ?
      
        call.doubleCover(`${pdfPath}`, `${pdfPath}-coverSheet.png`)
          .then(res.send(undefined)) :   // <---------- is there a better way to do this?

        call.singleCover(`${pdfPath}`, `${pdfPath}-coverSheet.png`)
          .then(res.send(undefined)).    // <---------- is there a better way to do this?

    })
    .catch(err => console.log(err + " line 151"))

}) : generatePDf(req.body.data, callSheet)
   .then(res.send(undefined))   // <---------- is there a better way to do this?

.catch(err => res.send(err + " line 162"))

})

0 个答案:

没有答案
相关问题