Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created April 9, 2015 13:04
Show Gist options
  • Save gkucmierz/d5646a6639e66bce438d to your computer and use it in GitHub Desktop.
Save gkucmierz/d5646a6639e66bce438d to your computer and use it in GitHub Desktop.
AsyncMemory
this.AsyncMemory = function () {
var memory;
var tid;
var cleanNextTick = function () {
clearInterval(tid);
tid = setTimeout(function () {
memory = undefined;
});
};
return {
evaluate: function (getValueFn) {
if (memory === undefined) {
memory = getValueFn();
cleanNextTick();
}
return memory;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment