Here is an idea of small but useful callback wrapper.
After applying metasync.cb:
no need to check like this: if (callback) return callback(err, data);
wrapper prevents to call it more then once
it may optionally add debugging wraper to trace async code (not for production)
Usage:
const doSomethingAsync = (par1, parN, callback) => {
const cb = metasync.cb(callback); // apply wrapper
// ... some code here ...
// No need to check: if (cb) return ....
cb(err, data); // first call will be passed to callback
return cb(err, data); // second will write warning to console or log
};
Here is an idea of small but useful callback wrapper. After applying
metasync.cb
:if (callback) return callback(err, data)
;