#... many module loading lines commented out------> sayHello = -> ....... console.log 'hello' [Function]------> a = -> ....... setTimeout sayHello, 1000 [Function]------> Q.fcall(a())....... .then console.log 'world'world[object Object]coffee> helloundefined
Since `a()` does not return a promise, `Q.fcall(a())` gives you back a promise that is immediately fulfilled, so its onFulfilled handler is called after only a single turn of the event loop, logging “world.” Then, 1000 ms later, your setTimeout timer fires independent of the Q mechanism, and “hello” is logged.
If you want to return a promise to log “hello” after 1000 ms, you’ll want to do something like
var Q = require("q");
function sayHello() {
console.log("hello");
}
function a() {
return Q.delay(1000).then(sayHello);
}
a().then(function () {
console.log("world");
});
Note that you don’t need to use `Q.fcall` if `a()` already returns a promise.
Also, just a tip, when asking for help on mailing lists it is preferable to use the common language everyone speaks and that the library is written in, viz. JavaScript. Using CoffeeScript will dramatically decrease the number of people able to help you or interested in responding.
--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.