Created
April 9, 2015 13:04
-
-
Save gkucmierz/d5646a6639e66bce438d to your computer and use it in GitHub Desktop.
AsyncMemory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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