Skip to content

Instantly share code, notes, and snippets.

@wadez
Last active June 13, 2021 10:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadez/d6f44abce8dc5862092278ea7336b285 to your computer and use it in GitHub Desktop.
Save wadez/d6f44abce8dc5862092278ea7336b285 to your computer and use it in GitHub Desktop.
Notional example of callback hell
login.use(getLoginStrategies(function (db, session, done) {
var retrievedUsername;
var setUserName = function (a) {
retrievedUsername = a
}
var retrievedProfile;
var setProfile = function (a) {
retrievedProfile = a
}
var user = db.getUser(
session.getUsername(function (err, username) {
if (err) return done(null);
setUserName(username);
}),
function (err, user, done1) {
if (err) return done(null);
setTimeout(function () {
if (user.username !== retrievedUsername) return done1(null);
var profile = db.getProfile(
session.getCachedProfile(function (err, profile, verifyProfile) {
if (err) return done(null);
setTimeout(function () {
setProfile(profile);
},1)
setTimeout(function () {
if (profile === null) return done(null)
verifyProfile(function (err, result) {
if (err || result === false) return done(null)
setProfile(profile);
})
}, 200)
}),
function (err, user, done2) {
if (err) return done(null);
setTimeout(function () {
if (profile.updatedAgo > 3600) return done2(null);
if (retrievedProfile !== null) return done(retrievedProfile)
done2(retrievedProfile)
}, 1000)
});
setTimeout(function () {
if (retrievedProfile !== null) {
profile.updatedAgo = 0;
}
done(profile)
}, 5000);
}, 1000)
});
setTimeout(function () {
done(user)
}, 6000);
}, function (err, profile, done) {
if (profile) {
return done(profile.getStrategy())
}
done(null);
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment