Tuesday 30 May 2017

Wait for queries results

I'm using the Couchbase nodeJS SDK. To make a query I must call bucket.query("SELECT ...", function(err, rows){console.log("query's result received")})

I would like to run queries sequentially like :

  1. Run query A
  2. Work on result A
  3. Run query B
  4. Work on result B
  5. ...
  6. Continue after all results has been reveived and handle

Or even better it could be

  1. Run all queries
  2. Work on results one by one as they are being reveived
  3. Continue after all results has been reveived and handle

The point is I dont know how to wait for all the queries to be finished before continuing. I tought of promises but I'm new to nodeJS and I'm not sure I used them correctly, maybe someone could point me to the right direction ?

I saw that the async/await feature is available in node but I didn't manage to make it working either.

Any help would be apprecietate !



via MHogge

No comments:

Post a Comment