title: Javascript function does not exit the function wehn the condtion failed
body: <p>I have following code which process a queue and I need to exist the function when there are no messages in the queue and there is no enough time to process more messages. My problem is, it doesn't jump out of the function upon failing the condition and I think it's due to that this a recursive function but I cannot figure it out.</p>
  
  <pre><code>/**
   * Check if there is enough time to process more messages
   *
   * @param {} context
   * @returns {boolean}
   */
  async function enoughTimeToProcess(context) {
    return context.getRemainingTimeInMillis() &gt; 230000;
  }
  
  /**
   * Consume the queue and increment usages
   *
   * @param context
   *
   * @returns {boolean}
   */
  async function process(context) {
    const messagesPerRequest = queueConst.messagesPerRequest;
    const messagesToBeDeleted = [];
  
    const queue = new queueClient();
  
    const messages = await queue.getMessages(messagesPerRequest);
  
    if (messages === undefined) {
      if (await enoughTimeToProcess(context) === true) {
        await process(context);
      } else {
        return false;
      }
    }
  
    const responses = messages.map(async(messageItem) =&gt; {
      const messageBody = JSON.parse(messageItem.Body);
      const parsedMessage = JSON.parse(messageBody.Message);
  
      const accountId = parsedMessage[0].context.accountId;
      let code = parsedMessage[0].context.code;
  
      // Our DB support only lowercase characters in the path
      code = code.toLowerCase();
  
      const service = parsedMessage[0].name;
      const count = parsedMessage[0].increment;
  
      const storageResponse = await incrementUsage(
        { storageClient: storage, code, accountId, service, count }
      );
  
      if (storageResponse) {
        messagesToBeDeleted.push({
          Id: messageItem.MessageId,
          ReceiptHandle: messageItem.ReceiptHandle,
        });
      }
  
      return 1;
    });
  
    const processedMessages = await Promise.all(responses);
    const processedMessagesCount = processedMessages.length;
  
    if (messagesToBeDeleted.length &gt; 0) {
      console.log(`${processedMessagesCount} messages processed.`);
      await queue.deleteMessageBatch(messagesToBeDeleted);
    }
  
    if (await enoughTimeToProcess(context) === true) {
      await process(context);
    }
  
    return true;
  }
  </code></pre>