Closed Alexsey closed 6 years ago
Interesting idea; but this is about Promises. async function
s are just functions that always return a Promise (that allow alternative syntax inside them).
The overwhelming ecosystem standard for this is to call it "try" and attach it to Promise
; I think that moving it would cause it to be immediately rejected. Separately, I don't agree with your reasoning - the primitive here is Promise
, not Function
.
Well, async function
s are not just always return a promise. They also newer throw. And newer-throw is actually the thing you are interesting in as far as I can see from proposal description
Although I understand the point that such change would probably lead to immediate rejection
Historically this functionality were provided by libraries. And libraries are usually expose themselves in code as a separate objects. But if this functionality is considered to be added to the language itself - there is no more reason to limit it with the same restrictions
The proposed transformation is actually not so much about
Promise
as it is aboutfunction
- it is convertion of regularfunction
toasync function
. As it is so, more appropriate place for it isFunction.prototype
and definitely notPromise
. In this case naming would be likeasAsync
and it would tell more about what it actually doAs a free bonus it would allow to naturally pass arguments to the function call
The syntax became:
vs
Another free bonus is that it allows to easily obtain an
async
version of any function by justThat may provide more separation to data preparation and business logic