Answer the question
In order to leave comments, you need to log in
Asynchrony and taking a request request?
I have a function
var getStore = function(sessionID) {
sessionStore.get(sessionID, function(err, session){
return session ? true : false;
});
};
Answer the question
In order to leave comments, you need to log in
Well, why? Why turn good asynchronous code into bad synchronous code? There is a tool - work. Why change it?
Badly tried:
var getStore = function (sessionID) {
return new Promise(
function (resolve, reject) {
sessionStore.get(sessionID, function(err, session) {
if(err) {
reject(err);
}
resolve(!!session);
});
});
}
// usage
getStore(1).then(function(isAuth){
// isAuth - true or false
}, function(error){
// error
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question