I'm writing a piece of JavaScript to make one or two ajax calls. There will always be one ajax call fired but it might be two based on cookie setting. If user is logged in then we call another service to get the data. I would want this to fire async that's why I didn't put the second ajax call in the callback of the first call. We don't use jQuery just vanilla JS. 'use strict';import Cookie from 'js-cookie';const _ = require('../helpers');module.exports = function(cb) {  let number_of_calls = 1;  window._g = window._g || {};  const uid = Cookie.get('uid');  if (uid) {    number_of_calls += 1;  }  function setG(fds) {    --number_of_calls;    const out = JSON.parse(fds);    window._g.context = out;    if (number_of_calls === 0) {      cb({});    }  };  function setUser(user) {    --number_of_calls;    const out = JSON.parse(user);    window._g.user = out;    if (number_of_calls === 0) {      cb({});    }  }  _.ajax({url: '//some_service/content?url=' + _.url}).done(setG);  if (uid) {    _.ajax({url: '//another_service/user?uid=' + uid}).done(setUser);  } };
JavaScript multiple ajax calls but can either be one or two
javascript;ajax;callback