I'm struggling to find a solution for this problem. The use case is as follow:
Say for example the function is:
function retrieveResource(resourceId, callback) {
extLib.getResource(resourceId, function (err, data) {
callback(err, data);
};
};
So when multiple "caller" are calling retrieveResource functions, often they have the same resourceId. When this happen within say 1 second interval, I just want to have 1 call to extLib.getResource executed and the rest will just use the same value as the first function call.
Using cache doesn't quite work out here because the function is called roughly at the same time, they all check the cache roughly at the same time and the cache is empty at that point.
I looked at _.debounce, _.throttle and they are not what I'm looking for since debounce is executing just one function and throttle is still executing all functions.
Any ideas?