function pageLoop(gameIDs, res, nextCursor) {
  return new Promise(
    function (resolve, reject) {
      setTimeout(() => {
        if (nextCursor != null) {
          getOauthToken().catch(e => {
            console.error("error while trying to receive access token: " + e);
          }).then((token) => {
            return getStreams(gameIDs, token, nextCursor);
          }).then((nextPage) => {

            if (nextPage && nextPage.data && nextPage.data.length > 0) {
              var counter = 0;

              nextPage.data.forEach(stream => {
                if (stream.tag_ids) {
                  var streamWithTag = tags.find(tag => {
                    if (stream.tag_ids.includes(tag))
                      return true;
                    return false;
                  });
                  if (streamWithTag) {
                    res.push(stream);
                    counter++;
                  }
                }
              });
            }
            if (nextPage && nextPage.data && nextPage.pagination && nextPage.pagination.cursor && nextCursor != nextPage.pagination.cursor) {

              nextCursor = nextPage.pagination.cursor;
              resolve({ "res": res, "next": nextCursor });
            }
            else {
              nextCursor = null;
              resolve({ "res": res, "next": null });
            }
          });

        }
        else {
          //console.log("no more cursor transmitted, end of list!");
          resolve({ "res": res, "next": null });
        }
      }, 150);

    }
  );
}
// resolves with a list of streams for the current cursor
resolves with a list of streams for the current cursor
resolves with a list of streams for the current cursor
function pageLoop(gameIDs, res, nextCursor) {
  return new Promise(
    function (resolve, reject) {
      setTimeout(() => {
        if (nextCursor != null) {
          getOauthToken().catch(e => {
            console.error("error while trying to receive access token: " + e);
          }).then((token) => {
            return getStreams(gameIDs, token, nextCursor);
          }).then((nextPage) => {
            if (nextPage && nextPage.data && nextPage.data.length > 0) {
              var counter = 0;
              nextPage.data.forEach(stream => {
                if (stream.tag_ids) {
                  var streamWithTag = tags.find(tag => {
                    if (stream.tag_ids.includes(tag))
                      return true;
                    return false;
                  });
                  if (streamWithTag) {
                    res.push(stream);
                    counter++;
                  }
                }
              });
            }
            if (nextPage && nextPage.data && nextPage.pagination && nextPage.pagination.cursor && nextCursor != nextPage.pagination.cursor) {
              nextCursor = nextPage.pagination.cursor;
              resolve({ "res": res, "next": nextCursor });
            }
            else {
              nextCursor = null;
              resolve({ "res": res, "next": null });
            }
          });
        }
        else {
          resolve({ "res": res, "next": null });
        }
      }, 150);
    }
  );
}
function pageLoop ( gameIDs , res , nextCursor ) { return new Promise ( function ( resolve , reject ) { setTimeout ( ( ) => { if ( nextCursor != null ) { getOauthToken ( ) . catch ( e => { console . error ( "error while trying to receive access token: " + e ) ; } ) . then ( ( token ) => { return getStreams ( gameIDs , token , nextCursor ) ; } ) . then ( ( nextPage ) => { if ( nextPage && nextPage . data && nextPage . data . length > 0 ) { var counter = 0 ; nextPage . data . forEach ( stream => { if ( stream . tag_ids ) { var streamWithTag = tags . find ( tag => { if ( stream . tag_ids . includes ( tag ) ) return true ; return false ; } ) ; if ( streamWithTag ) { res . push ( stream ) ; counter ++ ; } } } ) ; } if ( nextPage && nextPage . data && nextPage . pagination && nextPage . pagination . cursor && nextCursor != nextPage . pagination . cursor ) { nextCursor = nextPage . pagination . cursor ; resolve ( { "res" : res , "next" : nextCursor } ) ; } else { nextCursor = null ; resolve ( { "res" : res , "next" : null } ) ; } } ) ; } else { resolve ( { "res" : res , "next" : null } ) ; } } , 150 ) ; } ) ; }
resolves with a list of streams for the current cursor
resolves with a list of streams for the current cursor
//console.log("no more cursor transmitted, end of list!");