Let’s get serious about ES6 generator functions
facebook.github.io
facebook.github.io
Watching the use of generators in JavaScript and especially node.js is going to be very exciting over the coming years. We're excited at LinkedIn because we write a lot of node.js, and control flow is always being discussed: step, async, stepup, promises, and async generators look to solve a lot of that.
Also, checkout the AGen formal spec[1] for asynchronous generators. Raynos and I put it together recently to encourage interoperability between async generator solutions, and we're both using it in personal projects.[2]
I just tried a yield in a recursive function and the output is as simple as a non-recursive function. Are there any edge cases interesting to see?
[1]http://blogs.msdn.com/b/ericlippert/archive/2009/08/24/itera...
Re: unforeseen edge cases, I'd love to see any failing pull requests for the test suite: https://github.com/facebook/regenerator/blob/master/test/tes...
try {
foo();
yield i;
}
catch(e) {
console.log(e);
}
If `foo` throws an exception, I handle it, right? I don't see your generator wrapped in an exception handler, but maybe `wrapGenerator` does it.http://fitzgeraldnick.com/weblog/51/
:)
Thanks for doing this!
I tried implementing sandboxing a little while back by cleaning the global namespace after every tick and freezing all the built in prototypes, but I still don't know enough about the dirty details of js to know if I am doing it properly in a way that will actually be fast.
I am reluctant to use with but a friend of mine suggested that it is possible to use it to avoid polluting the global namespace. This in combination with freezing all the global prototypes might be enough to do what I want.
Have you thought about this at all? Is there already a library for this that would do what I want? I wouldn't mind running the code in a worker to restrict access to the dom apis.
I think it might be a little slower than I would like, but I will try again.
Thanks :)
Python manages to work fine without ugly wart in the syntax, and it seems to me that presence of `yield` keyword in body is enough at syntactical level to tell compiler that the function is a generator.
The asterisk also makes it trivial (using regular expressions) to tell whether a string of code contains any generator functions.
"Explicit is better than implicit" is a rule of thumb that Python supposedly values, but neglects to follow here!