4 ms·
> Also regarding that article: you can call async functions from non-async functions - you will simply get the Promise object instead of the data. async fu
by camus2 10y ago
> Also regarding that article: you can call async functions from non-async functions - you will simply get the Promise object instead of the data.
async function() getZ(){ return promise }
function() getX(){
return x = y * getZ()
}
// sync call globally.
let x = getX(); // NaN
async/await makes things more readable, it doesn't change the issue of leaky abstraction and you need to know whether the call is blocking or non blocking when calling getZ and using a function that calls getZ. What should you do? assume everything is asynchronous by default?
Imagine you have a validation lib, you don't need it to be asynchronous to validate a string of length > 10, but you need to rewrite your whole API if you need to validate the fact a unique index has to be validated from a database.
- realharo 10y agoThat's kind of exactly what the second half of my comment was about - if you have static typing, then this problem just doesn't exist. If not, then the problem is really no different from not knowing what your functions are returning (are they returing a Promise object? are they returning the data itself?). Not knowing the return type of the functions you use is hardly something new. You would have the exact same issue with functions that take callbacks. See the link I sent there https://goo.gl/vDk3Gz https://goo.gl/vDk3Gz - you can hover over all the variables and functions (once the editor fully loads), try typing "n.", hover over the highlighted errors, etc. The tooling takes care of everything.