Hey Jean -
> You probably had at look at taskjs.org.
Ya, I've been tracking task.js for awhile now - just haven't delved in too
deeply since node is realistically the only platform generators are going
to be practical on in the near future (browser support is obviously pretty
sparse still). On the one hand, task.js is awesome and deserves the hype
it's received. On the other hand, I find the promises layer to be a
deterrent against using it for Node applications, since the majority of the
node ecosystem is based on passing callbacks/continuations, rather than
promises. That's probably the most fundamental difference between suspend
and task.js: suspend is designed to be
> After much thinking, I came to the conclusion that this flow control
issue is not such a big deal, solutions like "promise/a" demonstrates that
async activities can be orchestrated in a readable way without threads.
I agree that promises *can* improve the situation, but I think it has to be
all-or-nothing. The random hodgepodge of promises use in node modules is
problematic - it's not the fault of promises, of course. It's just
confusing when/where you need to .then() vs. pass a callback. Regardless
of your feelings towards promises, though, it's important to recognize that
they're still just an abstraction on top of callbacks - you're either
passing a callback to the method itself, or you're passing a callback to
some method on your promise/future/deferred/etc. This is why generators
are particularly interesting with regards to async code: they're the first
*language* level construct in JS that allows this async behavior without
relying callbacks.
> I am conducting an experiment about a similar control flow problem
Parole looks really interesting! I'm going to give the source a
more thorough reading once I have time, but on first glance I like that it
thinks outside of the box, compared to 90% of the other control flow
libraries out there.
> This is more concise, does not have the array destructuring issue, runs
today everywhere and is readable once you understand that a Parole() is an
extended Function suitable as a node.js callback.
Given where destructuring assignment and generators currently stand in
V8/node, you're probably right for now, but remember that my goal is to get
ahead of the curve here in anticipation of these upcoming language
features. I think I would still prefer the following:
var resume = require('resume'), fs = require('fs');
suspend(function* (resume) {
var [err, buffer] = fs.readFile(__filename, resume);
// no callbacks or .on()'s or .then()'s, just use it!
console.log(buffer.toString('utf8'));
});
True, you have to pay the suspend/generator block, but that's a tax you
only have to pay once, and you can have as many async calls in there as
you'd like with no additional "taxation".
Thanks for the feedback, and I'm looking forward to hacking around with
Parole!
- Jeremy
On Wednesday, May 29, 2013 7:12:20 PM UTC-4, Jean Hugues Robert wrote:
>
> Hi,
>
> This is interesting. You probably had at look at taskjs.org. Generators
> are kinds of structured fibers that, yes, can be "abused" to provide some
> form of threading. How "unobstrusive" this can be remains to be fully
> explored, as you do, in good company (see also streamline implementation
> using generators, an interesting exploration too).
>
> Your approach reminds me about the "await" construct in C#, the"yield" in
> your example really means "await".
>
> After much thinking, I came to the conclusion that this flow control issue
> is not such a big deal, solutions like "promise/a" demonstrates that async
> activities can be orchestrated in a readable way without threads. Besides,
> early implementations of generators are apparently rather slow (fibers are
> fast, non standard... and controversial).
>
> I am conducting an experiment about a similar control flow problem, here
> is one result:
>
> var Parole = require('l8/lib/whisper'), fs = require( 'fs' );
>
>
>
> var read = Parole(); fs.readFile( __filename, read );
>
> read.on( function( err, data ){ console.log( data.toString( 'utf8' ); }
> );
>
> // or: read.then( function( data ){ console.log( data.toString( 'utf8'
> ); } );
>
>
> This is more concise, does not have the array destructuring issue, runs
> today everywhere and is readable once you understand that a Parole() is an
> extended Function suitable as a node.js callback.
>
> See https://github.com/JeanHuguesRobert/l8/wiki/ParoleReference. You may
> be surprised by the P.generator() easy way of defining an async generator
> using today's javascript.
>
> Yours,
>
> Jean Hugues
>
>
>
>
>
>
>
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.