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