javascript - Q promise & synchronous I/O -


after reading q documentation, under impression following wait on select thereby providing sync i/o capability. assume db open sqlite database.

   count = 500;    q.invoke(db, 'get', "select * blah blah ...").done(       function () { --count; },       function () { // error code}    );    console.log(count); 

testing reveals not true. how can select , result synchronized via promise methodology console output 499?

i want wrap in while loop processes x number of rows given row can decrease count value retrieved row. number of times through loop data dependent.

without introducing threads or fibers, not possible make asynchronous operation synchronous operation. such, need put console.log inside handler notifies when operation has completed.

var count = 500; q.invoke(db, 'get', "select * blah blah ...") .then(function (results) {     (var = 0; < results.length; i++) {         var result = results[i];         --count;     } }) .done(); 

some database api’s permit stream results. need in documentation. ideally like:

var count = 500; q(db) .invoke("getstream", "select * blah blah blah") .invoke("foreach", function (result) {     --count; }) .then(function () {     assert.equals(count, 0); }) .done(); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -