Forget your promises... adopt the yielded style programming

946 views
Skip to first unread message

Michaël Rouges

unread,
Aug 12, 2013, 9:41:37 PM8/12/13
to nod...@googlegroups.com
Hi all,

I created a new tool browsers/Node.js compatible.

It can handle asynchronous calls as if they weren't, and can create relationships between your various scopes.

https://npmjs.org/package/yld

Floby

unread,
Aug 14, 2013, 5:50:02 AM8/14/13
to nod...@googlegroups.com
I don't get the flow from the examples.

Michaël Rouges

unread,
Aug 14, 2013, 6:01:24 AM8/14/13
to nod...@googlegroups.com
More examples at http://dvp.io/yld-art (french)

I'm currently working on a proper translation, in english... ;)

Michaël Rouges

unread,
Aug 14, 2013, 8:13:03 AM8/14/13
to nod...@googlegroups.com
Posted 6 how-it-works-* in the examples directory.

Need more? :)

Norman Paniagua

unread,
Aug 14, 2013, 10:39:02 AM8/14/13
to nod...@googlegroups.com
Maybe instead of examples will be much better an explanation of the concept, seems that the french post explain it but will be cool to have it in english.

Regards

Michaël Rouges

unread,
Aug 14, 2013, 11:44:20 AM8/14/13
to nod...@googlegroups.com
Thanks for this advice...

I wish to make it... I search for a good tutorial to make a complete GitHub wiki in rules of the art...

Michaël Rouges

unread,
Aug 14, 2013, 3:38:13 PM8/14/13
to nod...@googlegroups.com
The wiki : https://github.com/Lcfvs/yld/wiki

I apologize if my English isn't very correct, I receive with pleasure your comments.

Rick Waldron

unread,
Aug 14, 2013, 6:31:18 PM8/14/13
to nod...@googlegroups.com
It's unwise to encourage the use of `yield` in non-generator function bodies... "yield" is strict-mode reserved and will throw a SyntaxError exception in ES6 engines. This appears in many places throughout the readme file.


Rick








On Wed, Aug 14, 2013 at 3:38 PM, Michaël Rouges <michael...@gmail.com> wrote:
The wiki : https://github.com/Lcfvs/yld/wiki

I apologize if my English isn't very correct, I receive with pleasure your comments.

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michaël Rouges

unread,
Aug 14, 2013, 8:35:28 PM8/14/13
to nod...@googlegroups.com
Could you tell me why, for you, my yielded functions aren't generator functions, please?


Martín Ciparelli

unread,
Aug 14, 2013, 9:09:19 PM8/14/13
to nod...@googlegroups.com

Because they're missing the '*'?

Rick Waldron

unread,
Aug 14, 2013, 9:18:58 PM8/14/13
to nod...@googlegroups.com
On Wed, Aug 14, 2013 at 8:35 PM, Michaël Rouges <michael...@gmail.com> wrote:
Could you tell me why, for you, my yielded functions aren't generator functions, please?
Because they're not.

A Generator function looks like this:

function * generator() {
  yield 1;
}

Note the asterisk between "function" and "generator".

Rick

Rick Waldron

unread,
Aug 14, 2013, 9:20:16 PM8/14/13
to nod...@googlegroups.com
Too be blunt, none of the code in the yld.js file will actually run, these will all throw syntax error exceptions: https://github.com/Lcfvs/yld/blob/master/yld.js#L76-L97

Rick

Jake Verbaten

unread,
Aug 14, 2013, 9:35:58 PM8/14/13
to nod...@googlegroups.com
That looks like the old firefox version of generators as well as firefox specific (from es4) destructuring & conditional catch clause.

Rick Waldron

unread,
Aug 14, 2013, 9:37:20 PM8/14/13
to nod...@googlegroups.com
On Wed, Aug 14, 2013 at 9:35 PM, Jake Verbaten <ray...@gmail.com> wrote:
That looks like the old firefox version of generators as well as firefox specific (from es4) destructuring & conditional catch clause.


Good catch. I had dismissed the possibility since this was all node-oriented.

Michaël Rouges

unread,
Aug 14, 2013, 9:56:53 PM8/14/13
to nod...@googlegroups.com
My code is based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7 examples...

Would they be so wrong?

Rick Waldron

unread,
Aug 14, 2013, 10:02:24 PM8/14/13
to nod...@googlegroups.com
On Wed, Aug 14, 2013 at 9:56 PM, Michaël Rouges <michael...@gmail.com> wrote:
My code is based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.7 examples...

Would they be so wrong?

Yes, if you're trying to use generators in node, which are based on the in-progress ES6 standard. If your library is meant to be used in Firefox only and with special script tags, then your code is fine, otherwise it's not. 

Don't argue with me, I'm right.

Rick

Bruno Jouhier

unread,
Aug 15, 2013, 5:45:14 AM8/15/13
to nod...@googlegroups.com
Looks like Michaël has been working with generators in Firefox (he mentions JavaScript 1.7 somewhere).

Michaël, you should take a look at harmony generators. They will superseed the JS 1.7 generators in Firefox. It's the same concept but the syntax has evolved a little bit. For example yield is only allowed inside generator functions declared with function*. You can play with them with node 0.11.5.

Also, some projects you can look at:

https://github.com/jmar777/suspend
https://github.com/spion/genny
https://github.com/bjouhier/galaxy (mine - there is a browser example that works in Chrome Canary)

Bruno

Michaël Rouges

unread,
Aug 15, 2013, 5:50:48 AM8/15/13
to nod...@googlegroups.com
Thanks Rick, for your explanations...

New version (1.0.1) online... ES6 generators compliant.

The NPM seems to take a few time to refresh my last publication... but the repo is ok.

Michaël Rouges

unread,
Aug 15, 2013, 5:52:26 AM8/15/13
to nod...@googlegroups.com
Thanks too, Bruno... it's already completed... :D

Rick Waldron

unread,
Aug 15, 2013, 8:16:02 AM8/15/13
to nod...@googlegroups.com
On Thu, Aug 15, 2013 at 5:45 AM, Bruno Jouhier <bjou...@gmail.com> wrote:
Looks like Michaël has been working with generators in Firefox (he mentions JavaScript 1.7 somewhere).

Michaël, you should take a look at harmony generators. They will superseed the JS 1.7 generators in Firefox. It's the same concept but the syntax has evolved a little bit. For example yield is only allowed inside generator functions declared with function*. You can play with them with node 0.11.5.

Also, some projects you can look at:

https://github.com/jmar777/suspend
https://github.com/spion/genny
https://github.com/bjouhier/galaxy (mine - there is a browser example that works in Chrome Canary)


Maybe I'm just grouchy this morning, but is there any reason why you're just repeating everything that Jake and I have already posted?

Rick

Michaël Rouges

unread,
Aug 15, 2013, 8:50:09 AM8/15/13
to nod...@googlegroups.com
Any other bad things in my tool?

I ask nothing better than to code better. :)

Bruno Jouhier

unread,
Aug 15, 2013, 12:11:52 PM8/15/13
to nod...@googlegroups.com


On Thursday, August 15, 2013 2:16:02 PM UTC+2, Rick Waldron wrote:



On Thu, Aug 15, 2013 at 5:45 AM, Bruno Jouhier <bjou...@gmail.com> wrote:
Looks like Michaël has been working with generators in Firefox (he mentions JavaScript 1.7 somewhere).

Michaël, you should take a look at harmony generators. They will superseed the JS 1.7 generators in Firefox. It's the same concept but the syntax has evolved a little bit. For example yield is only allowed inside generator functions declared with function*. You can play with them with node 0.11.5.

Also, some projects you can look at:

https://github.com/jmar777/suspend
https://github.com/spion/genny
https://github.com/bjouhier/galaxy (mine - there is a browser example that works in Chrome Canary)


Maybe I'm just grouchy this morning, but is there any reason why you're just repeating everything that Jake and I have already posted?

Answer is simple: I did not scroll far enough down and did not see that there were more messages in the thread (or the page wasn't up-to-date - I don't know). But I saw them just after posting and felt a bit silly.

Bruno

Rick Waldron

unread,
Aug 15, 2013, 12:20:30 PM8/15/13
to nod...@googlegroups.com
On Thu, Aug 15, 2013 at 12:11 PM, Bruno Jouhier <bjou...@gmail.com> wrote:


On Thursday, August 15, 2013 2:16:02 PM UTC+2, Rick Waldron wrote:



On Thu, Aug 15, 2013 at 5:45 AM, Bruno Jouhier <bjou...@gmail.com> wrote:
Looks like Michaël has been working with generators in Firefox (he mentions JavaScript 1.7 somewhere).

Michaël, you should take a look at harmony generators. They will superseed the JS 1.7 generators in Firefox. It's the same concept but the syntax has evolved a little bit. For example yield is only allowed inside generator functions declared with function*. You can play with them with node 0.11.5.

Also, some projects you can look at:

https://github.com/jmar777/suspend
https://github.com/spion/genny
https://github.com/bjouhier/galaxy (mine - there is a browser example that works in Chrome Canary)


Maybe I'm just grouchy this morning, but is there any reason why you're just repeating everything that Jake and I have already posted?

Answer is simple: I did not scroll far enough down and did not see that there were more messages in the thread (or the page wasn't up-to-date - I don't know). But I saw them just after posting and felt a bit silly.


Makes sense—I've done the same before. Sorry for being a nit-picker.

Rick

Michaël Rouges

unread,
Aug 16, 2013, 1:35:06 AM8/16/13
to nod...@googlegroups.com
New readme...

Michaël Rouges

unread,
Aug 18, 2013, 5:41:42 AM8/18/13
to nod...@googlegroups.com
New version 1.0.7

The generators are now extensibles.

The parent generator yld() & error are unavailable, from the child generator. Each generator treats them itself.


https://npmjs.org/package/yld

Michaël Rouges

unread,
Aug 18, 2013, 6:39:08 AM8/18/13
to nod...@googlegroups.com
New major version (1.1.0)

Simplified parent <-> child communication

See the how-it-works-6.js & the diff

https://npmjs.org/package/yld

Michaël Rouges

unread,
Aug 18, 2013, 9:00:42 AM8/18/13
to nod...@googlegroups.com
Version 1.1.1

this.error becomes this.throw(), conforming with the ES6 generators

Rick Waldron

unread,
Aug 18, 2013, 6:46:46 PM8/18/13
to nod...@googlegroups.com
Just a friendly heads up, there is no close method on GeneratorObject, eg. 

fnGenerator.close();
generator.close();



Rick

On Sunday, August 18, 2013, Michaël Rouges wrote:
Version 1.1.1

this.error becomes this.throw(), conforming with the ES6 generators

--

Michaël Rouges

unread,
Aug 18, 2013, 9:15:58 PM8/18/13
to nod...@googlegroups.com
Hi Rick,

Thank you for looking at my code, however, the spec says otherwise.

http://wiki.ecmascript.org/doku.php?id=harmony:generators

Michaël

Jake Verbaten

unread,
Aug 19, 2013, 5:03:14 AM8/19/13
to nod...@googlegroups.com
At the top of that page it says 

> This proposal has progressed to the Draft ECMAScript 6 Specification, which is available for review here: specification_drafts.
> The content on this page is for historic record only and may no longer reflect the current state of the feature described within.

If you look at the draft spec ( http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.19.4.1 ) it says there are two methods, next & throw

Rick: That notice of "this page is 100% out of date and should not be used at reference material" really should be a lot more obvious. Maybe something like give the bolded message a title "Warning:" with a warning icon


--

Michaël Rouges

unread,
Aug 19, 2013, 6:51:40 AM8/19/13
to nod...@googlegroups.com
Thanks guys. Updated to version 1.1.2 ;)


2013/8/19 Jake Verbaten <ray...@gmail.com>

Rick Waldron

unread,
Aug 19, 2013, 9:13:42 AM8/19/13
to nod...@googlegroups.com
On Mon, Aug 19, 2013 at 5:03 AM, Jake Verbaten <ray...@gmail.com> wrote:
At the top of that page it says 

> This proposal has progressed to the Draft ECMAScript 6 Specification, which is available for review here: specification_drafts.
> The content on this page is for historic record only and may no longer reflect the current state of the feature described within.

If you look at the draft spec ( http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.19.4.1 ) it says there are two methods, next & throw

Rick: That notice of "this page is 100% out of date and should not be used at reference material" really should be a lot more obvious. Maybe something like give the bolded message a title "Warning:" with a warning icon


I think it's pretty obvious already and I'm not really interested in spending the amount of time it would require to go back and update every page. People should just read the whole page before claiming to know a thing. I do appreciate your feedback though and if I have a day where I have time to do this, I'll dig in, but that might not be very soon.



 

On Sun, Aug 18, 2013 at 6:15 PM, Michaël Rouges <michael...@gmail.com> wrote:
Hi Rick,

Thank you for looking at my code, however, the spec says otherwise.

http://wiki.ecmascript.org/doku.php?id=harmony:generators

Do me a favor, when I offer you feedback based on ES6 features, try to remember that I'm a member of TC39, directly involved in ES6, and assume that I'm not trolling you. This doesn't mean that I think I'm always right, I'm not—I actually double checked the spec draft before sending you that message, just to be certain. What I promise is that I will always offer information in the best of faith and only to make that interested community members, such as yourself, stay well informed (so you too can pass it on).

Rick

 

Michaël Rouges

unread,
Aug 19, 2013, 10:00:42 AM8/19/13
to nod...@googlegroups.com
Rick,

Thanks for all...

I didn't expect that I would suggest, to share this new draft.

I share and advises all day, even though I'm much less present in the English-speaking community, since it isn't my force.


;)


2013/8/19 Rick Waldron <waldro...@gmail.com>

--

Michaël Rouges

unread,
Sep 12, 2013, 6:32:33 PM9/12/13
to nod...@googlegroups.com
New version (1.1.9) released. ;)

Norman Paniagua

unread,
Sep 12, 2013, 6:36:26 PM9/12/13
to nod...@googlegroups.com
can you provide release notes?

regards

-- 
Norman Paniagua
Sent with Sparrow

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/f27jl6NxCzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Michaël Rouges

unread,
Sep 12, 2013, 7:53:48 PM9/12/13
to nod...@googlegroups.com
Hi Norman,

Thanks for your interest.

This version includes some internal improvements changing nothing in its operation.

There's one significant change: in order to avoid recursion problems, the asynchronous execution privileges setImmediate(), then process.nextTick(), then  setTimeout()... depending
to the available methods.

Cordialy

Michaël Rouges

unread,
Sep 13, 2013, 5:07:24 AM9/13/13
to nod...@googlegroups.com
New major release (v 1.2.0)

Adding a way to set a delay before the generator.next() or generator.nextCb() call

In order to avoid recursion problems, the asynchronous execution privileges setImmediate(), then setTimeout()... depending to the available methods.

Reply all
Reply to author
Forward
0 new messages