// We return a cancel function that aborts the XHR
returnfunction(){
jqXHR.abort();
};
})
.j(function(){
// Since this represents the Juggle instance we can call
// methods like .cancel() from in here.
// .cancel() will call all returned functions from .j()
// callbacks
this.cancel();
})
.fail(function(err){
throw err;
});
Using .timeout()
(newJuggle)
.j(function(complete){
setTimeout(function(){
complete('This will never get recorded');
},30*1000);
})
.timeout(10*1000,function(){
throw'Timed out mofo';
});
Also just like .cancel(), when a Juggle times out all returned
functions will be called. Here is the same example as above
but utilising a cancel function.
(newJuggle)
.j(function(complete){
var t =setTimeout(function(){
complete('This will never get recorded');
},30*1000);
returnfunction(){
clearTimeout(t);
};
})
.timeout(10*1000,function(){
throw'Timed out mofo';
});
Using Juggle to load JS in parallel
functionasyncJS(src,callback){
returnfunction(complete){
var firstScript = s =document.getElementsByTagName('script')[0],