I'm studying the promises pattern and using kriskowal's q for node.js,
having this snippet:
var deferred = Q.defer();
try {
messageData = JSON.parse(message);
} catch (e) {
global.logger.warn('Error parsing JSON message.');
deferred.reject(e);
}
...
if (some_reason)
deferred.resolve(something);
...
return deferred.promise;
What if both the parser fails and some_reason is true?
Will the execution procede from rejecting through resolving and both promise's method be called at different times, thus generating a bug?
Should i avoid to call reject/resolve multiple times?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…