如果/不返回值,则异步函数调用

时间:2019-01-08 21:30:07

标签: node.js grpc

我一直在尝试在if / else中提取异步值,我已经解决了许多错误,但以下内容返回了空括号:

router.post('/api/shill', async (req, res) => {
  let checkIdLength = req.body.Id;
  let checkIP = validateIP(req.body.Ip);
  let checkPort = Number.isInteger(req.body.Port);
  console.log(req.body.Id);
  if (checkIdLength.length != 66 || checkIP != true || checkPort != true || typeof req.body.Wumbo != "boolean") {
    res.status(400).send('Invalid value(s) detected');
  }
  else try {
      challengeInvoice = getInvoice();
      res.status(200).send(challengeInvoice);
  } catch (e) {console.log(e)}
})

async function getInvoice() {
  await lnd.addInvoice({}, (err, res) => {return res}); 
}

首先,lnd.addInvoice与grpc通话相关

1 个答案:

答案 0 :(得分:0)

您可以将promise用于异步数据。

library(survminer)
library(survival)
survAL <- survfit(Surv(time, status) ~ sex, data = lung)

ggsurvplot(survAL, legend.title = "Allostatic Load", legend.labs = c("M","F"), 
 ylim = c(0.0, 1.0), conf.int = TRUE, pval = TRUE, 
 xlim = c(0,300), xlab = "Time", ylab = "Survival Probability", 
 break.time.by = 50, ggtheme = theme_light(), risk.table = TRUE, 
 risk.table.col = "strata",  risk.table.title="My title", data = lung)

然后

 try {
      getInvoice().then(challengeInvoice => {
           res.status(200).send(challengeInvoice);
       })
  } catch (e) {console.log(e)}