I'm using nodejs and was wondering when should I use Q defer, and when just use Promise.resolve/reject?
I saw a lot of examples of both kinds, for example:
// with Q defer
fucntion oneWay(myVal) {
var deffered = Q.defer();
if (myVal < 0) {
deffered.reject(new Error('nope'));
} else {
deffered.resolve('yay');
}
return deffered.promise;
}
// native Promise
fucntion orAnother(myVal) {
if (myVal < 0) {
return Promise.reject(new Error('nope'));
} else {
return Promise.resolve('yay');
}
}
What's the difference, and when is a good practice to use difer?
Is there any difference between Promise.resolve/reject (native) and Q.resolve/reject? They both return promise but it looks different when I look at the return value in node console.
Thanks