In loopback documentation what does variable 'cb' stands for?
Asked Answered
N

1

2

Look at the loopback code in their documentation http://docs.strongloop.com/display/public/LB/Defining+and+using+roles, what I am trying to understand since start is 'cb'. I understand it is some kind of callback but why it is all round the place? Does it have to do anything with Async.js??

Niemann answered 19/6, 2015 at 11:21 Comment(0)
G
4

It has to do with the way node works asynchronously. It uses an 'event loop' that passes off other i/o functions to a background worker thread. When the background work completes the event loop receives a callback. There's a good discussion of this here: Why is node.js asynchronous?

Node libraries that call on expensive resources follow this model to gain performance.

The callback is a function you pass into the library function which is executed when that function completes its processing. It's often anonymous.

The convention is to have this function accept an error parameter as the first argument and results as subsequent ones. You'll see this pattern everywhere:

lib.somfunc( 'argument', function(err, res){

    if(err)....

}); 

Async.js is something a bit different. It's a library that provides various means for orchestrating asynchronous code that uses callbacks.

Grieco answered 19/6, 2015 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.