title: How to combine the results of several MediaWiki API requests?
body: <p>I have a small (working) Wikipedia user script that queries the MediaWiki API and then queries it once again for each of the results of the first query, printing the results of the "second level" queries on the console (Firefox 52.0/Linux):</p>
  
  <pre><code>mw.loader.using( [ 'mediawiki.api', 'mediawiki.ForeignApi' ] ).done( function () {
      var api = new mw.Api();
      api.get( {
          action: 'query',
          meta: 'globaluserinfo',
          guiprop: 'merged'
      } ).done( function ( data ) {
          data.query.globaluserinfo.merged.forEach( function( element, index, array ) {
              let url = element.url;
              var remoteapi = new mw.ForeignApi( url + '/w/api.php' );
              [mw.config.get('wgNamespaceIds').user, mw.config.get('wgNamespaceIds').user_talk].forEach( function( element, index, array ) {
                  remoteapi.get( {
                      action: 'query',
                      list: 'allpages',
                      apprefix: data.query.globaluserinfo.name,
                      apnamespace: element
                  } ).done( function (data2) {
                      for( var j = 0; j &lt; data2.query.allpages.length; j++ )
                          console.log( url + '/wiki/' + data2.query.allpages[j].title );
                  });
              } );
          } );
      } );
  } );
  </code></pre>
  
  <p>I now want to replace the individual console outputs with <em>one</em> combined dialog box (à la <code>mw.loader.using( 'oojs-ui-windows' ).done( function () { OO.ui.alert( 'All results: ' + results ); } );</code>).</p>
  
  <p>In other words, I want to execute one callback when all API queries have been done, accessing/aggregating/combining the results from all of them.  How can that be done?</p>