Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-17 Thread jmar777
Here are the notes from the meeting when this was discussed: https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-01/jan-31.md#comprehensionsgenerator-syntax Ahh, thanks for the clarification. So, hopefully correct this time, the previous example should have really been: [for (url of

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-17 Thread jmar777
Also, FWIW, the LTR version reads much more naturally to me. Happy about that change. On Wednesday, July 17, 2013 8:42:40 AM UTC-4, jmar777 wrote: Here are the notes from the meeting when this was discussed:

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-17 Thread Rick Waldron
On Wed, Jul 17, 2013 at 8:42 AM, jmar777 jmar...@gmail.com wrote: Here are the notes from the meeting when this was discussed: https://github.com/**rwldrn/tc39-notes/blob/master/**

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-17 Thread Rick Waldron
On Wed, Jul 17, 2013 at 8:43 AM, jmar777 jmar...@gmail.com wrote: Also, FWIW, the LTR version reads much more naturally to me. Happy about that change. Same here :) On Wednesday, July 17, 2013 8:42:40 AM UTC-4, jmar777 wrote: Here are the notes from the meeting when this was

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-16 Thread cpprototypes
The code sample I posted was a simplified example to demonstrate the issue. The actual command line script I was working on uses the response from the get request for other things. That for...of syntax is very nice, is it an official part of ECMAScript 6? On Friday, July 12, 2013 2:47:28 PM

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-16 Thread jmar777
That for...of syntax is very nice, is it an official part of ECMAScript 6? Yes, although it's not implemented in V8 just yet. Once for-of and generator-expressions are implemented, a lot of these operations will become a lot nicer at the language level (rather than relying on cludgy

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-16 Thread jmar777
Yes, although it's not implemented in V8 just yet. I was wrong (and happy about it)! This is working in the latest unstable version of node/v8: $ node -e 'console.log(process.versions.v8)' 3.20.2 $ node --harmony-iteration --harmony-generators function* gen() { yield 'foo'; yield 'bar'; }

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-16 Thread Rick Waldron
On Tue, Jul 16, 2013 at 2:36 AM, cpprototypes cpprototy...@gmail.comwrote: The code sample I posted was a simplified example to demonstrate the issue. The actual command line script I was working on uses the response from the get request for other things. That for...of syntax is very nice,

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-16 Thread Rick Waldron
On Tue, Jul 16, 2013 at 9:13 AM, jmar777 jmar...@gmail.com wrote: That for...of syntax is very nice, is it an official part of ECMAScript 6? Yes, although it's not implemented in V8 just yet. Once for-of and generator-expressions are implemented, a lot of these operations will become a

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread cpprototypes
Thanks for the replies, I have a better understanding now of how these libraries are using generators. I hope that one of these types of libraries becomes as popular as the async library and standard within the node community. This way of writing async code is much more elegant than the

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread Tim Caswell
I'm so glad to see more interest in using generators in node.js. I've experimented with this style of programming a *lot*. I even went so far as to re-implement node.js in the lua language (luvit.io) and attempted to implement it on top of SpiderMonkey (luvmonkey) because both VMs already have

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread Jake Verbaten
The fact that you can't trivially do deep yields in callbacks is a good thing. For example ``` contents.split('\n').forEach(function(id) { var info = yield request.get('http://www.example.com?id='+idhttp://www.example.com/?id='+id, resume); }); ``` Would have done N get request in series

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread jmar777
This is probably true (although I'm currently arguing for them anyway in es-discuss :)). Regarding the suspend example, I keep running into this same problem myself, and the nested generators are just too clunky to work with for such common interactions. Expect some helper functions in the

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread Bruno Jouhier
Parallelizing is not very difficult. Galaxy gives you two ways to do it. The first one is to call galaxy.spin. This gives you another generator function on which you can yield later to get the result. This is very much like a future. var future = galaxy.spin(generatorFunction(args)); // do

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread jmar777
Hey - Just realized there's another simple solution to your issue (that should work with any of the libraries mentioned in this thread) - just avoid nested functions: suspend(function* (resume) { var contents = yield fs.readFile('idList.json', 'utf8', resume), ids =

Re: [nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-15 Thread Rick Waldron
On Mon, Jul 15, 2013 at 7:17 PM, jmar777 jmar...@gmail.com wrote: Hey - Just realized there's another simple solution to your issue (that should work with any of the libraries mentioned in this thread) - just avoid nested functions: suspend(function* (resume) { var contents = yield

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-13 Thread Bruno Jouhier
yield is only valid inside a function*. This is why galaxy has a 'Star' variant for all the array methods that take a callback. So, it should work if you replace forEach by forEachStar Bruno On Friday, July 12, 2013 11:47:28 PM UTC+2, cpprototypes wrote: I'm using node 0.11.3 with

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-13 Thread Bruno Jouhier
I responded a bit too quickly. To make it work with galaxy you need to change the following: * forEach - forEachStar * function(id) - function*(id) for the callback * add a yield to the forEachStar call (this is a function* so you need to yield on it) This will get you started but you will hit

[nodejs] Re: Weird error with generators (using suspend or galaxy)

2013-07-13 Thread Bruno Jouhier
I just published a new version (0.1.3) that makes it easier to deal with mulitple results callback. You don't need to write a wrapper any more; you just get the resutls as an array. So your example becomes: var galaxy = require('galaxy'); var fs = galaxy.star(require('fs')); var get =