3 ms·
No, the caller has control. result = await maybePromiseWhoCaresIUsedAwait(); You can use await without knowing if the function you called returns a promise
by Touche 9y ago
No, the caller has control.
result = await maybePromiseWhoCaresIUsedAwait();
You can use await without knowing if the function you called returns a promise or not. This works fine:
result = await 3;
- singularity2001 9y agook and to be safe you ``` await every() await freakin() await function() ``` ? Or you may end up with obscure bugs, when you expect a sync method or worse, when a sync method changes to async in the next api version(happened in real world!)
- Touche 9y agoI'm not aware of any programming language where it is safe to use a function's return value without knowing what the return value is. This seems unrelated to async/await, if you are calling functions that are returning things other than what you expect, you are pretty much screwed.
- xfer 9y agoNo in typed language, this is not a problem because the compiler will refuse to compile. For uni-typed languages async/await is not the right model imho.
- Touche 9y agoAgain, this is unrelated to async/await. Normal functions might return a number or an object or undefined or whatever. Since JavaScript is a dynamic language it is unsafe to call a function without either 1) Trusting that the function returns what its API says it should return or 2) Checking the return type and acting appropriately. So, the grandparent's complaint is about JavaScript being a dynamic language, async/await doesn't fix this issue or make it any worse.
- singularity2001 9y agograndpa here. position accepted.