• Wednesday , 20 September 2017

JavaScript Generators

Code Canyon



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

3d Ocean

Related Posts

25 Comments

  1. Rameshkumar Veldurai
    August 8, 2017 at 07:03

    Thanks, Awesome video

  2. Laurie Gray
    August 8, 2017 at 07:03

    Awesome teacher thanks so much

  3. Mojo Jojo
    August 8, 2017 at 07:03

    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.

  4. HonestOntario
    August 8, 2017 at 07:03

    @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?

  5. Rafael Goesmann
    August 8, 2017 at 07:03

    Is the run function similar to the co library? https://github.com/tj/co

  6. Krabby Paddy Vlogs
    August 8, 2017 at 07:03

    hi I was wondering how to start a new youtube channel if you have 0 subs

  7. noherczeg
    August 8, 2017 at 07:03

    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

  8. Fin Monster
    August 8, 2017 at 07:03

    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.

  9. Franco Bellucci
    August 8, 2017 at 07:03

    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!

  10. Gustavo N.
    August 8, 2017 at 07:03

    Could you please make some video on Cordova. I could really use some help xD

  11. Thomas Decrick
    August 8, 2017 at 07:03

    Your voice sounds a bit like Seth Rogan's

  12. TheInfamousButt
    August 8, 2017 at 07:03

    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.

  13. Ken Aguilar
    August 8, 2017 at 07:03

    The result of yield 'grizzly' is not gonna be assigned to kind?

  14. Ouriel Ottaviani
    August 8, 2017 at 07:03

    Do you think you can start a project that's more complex? A full production site for example?

  15. sj
    August 8, 2017 at 07:03

    Is there a way to use generators on streams?

  16. Hari K T
    August 8, 2017 at 07:03

    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.

  17. Hayden Lueck
    August 8, 2017 at 07:03

    Do you have your bash_profile posted anywhere? Looks nice.

  18. Chlorophant
    August 8, 2017 at 07:03

    I find your lack of semicolons disturbing Darth Vader Voice

  19. anthony-y
    August 8, 2017 at 07:03

    What font is he using? It's the default one on OSX right? What's it called?

  20. sdsdsdfsdf
    August 8, 2017 at 07:03

    i was staring at this run function for an hour and finally understood it.

  21. sdsdsdfsdf
    August 8, 2017 at 07:03

    If generators are available in es2015 then why don't you use let instead of var?

  22. Sarbbottam Bandyopadhyay
    August 8, 2017 at 07:03

    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.

  23. tut54as
    August 8, 2017 at 07:03

    What would happen inside the run function if the callback had more than two parameters?
    Thanks

  24. Sumit Jain
    August 8, 2017 at 07:03

    Thanks for explaining generators. They are awesome. I use it with bluebird promise.coroutine to write my code in synchronous way.

  25. Jay Scott ANDERSON
    August 8, 2017 at 07:03

    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. 🙂

Leave A Comment

You must be logged in to post a comment.