Learn about JavaScript Generators and how to use them to write asynchronous code in a synchronous fashion.
Code examples from this video: https://github.com/shama/letswritecode/tree/master/javascript-generators
Original source
Learn about JavaScript Generators and how to use them to write asynchronous code in a synchronous fashion.
Code examples from this video: https://github.com/shama/letswritecode/tree/master/javascript-generators
Original source
25 responses to “JavaScript Generators”
Thanks, Awesome video
Awesome teacher thanks so much
For those who don't know what the done is in ( {value: somevalue, done:false} ) generator returned object:
It is just a property to let you know if there are any more elements to iterate over or not. It will return true if iterator is at the end of elements are no more elements are there to return and false if there are still elements left to be iterated.
@5:55, how does `kind` become bound to 'ferocious'…? So after the first bear.next() call, `var kind = ` is left hanging undefined until the next call…? If you pass in a list of arguments, would `kind` become an array or something?
Is the run function similar to the co library? https://github.com/tj/co
hi I was wondering how to start a new youtube channel if you have 0 subs
To be honest I really don't like this. Not the video, but generators. They are hiding something from us, and replace details with some sort of a black magic thingy. Do people really suffer that much with async processing of data?
I have a question as well: When you have a function like your run() function. If I want to use it, what should I expect? procedural processing of it, or async? I somewhat understand most of these basic tutorials, but I absolutely can not figure out how these fit in with any existing code. :S
Just realized how works your 'run' function. I think, you missed to explain very important thing that 'yield' always immediately returns object(let's call it 'singleObject'), even if async operation hasn't completed yet. but when async operation completed then generator append some data to value property of 'singleObject'. I doesn't check it, it's only my own speculation, but I think it is actualy.
What atom package are you using to enable the dots and the return mark at the end of each line? Any other packages to recommend? Thanks!
Could you please make some video on Cordova. I could really use some help xD
Your voice sounds a bit like Seth Rogan's
Hey Kyle, just wanted to say thanks for the awesome vids. I've watched a lot of them. I shared this one on Reddit to hopefully get you some more love. Keep it up. They are awesome. Love the simple format.
The result of yield 'grizzly' is not gonna be assigned to kind?
Do you think you can start a project that's more complex? A full production site for example?
Is there a way to use generators on streams?
one thing I was expecting with
var kind = yield 'grizzly'
yield kind + ' polar'
was it will print 'grizzly polar ' . I was also not sure how the generators are accepting the values .
Probably due to new to node 🙂 .
Thank you for the videos.
Do you have your bash_profile posted anywhere? Looks nice.
I find your lack of semicolons disturbing Darth Vader Voice
What font is he using? It's the default one on OSX right? What's it called?
i was staring at this run function for an hour and finally understood it.
If generators are available in es2015 then why don't you use let instead of var?
Thanks Kyle, as always, a good presentation. I guess the example, https://github.com/shama/letswritecode/blob/master/javascript-generators/index.js#L12-L38 might be a bit overwhelming for complete beginner to generators. A brief walk through of the code would be great. Could you help with few real time use cases, for using generator, may be a follow up video. Once again, thank you for all these great videos.
What would happen inside the run function if the callback had more than two parameters?
Thanks
Thanks for explaining generators. They are awesome. I use it with bluebird promise.coroutine to write my code in synchronous way.
Oh, just figured out, in the output, the second parameter, "done", as in { value: "grizzly", done: false }, has nothing to do with the "return 'done'" in the function body. 🙂