Friday 21 February 2020

Thoughts about async / await

I've been reading many posts about new async / await feature in JavaScript and find that not many people are fine with it. More interestingly people trying to reinvent the wheel like overwriting native implementation etc. `awaity` do this to some degree, and not everyone can't quite get understand why to put `bluebird.js` in your project. Still, there is always room for improvement.I wrote a small piece of code many years ago and put it into the npm library recently. This code traveling from project to project. You can find it very tiny and very useful - https://of.js.org/. It upgrades your promises with some basic features. First, it adds timeouts for your async operations which will be appreciated by jQuery and `axios` users. And of course, there retry option. You can define your default value in case of error or override error with your own (different message for user in the example). And most useful is to get rid of unnecessary repetitive try / catch code.I was inspired to write this after reading these posts:https://www.reddit.com/r/node/comments/dpzsv1/beginner_forcing_asynchronous_functions_to/https://www.reddit.com/r/node/comments/f3kfqo/how_do_you_handle_async_await_errors/https://www.reddit.com/r/node/comments/f3dzut/javascript_callback_promise_and_asyncawait/https://www.reddit.com/r/node/comments/f46rdz/how_to_rewrite_code_using_async_and_await_in_node/

Submitted February 21, 2020 at 04:27PM by r37r0m0d3l

No comments:

Post a Comment