title: Calculating sum of multiple async callbacks
body: <p>I am still learning Javascript properly and read a few threads on here about asynchronity (<a href="https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call/14220323#14220323">1</a> <a href="https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron">2</a>).
  Unfortunately, I have still trouble to find a solution to my problem. I am calling an API in async fashion and would like to create a sum out of the response that I am receiving of multiple async calls.</p>
  
  <p>Let's say I want my code to perform an action if my "sum" has a value of 40. Async call "A" returns 6, async call "B" returns 8, and so on until we finally reach the value of 40.
  How can I create such a sum, as my calls are all async?
  Would it require to write each async result to a database and pull the value up in the next async call?
  Is there a better solution for this?</p>
  
  <p>Thank you for your help.</p>
  
  <p>EDIT: To make things easier to understand I will add some source code:</p>
  
  <p>Webhook.js</p>
  
  <pre><code>router.post('/', (req, res, next) =&gt; {
    if (middleware.active)
      middleware.handle(req.body) // &lt;--- this gives me one result
    res.sendStatus(200)
  });
  </code></pre>
  
  <p>Basically, I will receive multiple webhook calls. "middleware.handle" will send an API call to third party application. I want to take the result from that API call and add it to the result of another API call from another webhook request.</p>
  
  <p>As you can see, I don't know when my webhook will be triggered, neither how many times it will be triggered before reaching my desired total of 40.</p>