Sent from my Windows Phone
From: Chris Scribner
Sent: 12/31/2011 6:55 PM
To: nodejs
Subject: [nodejs] asyncblock 1.0 released (Flow control library built
on Fibers)
Dear community,
The module:
https://github.com/scriby/asyncblock
Thanks!
Feedback is welcome,
Chris
--
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
I wonder if it would be possible to combine call and wait into a
single line for the simple case, so to be more like streamline. In my
humble opinion this might improve popularity of such module like:
var asw = flow(setTimeout(flow.callback(), 2000));
var parallel = flow(setTimeout(flow.callback(), 2000),
setTimeout(flow.callback(), 3000));
> //Get the result of fs.readFile(path, 'utf8')
> var contents = flow.func(fs.readFile).args(path, 'utf8').sync();
Is the this pointer in readFile correct and equal to fs?
I think in an ideal world, you would never have to call some sort of
wait() anywhere. You would have some way of dependency analysis that
decides for you, what things can run in parallel, without having to
explicitly write it out yourself. Of course the good coder, still
needs to write code that way, to give that flow diagram good
possibilities to do things in parallel.
But maybe thats kind of possible. So you call the async function, and
it returns a future/promise kind of object, which halts execution just
when you need its value and its not there yet. Might even be possible
to do by Javascripts valueOf feature.
var o = flow(some.aSyncFunction(foo, bar, flow.callback)) // <-- this
returns an object whouse valueOf function is set. Returns immediately.
var x = o + 1; <-- the valueOf function will yield when o is not yet ready.
Maybe this will let people scream up again yet once more, because of
the hazards to do unsafe use of globals and not caring when the yield
might happen. Maybe it still is a nice option for efficient and
elegant coding for people who just avoid coding that kind of hazards.
One idea state would be to have all the asny/parallell tasks quite in
the background, like this:
var contents1 = fs.readFile(path1, 'utf8');
var contents2 = fs.readFile(path1, 'utf8');
console.log(content1 + '::' content2);
One might argue, that in this state its too obscure, where
halt/reentries might happen, and this is evil. In that case where
content1 and content are computed.
Following might be a good compromise:
var contents1 = async(fs.readFile(path1, 'utf8', callback));var
contents2 = async(fs.readFile(path1, 'utf8',
callback));console.log(contents1.keep + '::' contents2.keep);
async highlights there is something happening otherwise, "keep" (like
keeping the promise) is a getter, that might yield the until the async
is completed if it didn't already. Any calls to keep would be possible
reentry points. The hazard of random subroutines yielding on you,
without expectation is removed, since only who holds the "async"
handler, can create new promise/keep objects. And only who holds such
a value, is able to call its .keep getter, so a yield might happen.
Either the actual call to the async function is made in the main
application. This forces the application coder to make some more info
to the callback, so callback and async are matched (this is what you
first have done). This creates a heavy API to take care of, to do it
correctly.
Or you make the library do the actual function call, so it can fill
the callback parameter itself (this is what you second add-on did).
This, however, mangles up the this pointer and is thus bad. Having to
supply the this pointer as well, makes the whole interface cumbersome
again.
Third option is a complete preprocessor, like streamline did, which is
perceived a tad hefty by people, and the code you debug is not 100%
anymore the code you write.
Non of the three options is really, really satisfactory IMHO.
> var contents1, contents2;
> fs.readFile(path1, 'utf8', contents1 = flow.future());
> fs.readFile(path2, 'utf8', contents2 = flow.future());
> console.log(contents1.result + '::' + contents2.result);
Depending on style, one might also write like this with same mechanics:
var contents1 = future(), contents2 = future();
fs.readFile(path1, 'utf8', contents1);
fs.readFile(path2, 'utf8', contents2);
console.log(contents1.value + '::' + contents2.value);
Can somebody explain me what a "future" and "promise" actually is in
detail? Whats the difference between the both? "? I know what a
callback is, and what a fiber is. I get it futures and promises are
both some kind of function returned, but what exactly is know a
"future" and a "promise". And the difference between the both. I so
far just used node-futures etc. but it was more a general flow-control
library to me.