Often times I accidentally call an asynchronous function directly like so
let get_users;
let users;
/*
* @return data on success and null otherwise
*/
get_users = async function (){
let users;
users = await $.ajax({...});
return users;
}
users = get_users();
if (users === null){
console.log ('Fail');
}
else{
console.log ('Success');
}
This will write Success every time because the returned promise is not null and it is quite a nightmare to debug. I can go through and append something to all of my 500+ asynchronous functions (eg. foo.bar_async ()) and then use grep to find all cases where a *_async function was called without the await command, but that is very hard and very ugly. Is there a better way to debug this (NOTE I do not believe JSHint can handle this, especially when files are loaded as modules)?