Node.jsasync.js

Syntax

  • Each callback must be written with this syntax:

  • function callback(err, result [, arg1[, ...]])

  • This way, you are forced to return the error first, and can't ignore handling them later on. null is the convention in absence of errors

  • callback(null, myResult);

  • Your callbacks can contain more arguments than err and result, but it's useful only for a specific set of functions (waterfall, seq, ...)

  • callback(null, myResult, myCustomArgument);

  • And, of course, send errors. You must do it, and handle errors (or at least log them).

  • callback(err);

Related Examples

async.each(To handle array of data efficiently)