Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Multiple callbacks in same async function?

Multiple callbacks in same async function?

Problem

If you have more than one Callback in an asynchronous Function, will it exit the function on the first execution of a callback, similar to a return statement, or will it continue on?

function handler(conn, callback){

    if (conn === true){
        callback('found');
    }

    callback('not found');

});
Problem courtesy of: gjw80

Solution

Yes, it will continue on, unless you return callback()

Solution courtesy of: thiago.lenz

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Multiple callbacks in same async function?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×