Ox.cache async should call callback always async
This commit is contained in:
parent
c7eaee0794
commit
807844c836
1 changed files with 7 additions and 1 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.cache <f> Memoize a function
|
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>
|
<script>
|
||||||
Ox.test.fn = Ox.cache(function(n) { return n * Math.random(); });
|
Ox.test.fn = Ox.cache(function(n) { return n * Math.random(); });
|
||||||
</script>
|
</script>
|
||||||
|
@ -31,7 +35,9 @@ Ox.cache = function(fn, options) {
|
||||||
fn.apply(this, args.slice(0, -1).concat(callback));
|
fn.apply(this, args.slice(0, -1).concat(callback));
|
||||||
} else {
|
} else {
|
||||||
// call callback with cached arguments
|
// call callback with cached arguments
|
||||||
callback.apply(this, cache[key])
|
setTimeout(function() {
|
||||||
|
callback.apply(this, cache[key]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(key in cache)) {
|
if (!(key in cache)) {
|
||||||
|
|
Loading…
Reference in a new issue