Tuesday, 23 May 2017

Nodejs promise not working when using q library

I am trying to learn promises on my own. This is the code I wrote -

var Q = require('q');

var promise = Q.fcall(function() {
  setTimeout( console.log('hi'), 1000 );
  return 7;
});

promise.then(function(contents) {
  console.log(contents);
});

setTimeout( function(){console.log('bye');}, 1000 );

Now this is not printing the contents. I just get C:\node\Ex_Files_UaR_Node\first>node example3.js hi bye

I was expecting to get - hi 7 bye

Please let me know if there is anything very much evident which I am missing.



via user3276247

No comments:

Post a Comment