title: Async function never returns
body: <p>I'm using Node version 7.6.0 to try out the native async and await features.</p>
  
  <p>I'm trying to figure out why my async call just hanging never actually resolves.</p>
  
  <p>NLP module:</p>
  
  <pre><code>const rest = require('unirest')
  const Redis = require('ioredis')
  const redis = new Redis()
  const Promise = require('bluebird')
  const nlp = {}
  nlp.queryCache = function(text) {
      return new Promise(function(resolve, reject) {
          redis.get(text, (err, result) =&gt; {
              if (err) {
                  console.log("Error querying Redis: ", err)
                  reject(new Error("Error querying Redis: ", err))
              } else {
                  if (result) {
                      let cache = JSON.parse(result)
                      console.log("Found cache in Redis: ", cache)
                      resolve(cache)
                  } else {
                      resolve(null)
                  }
              }
          })
      })
  }
  
  nlp.queryService = function(text) {
      console.log("Querying NLP Service...")
      return new Promise(function(resolve, reject) {
          rest.get('http://localhost:9119?q=' + text)
              .end((response) =&gt; {
                  redis.set(text, JSON.stringify(text))
                  resolve(response.body)
              })
      })
  }
  
  nlp.query = async function(text) {
      try {
          console.log("LET'S TRY REDIS FIRST")
          let cache = await nlp.queryCache(text)
          if (cache) {
              return cache
          } else {
              let result = await nlp.queryService(text)
              console.log("Done Querying NLP service: ", result)
              return result
          }
      } catch (e) {
          console.log("Problem querying: ", e)
      }
  
  }
  module.exports = nlp
  </code></pre>
  
  <p>The module consumer:</p>
  
  <pre><code>const modeMenu = require('../ui/service_mode')
  const nlp = require('../nlp')
  const sess = require('../session')
  const onGreetings = async function(req, res, next) {
      let state = sess.getState(req.from.id)
      if (state === 'GREET') {        
          let log = { 
              middleware: "onGreetings"           
          }
          console.log(log)
          let result = await nlp.query(req.text)
          console.log("XXXXXXXX: ", result)
          res.send({reply_id: req.from.id, message: msg})
  
      } else {
          console.log("This query is not not normal text from user, calling next()")
          next()
      }
  };
  module.exports = onGreetings;
  </code></pre>
  
  <p>I'm unable to get the code to proceed to following line:</p>
  
  <pre><code>console.log("XXXXXXXX: ", result) 
  </code></pre>
  
  <p>I can see that the query was successful in the NLP module</p>
  
  <p><a href="https://i.stack.imgur.com/aQLHB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aQLHB.png" alt="Console log output"></a></p>
  
  <p><a href="https://i.stack.imgur.com/2T0GV.png" rel="noreferrer">Edit: Added console.log statement to response body</a></p>
  
  <p><a href="https://i.stack.imgur.com/lLmWi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lLmWi.png" alt="Console output on the actual response.body"></a></p>
  
  <p><a href="https://i.stack.imgur.com/EtVGR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/EtVGR.png" alt="Log statement"></a></p>