处理promise的输出(Node JS)

时间:2017-02-07 08:44:32

标签: javascript node.js asynchronous callback promise

我希望此函数返回true / false。但事实并非如此。它返回undefined。你能帮我吗?

function isAvailable() {

  let startTime = new Date();
  let isAvail = null;
  Functions.getContentFromUrl(webLink + "/health-checker")
    .then((html) => {
      if (html.includes('Good!')) {
        isAvail=true;
      }
      else {
        console.error("Server is not available:" + html);
        isAvail =false;
      }


    })
    .catch((err) => {
        console.error("this is error" + err);
        isAvail =false;


      }
    )
  return isAvail;
  ;
}

0 个答案:

没有答案