title: how to make sure that a batch of requests are ready
body: <p>I need to get via API prices per dates for the following 12 months.</p>
  <p>One requirement is that requests cant be over 2 months. So I need to split this in 6 requests.</p>
  <p>So I get from current date to +1 month and I iterate 5 times more to get the 10 remaining months, like so:</p>
  <pre><code>const getPeriod = (dateIn, dateOut) =&gt; {
    axios
      .post(
        Utils.apiUrl,
        {
          hotelCodes: Utils.hotelId.split(','),
          dateIn: dateIn, 
          dateOut: dateOut, 
        }
      )
      .then((response) =&gt; {
        const calendarPrices = response.data.CalendarPrices
        var now = new Date()
        for (let d = 0; d &lt; calendarPrices.length; d++) {
          const date = new Date(calendarPrices[d].Date)
          date.setHours(12, now.getMinutes(), now.getSeconds()) 
          calendarPrices[d].dateObj = date
        }
        if (Utils.calendarPrices) {
          Utils.calendarPrices = Utils.calendarPrices.concat(calendarPrices)
        } else {
          Utils.calendarPrices = calendarPrices
        }
      })
      .catch((err) =&gt; {
        console.log(err)
      })
  }
  
  const getNextMonths = () =&gt; {
    for (let r = 1; r &lt;= requestsToMake; r++) {
      let dateIn = new Date()
      dateIn.setMonth(dateIn.getMonth() + 2 * r)
      const monthIn =
        (dateIn.getMonth() &lt; 9 ? '0' : '') +
        (parseInt(dateIn.getMonth(), 10) + 1)
  
      let dateOut = new Date()
      dateOut.setMonth(dateOut.getMonth() + 1 + 2 * r)
      const monthOut =
        (dateOut.getMonth() &lt; 9 ? '0' : '') +
        (parseInt(dateOut.getMonth(), 10) + 1)
      const lastDayOfMonth = new Date(
        dateOut.getFullYear(),
        dateOut.getMonth() + 1,
        0
      )
  
      getPeriod(
        `${dateIn.getFullYear()}-${monthIn}-01`,
        `${dateOut.getFullYear()}-${monthOut}-${lastDayOfMonth.getDate()}`
      )
  
    }
  }
  
  
  
  // get current month and the next one  
    axios
    .post(
      Utils.apiUrl,
      {
        hotelCodes: Utils.hotelId.split(','),
        dateIn: `${dateIn.getFullYear()}-${
          (dateIn.getMonth() + 1 &lt; 10 ? '0' : '') +
          parseInt(dateIn.getMonth() + 1, 10)
        }-${(dateIn.getDate() &lt; 10 ? '0' : '') + dateIn.getDate()}`,
        dateOut: `${dateOut.getFullYear()}-${
          (dateOut.getMonth() + 1 &lt; 10 ? '0' : '') +
          parseInt(dateOut.getMonth() + 1, 10)
        }-${
          (lastDayOfMonth.getDate() &lt; 10 ? '0' : '') +
          lastDayOfMonth.getDate()
        }`,
      }
    )
    .then((response) =&gt; {
      const calendarPrices = response.data.CalendarPrices
      var now = new Date()
      for (let d = 0; d &lt; calendarPrices.length; d++) {
        const date = new Date(calendarPrices[d].Date)
        date.setHours(12, now.getMinutes(), now.getSeconds()) 
        calendarPrices[d].dateObj = date
      }
  
      if (Utils.calendarPrices) {
        Utils.calendarPrices = Utils.calendarPrices.concat(
          calendarPrices
        )
      } else {
        Utils.calendarPrices = calendarPrices
      }
  
     
      datepicker = new HotelDatepicker(input, options)
      // get 10 more months
      getNextMonths()
    })
  </code></pre>
  <p>The problem i'm having is that those are async calls when the calendar is ready only the first request is complete</p>
  <p>How can i make sure all dates have been recived before I init the calendar?</p>
  <p>I'm thinking in making a recursive function but i don't know how to handle the callbacks..</p>