PageSourceSearch

https://www.iweathernet.com/js/common/deferreds.js

js iweathernet.com collected 2026-10-02 06:43:33 UTC 2,508 bytes, 112 lines download raw bytes

1//deferreds
2
3
4/*
51. Need timer to auto reject after a period
62. if timer is zero or not defined, no autojreject
73. creation adds deferred to array 
84. require a decription
95. allow for querying of unresolved items
106. allow for date/time of resolution to be stored (log)
117. use same method names as jQuery so that we don't have to change resolution code.
12
13
14
15*/
16
17(function(){
18var allDeferreds=[];
19var begintime=new Date();
20
21function deferred(description,timeoutSeconds){
22	this._deferred=jQuery.Deferred();
23	this._deferred.methods=this;
24	this._active=true;
25	this._time=0;
26	this._status="active";
27	this._description=description?description:"";
28	this._timeout=timeoutSeconds?timeoutSeconds*1000:0;
29	var internalDeferred=this;
30	if (this._timeout>0){
31		this._autoRejectTimer=window.setTimeout(function(){
32			internalDeferred._active=false;
33			internalDeferred._status="timeout";
34			jQuery("body").append(internalDeferred._description + " Failed to load");
35			//internalDeferred._deferred.reject();
36			internalDeferred._deferred.resolve();
37			
38		},this._timeout);
39	}
40
41	this._deferred.done(function(){
42		//set what happens if the deferred is resolved
43		internalDeferred._active=false;
44		if (internalDeferred._autoRejectTimer){
45			//turn off the autoreject timer
46			window.clearTimeout(internalDeferred._autoRejectTimer);
47		}
48		internalDeferred._status="resolved";
49		var completetime=new Date();
50		internalDeferred._time=(completetime-begintime)/1000;
51		
52	});
53
54	
55	this._deferred.fail(function(){
56		//set what happens if the deferred is resolved
57		internalDeferred._active=false;
58		if (internalDeferred._autoRejectTimer){
59			//turn off the autoreject timer
60			window.clearTimeout(internalDeferred._autoRejectTimer);
61		}
62		internalDeferred._status=="timeout"?internalDeferred._status="timeout":internalDeferred._status="fail";
63		var completetime=new Date();
64		internalDeferred._time=(completetime-begintime)/1000;
65
66		console.dir(internalDeferred);
67	});
68
69	allDeferreds.push(this);
70	
71	return this._deferred;
72}
73
74
75deferred.prototype={
76	all:function(){
77		//spit out the entire array
78		console.dir(allDeferreds)
79		
80	},
81	showActive:function(){
82		var output=[];
83		jQuery.each(allDeferreds,function(x,item){
84		
85			if (item._active){output.push(item)}
86			
87		})
88		console.dir(output);
89	},
90	showTimings:function(){
91		var output=[];
92		jQuery.each(allDeferreds,function(x,item){
93		
94			console.log(item._description,item._time,item._status);
95			
96		})
97		console.dir(output);
98		
99		
100		
101	}
102	
103	
104}
105
106
107iWeatherNet.deferred=deferred;
108
109
110})();
111
112

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.