Make it a function method
Closed this issue · 2 comments
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 about function
- it is convertion of regular function
to async function
. As it is so, more appropriate place for it is Function.prototype
and definitely not Promise
. In this case naming would be like asAsync
and it would tell more about what it actually do
As a free bonus it would allow to naturally pass arguments to the function call
The syntax became:
Promise.try(f.bind(null, arg1, arg2)
vs
f.asAsync(arg1, arg2)
Another free bonus is that it allows to easily obtain an async
version of any function by just
const fAsync = f.asAsync.bind(f)
That may provide more separation to data preparation and business logic
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