node.js - Delay() in the q module -
i using nodejs , learning promises using q module.
i'm misunderstanding delay()
fn in q module, think .
when run code:
chain .then (function() {console.log('starting');}) .then (function() {console.log('waiting 2500ms');}) .delay(2500) .then (function() {console.log('done');}) .then (function() {console.log('waiting 5500ms');}) .delay(5500) .then (function() {console.log('done');}) .then(function() {console.log('waiting 4500ms');}) .delay(4500) .then (function() {console.log('done');}) .then(function() { process.exit(0);});
i expect see delays of indicated times.
first delay seems occur.
second delay doesn't seem 5500ms.
third delay, expected 4500ms, doesn't seem happen @ all.
i understanding "delay(x)" mean "then, delay x milliseconds". incorrect? misunderstanding?
if modify code replace each delay(x)
.then(function() {sleep.usleep(x * 1000);})
...then works expect.
can please explain? thanks.
the delay() little different else expect, makes uglier chain them. learned discussion here.
q() .then (function() {console.log('starting');}) .then (function() {console.log('waiting 2500ms');}) //.delay(2500) .then( function () { return q().delay( 2500 ); } ) .then (function() {console.log('done');}) .then (function() {console.log('waiting 5500ms');}) //.delay(5500) .then( function () { return q().delay( 5500 ); } ) .then (function() {console.log('done');}) .then(function() {console.log('waiting 4500ms');}) //.delay(4500) .then( function () { return q().delay( 4500 ); } ) .then (function() {console.log('done');}) .then(function() { process.exit(0);});
hopefully fix soon.
Comments
Post a Comment