mojolicious / Mojo-AsyncAwait

:scream_cat: An Async/Await implementation for Mojolicious
Other
21 stars 0 forks source link

Improved await() regarding failing/rejected promises #2

Closed mjaix closed 3 years ago

mjaix commented 3 years ago

…with the possibility to avoid yet another eval wrapper.

I found that await handles the "sunshine" case great, but requires an eval wrapper to catch errors (which further should be passed without source code context information). IMHO I found a simple way to pass the error information, too.

jberger commented 3 years ago

I hate to be the bearer of bad news, but sadly that's all I have in this case.

First off, if this were a bare project, having such a syntax might be debatable, but it isn't. This project attempts to provide async/await as functions that appear to be keywords. As such they cannot change their prototype from one that expects (and will only take) one argument to taking two. It would be a massive breaking change for all existing users. Consider:

my @array = (await myfunc(), $thing); 

Before your patch that array would end up with two items, after it would only have one. That kind of breakage is not acceptable and so it would be rejected anyway. However it also isn't just trying to provide any syntax it is trying to provide a known syntax from other languages which have established that await throws an exception when it has an error, therefore making this change would actually change the expectation of the syntax away from the desired norm. I get it, perl doesn't have the best exception handling and so some people want to avoid evals. My answer to that is ... don't. The point is usually to let exceptions bubble up if you can.

But finally, this project in itself is essentially in moth-balls. I won't remove the code so that my existing users continue to be supported but now that Future::AsyncAwait has allowed mojo core to provide a native async/await from the framework itself, and one that doesn't depend on Coro, I have no intentions of making changes to this project.

All that goes to say, thanks for the effort and I wish I had better news for you.

mjaix commented 3 years ago

Thanks for the extremely quick reply ... my effort was not high at all, and I always appreciate help on climbing the learning curve, so I would not consider your news not being that bad :-).

I fully agree that there are syntax changes with my patch which are not acceptable at all, considering your example (although I would expect at least two elements in @array, but of course with the last element being $thing). I had been off from my Mojolicious based work for more than a year - of course I have registered Paul Evan's ongoing work on Future::AsyncAwait, but for whatever reason I thought Mojolicious' async stuff was based on Mojo::AsyncAwait :-(.

Perhaps it would be a good idea to mark the moth-ball status somewhere.