This might be a noob question, but I'm new to promises and trying to figure out how to use Q in node.js.
I see the tutorial begins with a
promiseMeSomething()
.then(function (value) {}, function (reason) {});
but I fail to grasp where exactly does the .then
came from. I guess it comes from
var outputPromise = getInputPromise()
.then(function (input) {}, function (reason) {});
but where does getInputPromise()
come from? I find no previous mention of it.
I have included it in my project like so
var Q = require('q');
// this is suppose, the async function I want to use promise for
function async(cb) {
setTimeout(function () {
cb();
}, 5000);
}
async(function () {
console.log('async called back');
});
How do I use Q
and its .then
here in my example?