News for hackers. Stuff that matters.
Re:Node v8.1.2 by davidgf on Thursday June 15, 2017 @09:31AM (#14560164)
I started using Async/Await and liked it, but I've been learning more about functional programming and went back to Promises
Re:Node v8.1.2 by b34r on Thursday June 15, 2017 @10:48AM (#14560900)
It IS promises ;) labeling a function as async makes it return a promise. await is sugar for avoiding having to roll your own promise tree.
Re:Node v8.1.2 by cloverich on Thursday June 15, 2017 @10:57AM (#14560982)
Sounds interesting -- do you have any resources handy that cover what you allude to (spec. comparing async calls to promises, and favoring the latter?) I use both in my ui code and they seem to have their niche for me. I prefer promise based calls when I want to separate out fetching data from the state-mutating callback, or when I may want to "cancel" something (ex: fetch a list of items for a list component, then unmount the component before the list returns -- no need to handle the response data anymore).
Re:Node v8.1.2 by davidgf on Sunday June 25, 2017 @06:17AM (#14629407)
Unfortunately not, my opinion is simply based on my personal experience and on what I've been learning along the way. I find promises really handy for data processing pipelines (grab some data and perform some transformations over it to get it in the form you need), regardless of wether any of the steps is async or not. I still find async/await really useful and mix it with promises if I need it, but I prefer to keep my code as functional as I can. Besides, I don't really like how JavaScript handles exceptions and would rather staying away from try/catch if possible
Re:Node v8.1.2 by pier25 on Thursday June 15, 2017 @11:34AM (#14561345)
There is no difference, async/await is just another promise notation.
Re:Node v8.1.2 by davidgf on Sunday June 25, 2017 @06:07AM (#14629374)
Although async/await is simply syntax sugar around promises, there's a huge difference indeed. With async/await your code keeps an imperative style, while with promises code end up with a functional look