Ox.Request: if data is in cache, don't fail if it gets removed before timeout

This commit is contained in:
rlx 2014-09-26 11:57:50 +02:00
parent 5424023903
commit c69858ca2d

View file

@ -106,7 +106,8 @@ Ox.Request = (function() {
@*/
send: function(options) {
var options = Ox.extend({
var data,
options = Ox.extend({
age: -1,
callback: null,
id: Ox.uid(),
@ -122,7 +123,7 @@ Ox.Request = (function() {
if (pending[options.id]) {
setTimeout(function() {
Ox.Request.send(options);
}, 0);
});
} else {
requests[options.id] = {
url: options.url,
@ -132,8 +133,9 @@ Ox.Request = (function() {
options.age == -1
|| options.age > +new Date() - cache[req].time
)) {
data = cache[req].data;
setTimeout(function() {
callback(cache[req].data, true);
callback(data, true);
});
} else {
pending[options.id] = true;