Skip to content

Use a loop? #205

@robross0606

Description

@robross0606

I am absolutely baffled on how to use this client in a do..while loop. It appears the client does an async call, but I cannot seem to get it to await response before continuing.

async function test() {
  let doMore = true;
  do {
    let endpoint = `${share_api}/test/search/scopes/conceptId?start=${start}&pageSize=${pageSize}`;
    console.log(`Retrieving from ${endpoint}...`);
    let oldStart = start;
    await client
      .get(endpoint, args, (data, response) => {
        let values = data.values;
        let total = data.total;
        //   values.forEach(value => {
        //     console.log(value);
        //   });
        console.log(`Received ${values.length} result(s).`);
        doMore = data.hasMore;
        start += pageSize;
      })
      .on("error", function(err) {
        console.log("Something went wrong on the request", err.request.options);
        doMore = false;
      });
    doMore = oldStart < start;
    console.log("Got here.");
  } while (doMore);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions