I have a library written on the callback pattern ...
I want to log in, check errors and continue next, but a misunderstanding of the js asynchronous operation does not give me that ...
let errorInfo = [];
function login() {
....
client.logOn(logOnOptions);
client.on('error', function (e) { // here callback to check for errors during auth, if it is not handle, the application will throw an exception
errorInfo.push(e.message);
})
nextFunction();
}
In this case, if there is an error, JS will start executing the next function nextFunction(), with an empty array ...
How can I stop the transition to the next function until the auth check passes?