creationix/gen-run — pull request #8 by TomiBelan (2013-08-31 08:44:10+00:00)
Title: Make gen more strict about being called exactly once

This pull request is branched off from #7. You probably want to look at 0eeee5f894face8b84d6f8ee70710cf0e68546e7, not the combined diff of both this and #7. If you want to merge it without #7, tell me and I'll rebase it.

What this commit does, and why:

* Protects against errors caused by incorrect usage. Correct library clients should be mostly unaffected. Ensures that gen is called at most once before the generator yields, and if it is not called, the generator has to yield a continuable.
* Fixes yielding weird async functions that receive a callback, but return a function value. Imagine a hypothetical setTimeout that doesn't return an integer, but a function that cancels the timeout when called. Yeah, I've never seen one either, this was mostly a side effect...
* Renames "resume" to "gen", to follow the README. The idea is that "resume" is what the anonymous function returned by "gen" is called. If you don't like the rename, I can separate it from the rest of the commit.
* Modifies tests so that they don't use `gen()(null, value)`. You're not supposed to do that: it circumvents the `done` check in resume. The new checks correctly detected that the tests didn't call gen before yielding nor yield a continuable.
* Removes useless `yielded = true` line from `check`.