Skip to content

Instantly share code, notes, and snippets.

@NguyenTungs
Last active March 12, 2019 08:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NguyenTungs/1dc0a9ed1c6fa6933012a7160d407d47 to your computer and use it in GitHub Desktop.
Save NguyenTungs/1dc0a9ed1c6fa6933012a7160d407d47 to your computer and use it in GitHub Desktop.
// Ví dụ về callback truyền thống, nỗi kinh hoàng của developer.
// link ref: https://anonystick.com/blog-developer/series-callback-javascript-phan-3-async-await-la-gi-va-su-khac-nhau-giua-promise-trong-javascript-vRwGny6a.jsx
const verifyUser = function(username, password, callback){
dataBase.verifyUser(username, password, (error, userInfo) => {
if (error) {
callback(error)
}else{
dataBase.getRoles(username, (error, roles) => {
if (error){
callback(error)
}else {
dataBase.logAccess(username, (error) => {
if (error){
callback(error);
}else{
callback(null, userInfo, roles);
}
})
}
})
}
})
}
// Thậm chí các bạn còn nhận ra rằng function getRoles còn lồng rất nhiều function nữa. Thật là rối rắm.
const getRoles = function (username, callback){
database.connect((connection) => {
connection.query('get roles sql', (result) => {
callback(null, result);
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment