About generators

# Mohan.Radhakrishnan at cognizant.com (10 years ago)

I have used simple generators but there seem to be some advanced usages. I came across these git references from another post and I have looked at the code. What are some articles that explain these concepts for JS developers before delving into this type of code ? Is reading this code the only way ?

# Aaron Powell (10 years ago)
# Mohan.Radhakrishnan at cognizant.com (10 years ago)

Thanks. What is the underlying concurrency framework when we use generators for concurrent workloads ? Does it depend on the particular VM ?

# Mohan.Radhakrishnan at cognizant.com (10 years ago)
# Axel Rauschmayer (10 years ago)

Thanks Aaron! The longer version of that blog post is here: www.2ality.com/2015/03/es6-generators.html

# Jason Orendorff (10 years ago)

On Thu, May 14, 2015 at 2:05 AM, <Mohan.Radhakrishnan at cognizant.com> wrote:

Thanks. What is the underlying concurrency framework when we use generators for concurrent workloads ? Does it depend on the particular VM ?

Generators aren't for concurrency.

When a generator runs, it runs in the same thread as the caller. The order of execution is sequential and deterministic, and never concurrent. Unlike system threads, a generator is only ever suspended at points marked by yield in its body.

(copied from hacks.mozilla.org/2015/05/es6-in-depth-generators)

# Jeremy Martin (10 years ago)

Hey (author of suspend here): this post was an earlier attempt I had an explaining some of the concepts involved: devsmash.com/blog/whats-the-big-deal-with-generators

It covers some of the basics, like, what iterators are, how generators relate to iterators, how generators enable "suspended" execution within the context of run-to-completion semantics; etc. Hope it helps!