I do it during the err check because it's more readable. And I assume 
everyone else is doing it for the same reason?

function somethingAsync(data, callback) {
  otherthigAsync(function(err, result) {
    if (err) return callback(err);

    // do something with result
  });
});

On Tuesday, April 10, 2012 4:17:27 PM UTC-7, Ken wrote:
>
> Assuming that the callback doesn't return a value, does v8 behave any 
> differently when invoking callbacks in one of these forms vs. the other?  I 
> find the first approach to be a convenient shorthand in many cases, but am 
> wondering (after observing some unexpected timings when profiling async 
> methods) if it leads to v8 doing something odd with the stack.
>
> Approach A, return the invoked callback:
>
> function foo(a, callback) {
>   var bar = ...; 
>   return callback(bar);
> }
>
> foo("derp", function(b) { ...; return; });
>
> Approach B, invoke callback, then return:
>
> function foo(a, callback) {
>    var bar = ...;
>    callback(bar);
>    return;
> }
>
> foo("derp", function(b) { ...; return; });
>

-- 
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

Reply via email to