You cannot say that "there isn't a way to get rid of callbacks", because
there ARE ways.
Solutions like streamline.js or fibers DO EXIST and have been around for a
more than a year. They allow you to write non bocking code without
callbacks. Maybe you don't like these solutions but that's a different
problem.
People keep equating "asynchronous" with "callbacks" and this is just
wrong. Asynchronous is a behavior, callbacks just a mechanism; and there
are other mechanisms than callbacks to deal with asynchronous behaviors: an
underscore marker in streamline, async/await keywords in jscex/F#, yield in
fibers, etc. When I write:
var next_id = rclient.incr("next_id", _);
This code is asynchronous. And the underscore marker indicates where the
code may yield. So nothing's hidden and the execution model is the same as
with async callbacks: non blocking, single threaded event loop, non
preemptive.
And BTW, there are also lots of synchronous callbacks around. For example:
arr.forEach(function(elt) {
// synchronous!!
});
ASYNCHRONOUS !== CALLBACKS
Bruno
On Tuesday, March 20, 2012 4:36:30 AM UTC+1, Mihai Tomescu wrote:
>
> Like it was mentioned, there isn't a way to get rid of callbacks because
> that's what gets us evented io in the first place.
>
> So at the end of the day, it's how you want to handle async code.
>
> My preference is the lightest possible abstraction written by @substack
> https://github.com/substack/node-seq. No fibers, thread-like things or
> any other crazyness, it just runs stuff sequentially.
>
> An yeah writing blocking code is a Bad Thing™ in node.
>
> On Sunday, March 18, 2012 8:23:37 PM UTC-4, Angelo Chen wrote:
>>
>> Hi,
>>
>> got this :
>>
>> function get_next_id() {
>> rclient.incr("next_id", function(err, reply) {
>> return reply
>> });
>> }
>>
>> will call this with:
>>
>> var next_id = get_next_id()
>>
>> this won't work, because function returns even before 'reply' was
>> taken from rclient( a redis), one solution is, passing a call back to
>> the function, is there any other way? thanks.
>>
>> Angelo
>>
>
On Tuesday, March 20, 2012 4:36:30 AM UTC+1, Mihai Tomescu wrote:
>
> Like it was mentioned, there isn't a way to get rid of callbacks because
> that's what gets us evented io in the first place.
>
> So at the end of the day, it's how you want to handle async code.
>
> My preference is the lightest possible abstraction written by @substack
> https://github.com/substack/node-seq. No fibers, thread-like things or
> any other crazyness, it just runs stuff sequentially.
>
> An yeah writing blocking code is a Bad Thing™ in node.
>
> On Sunday, March 18, 2012 8:23:37 PM UTC-4, Angelo Chen wrote:
>>
>> Hi,
>>
>> got this :
>>
>> function get_next_id() {
>> rclient.incr("next_id", function(err, reply) {
>> return reply
>> });
>> }
>>
>> will call this with:
>>
>> var next_id = get_next_id()
>>
>> this won't work, because function returns even before 'reply' was
>> taken from rclient( a redis), one solution is, passing a call back to
>> the function, is there any other way? thanks.
>>
>> Angelo
>>
>
--
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