Callbacks & Callback Hell
What callback optimization technique is shown here?
const cache = new Map();
function memoize(fn) {
return function(arg, callback) {
const cached = cache.get(arg);
if (cached) {
return process.nextTick(() => callback(null, cached));
}
fn(arg, (err, result) => {
if (!err) cache.set(arg, result);
callback(err, result);
});
};
}