Generators in JavaScript - What, Why and How - FunFunFunction #34
Why Stack Overflow recommends it
Stack Overflow users link it as a teaching reference when an answer involves generators or async flow and the asker needs a walkthrough of how generators work.
Recommended by 1 people across 1 different months, 2017 to 2017.
What it is
A 27-minute episode of the FunFunFunction series in which MPJ explains JavaScript generators, describing them as pausable functions or co-routines. It covers what they are, why they are useful for managing async operations alongside promises, and how to write them.
What people said
Recommends prajnavantha · 2017-03 · Stack Overflow · on “Javascript: Weird syntactic element”
I would not like to read your code for you but i think, with a little help you could understand this code your self. I guess you need help with the various new syntax being used in the code above. I'll try to note down those so that you can understand all of this code yourself. (0, (_asyncToGenerator2 || _load_asyncToGenerator()).default)(function*{}) This line basically is similar to (0,x)(function*{}) where x is a function which takes a generator function as an argument. Whenever you have a line of the form (x,y) it will always return the last value. So in the case of(x,y) it will return y. If its (0,x) it will return x. Thus in code which you posted, the first line will return (_asyncToGe
Cites Flame_Phoenix · 2017-04 · Stack Overflow · on “Achieve error differentiation in Promises”
Objectives When I started this thread, I had two objectives in mind: Having error differentiation Avoid an if then else of doom in a generic catcher I have now come up with two radically distinct solutions, which I now post here, for future reference. Solution 1: Generic error handler with Errors Object This solution is based on the solution from @Marc Rohloff [LINK] , however, instead of having an array of functions and looping through each one, I have an object with all the errors. This approach is better because it is faster, and removes the need for the if validation, meaning you actually do less logic: const errorHandlers = { ObjectRepeated: function(error){ return { code: 400, error };
Cites Daksh M. · 2017-12 · Stack Overflow · on “Why can i not increment this property?”
Well the promise hasn't been resolved, so what you can do is use async await functions or JavaScript generators which will make the client wait till the rating is incremented and the results json is sent. Here's a tutorial on async-await [LINK] and generators [this video] .