Ox.cache async should call callback always async

This commit is contained in:
j 2013-07-09 14:29:14 +00:00
parent c7eaee0794
commit 807844c836

View file

@ -2,6 +2,10 @@
/*@
Ox.cache <f> Memoize a function
fn <f> function
options <o>
async <b|false> function is async, last argument must be callback
key <f|JSON.stringify> return key for arguments
<script>
Ox.test.fn = Ox.cache(function(n) { return n * Math.random(); });
</script>
@ -31,7 +35,9 @@ Ox.cache = function(fn, options) {
fn.apply(this, args.slice(0, -1).concat(callback));
} else {
// call callback with cached arguments
callback.apply(this, cache[key])
setTimeout(function() {
callback.apply(this, cache[key]);
});
}
} else {
if (!(key in cache)) {