laps does not require anything from you. You can use it internally, you can return it as a result (promise-like), or you can use it eventually to reorganize some part of code.
It can work with any asynchronous API, and you do not need to wrap API method, you can wrap the callback.
The main thing you need to know: every lap is asynchronous internally but the sequence of laps will be executed synchronously. The next lap won't be started until the completion of all asynchronous callbacks of the previous lap.
Every wrapped callback become the command and you can also create and execute the commands manually. In addition, you can subscribe to events: start of the execution, finish of the execution, begin of the lap, end of the lap, error.
Examples
Synchronous
It is often necessary to organize the sequence of asynchronous calls in a chain.
Consider this example:
var dns =require('dns');
var count =0;
var handler =null;
varcallback=function(){
if(--count <=0&& handler){
count =0;
handler();
}
};
varerror=function(err){
console.log('Error: '+err.message);
callback();
};
varreverse=function(type,adr){
returnfunction(err,data){
if(err)returnerror(err);
console.log(type +', reverse for '+ adr +': '+JSON.stringify(data));