author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/Async.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/Async.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Async.js | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/frontend/gamma/js/Clipperz/Async.js b/frontend/gamma/js/Clipperz/Async.js index f7a9517..d525453 100644 --- a/frontend/gamma/js/Clipperz/Async.js +++ b/frontend/gamma/js/Clipperz/Async.js | |||
@@ -1,288 +1,278 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | //Clipperz.Async = MochiKit.Async; | 24 | //Clipperz.Async = MochiKit.Async; |
27 | 25 | ||
28 | 26 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 27 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } | 28 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } |
31 | 29 | ||
32 | Clipperz.Async.VERSION = "0.1"; | 30 | Clipperz.Async.VERSION = "0.1"; |
33 | Clipperz.Async.NAME = "Clipperz.Async"; | 31 | Clipperz.Async.NAME = "Clipperz.Async"; |
34 | 32 | ||
35 | Clipperz.Async.Deferred = function(aName, args) { | 33 | Clipperz.Async.Deferred = function(aName, args) { |
36 | args = args || {}; | 34 | args = args || {}; |
37 | 35 | ||
38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); | 36 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); |
39 | 37 | ||
40 | this._args = args; | 38 | this._args = args; |
41 | this._name = aName || "Anonymous deferred"; | 39 | this._name = aName || "Anonymous deferred"; |
42 | this._count = 0; | 40 | this._count = 0; |
43 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); | 41 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); |
44 | this._vars = null; | 42 | this._vars = null; |
45 | 43 | ||
46 | return this; | 44 | return this; |
47 | } | 45 | } |
48 | 46 | ||
49 | //============================================================================= | 47 | //============================================================================= |
50 | 48 | ||
51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { | 49 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { |
52 | 50 | ||
53 | 'name': function () { | 51 | 'name': function () { |
54 | return this._name; | 52 | return this._name; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | 'args': function () { | 55 | 'args': function () { |
58 | return this._args; | 56 | return this._args; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | //----------------------------------------------------------------------------- | 59 | //----------------------------------------------------------------------------- |
62 | 60 | ||
63 | 'callback': function (aValue) { | 61 | 'callback': function (aValue) { |
64 | if (this._shouldTrace) { | 62 | if (this._shouldTrace) { |
65 | //Clipperz.log("CALLBACK " + this._name, aValue); | 63 | Clipperz.log("CALLBACK " + this._name, aValue); |
66 | console.log("CALLBACK " + this._name, aValue); | ||
67 | } | 64 | } |
68 | 65 | ||
69 | if (this.chained == false) { | 66 | if (this.chained == false) { |
70 | var message; | 67 | var message; |
71 | 68 | ||
72 | message = "ERROR [" + this._name + "]"; | 69 | message = "ERROR [" + this._name + "]"; |
73 | this.addErrback(function(aResult) { | 70 | this.addErrback(function(aResult) { |
74 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { | 71 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { |
75 | Clipperz.log(message, aResult); | 72 | Clipperz.log(message, aResult); |
76 | } | 73 | } |
77 | return aResult; | 74 | return aResult; |
78 | }); | 75 | }); |
79 | 76 | ||
80 | if (this._shouldTrace) { | 77 | if (this._shouldTrace) { |
81 | var resultMessage; | 78 | var resultMessage; |
82 | 79 | ||
83 | resultMessage = "RESULT " + this._name + " <=="; | 80 | resultMessage = "RESULT " + this._name + " <=="; |
84 | // this.addCallback(function(aResult) { | 81 | // this.addCallback(function(aResult) { |
85 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { | 82 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { |
86 | //Clipperz.log(resultMessage, aResult); | 83 | Clipperz.log(resultMessage, aResult); |
87 | console.log(resultMessage, aResult); | ||
88 | |||
89 | return aResult; | 84 | return aResult; |
90 | }); | 85 | }); |
91 | } | 86 | } |
92 | } | 87 | } |
93 | 88 | ||
94 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { | 89 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { |
95 | Clipperz.log("callback " + this._name, this); | 90 | Clipperz.log("callback " + this._name, this); |
96 | } | 91 | } |
97 | 92 | ||
98 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); | 93 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); |
99 | }, | 94 | }, |
100 | 95 | ||
101 | //----------------------------------------------------------------------------- | 96 | //----------------------------------------------------------------------------- |
102 | 97 | ||
103 | 'addCallback': function () { | 98 | 'addCallback': function () { |
104 | var message; | 99 | var message; |
105 | 100 | ||
106 | if (this._shouldTrace) { | 101 | if (this._shouldTrace) { |
107 | this._count ++; | 102 | this._count ++; |
108 | message = "[" + this._count + "] " + this._name + " "; | 103 | message = "[" + this._count + "] " + this._name + " "; |
109 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); | 104 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); |
110 | this.addCallbacks( | 105 | this.addCallbacks( |
111 | //function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 106 | function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
112 | function(aResult) {console.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 107 | function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} |
113 | //function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
114 | function(aResult) {console.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
115 | ); | 108 | ); |
116 | } | 109 | } |
117 | 110 | ||
118 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); | 111 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); |
119 | 112 | ||
120 | if (this._shouldTrace) { | 113 | if (this._shouldTrace) { |
121 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); | 114 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); |
122 | this.addCallbacks( | 115 | this.addCallbacks( |
123 | //function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, | 116 | function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, |
124 | function(aResult) {console.log("-OK- " + message + "<--", aResult); return aResult;}, | 117 | function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} |
125 | //function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | ||
126 | function(aResult) {console.log("FAIL " + message + "<--", aResult); return aResult;} | ||
127 | ); | 118 | ); |
128 | } | 119 | } |
129 | }, | 120 | }, |
130 | 121 | ||
131 | //============================================================================= | 122 | //============================================================================= |
132 | 123 | ||
133 | 'addCallbackPass': function() { | 124 | 'addCallbackPass': function() { |
134 | var passFunction; | 125 | var passFunction; |
135 | 126 | ||
136 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 127 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
137 | 128 | ||
138 | this.addCallback(function() { | 129 | this.addCallback(function() { |
139 | var result; | 130 | var result; |
140 | 131 | ||
141 | result = arguments[arguments.length -1]; | 132 | result = arguments[arguments.length -1]; |
142 | passFunction(); | 133 | passFunction(); |
143 | 134 | ||
144 | return result; | 135 | return result; |
145 | }); | 136 | }); |
146 | }, | 137 | }, |
147 | 138 | ||
148 | //----------------------------------------------------------------------------- | 139 | //----------------------------------------------------------------------------- |
149 | 140 | ||
150 | 'addErrbackPass': function() { | 141 | 'addErrbackPass': function() { |
151 | var passFunction; | 142 | var passFunction; |
152 | 143 | ||
153 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 144 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
154 | 145 | ||
155 | this.addErrback(function() { | 146 | this.addErrback(function() { |
156 | var result; | 147 | var result; |
157 | 148 | ||
158 | result = arguments[arguments.length -1]; | 149 | result = arguments[arguments.length -1]; |
159 | passFunction(); | 150 | passFunction(); |
160 | 151 | ||
161 | return result; | 152 | return result; |
162 | }); | 153 | }); |
163 | }, | 154 | }, |
164 | 155 | ||
165 | //----------------------------------------------------------------------------- | 156 | //----------------------------------------------------------------------------- |
166 | 157 | ||
167 | 'addBothPass': function() { | 158 | 'addBothPass': function() { |
168 | var passFunction; | 159 | var passFunction; |
169 | 160 | ||
170 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 161 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
171 | 162 | ||
172 | this.addBoth(function() { | 163 | this.addBoth(function() { |
173 | var result; | 164 | var result; |
174 | 165 | ||
175 | result = arguments[arguments.length -1]; | 166 | result = arguments[arguments.length -1]; |
176 | passFunction(); | 167 | passFunction(); |
177 | 168 | ||
178 | return result; | 169 | return result; |
179 | }); | 170 | }); |
180 | }, | 171 | }, |
181 | 172 | ||
182 | //----------------------------------------------------------------------------- | 173 | //----------------------------------------------------------------------------- |
183 | 174 | ||
184 | 'addIf': function (aThenBlock, anElseBlock) { | 175 | 'addIf': function (aThenBlock, anElseBlock) { |
185 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 176 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
186 | var deferredResult; | 177 | var deferredResult; |
187 | 178 | ||
188 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { | 179 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { |
189 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); | 180 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); |
190 | } else { | 181 | } else { |
191 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); | 182 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); |
192 | } | 183 | } |
193 | 184 | ||
194 | return deferredResult; | 185 | return deferredResult; |
195 | })) | 186 | })) |
196 | }, | 187 | }, |
197 | 188 | ||
198 | //----------------------------------------------------------------------------- | 189 | //----------------------------------------------------------------------------- |
199 | 190 | ||
200 | 'addMethod': function () { | 191 | 'addMethod': function () { |
201 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); | 192 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); |
202 | }, | 193 | }, |
203 | 194 | ||
204 | //----------------------------------------------------------------------------- | 195 | //----------------------------------------------------------------------------- |
205 | 196 | ||
206 | 'addMethodcaller': function () { | 197 | 'addMethodcaller': function () { |
207 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); | 198 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); |
208 | }, | 199 | }, |
209 | 200 | ||
210 | //============================================================================= | 201 | //============================================================================= |
211 | 202 | ||
212 | 'addLog': function (aLog) { | 203 | 'addLog': function (aLog) { |
213 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 204 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
214 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); | 205 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); |
215 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); | ||
216 | } | 206 | } |
217 | }, | 207 | }, |
218 | 208 | ||
219 | //============================================================================= | 209 | //============================================================================= |
220 | 210 | ||
221 | 'acquireLock': function (aLock) { | 211 | 'acquireLock': function (aLock) { |
222 | // this.addCallback(function (aResult) { | 212 | // this.addCallback(function (aResult) { |
223 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ | 213 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ |
224 | // MochiKit.Base.method(aLock, 'acquire'), | 214 | // MochiKit.Base.method(aLock, 'acquire'), |
225 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 215 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
226 | // ], {trace:false}); | 216 | // ], {trace:false}); |
227 | // }); | 217 | // }); |
228 | 218 | ||
229 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); | 219 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); |
230 | }, | 220 | }, |
231 | 221 | ||
232 | 'releaseLock': function (aLock) { | 222 | 'releaseLock': function (aLock) { |
233 | // this.addCallback(function (aResult) { | 223 | // this.addCallback(function (aResult) { |
234 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ | 224 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ |
235 | // MochiKit.Base.method(aLock, 'release'), | 225 | // MochiKit.Base.method(aLock, 'release'), |
236 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 226 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
237 | // ], {trace:false}); | 227 | // ], {trace:false}); |
238 | // }); | 228 | // }); |
239 | // this.addErrback(function (aResult) { | 229 | // this.addErrback(function (aResult) { |
240 | ///console.log("releaseLock.addErrback:", aResult); | 230 | ///Clipperz.log("releaseLock.addErrback:", aResult); |
241 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ | 231 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ |
242 | // MochiKit.Base.method(aLock, 'release'), | 232 | // MochiKit.Base.method(aLock, 'release'), |
243 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) | 233 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) |
244 | // ], {trace:false}); | 234 | // ], {trace:false}); |
245 | // }); | 235 | // }); |
246 | 236 | ||
247 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); | 237 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); |
248 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); | 238 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); |
249 | this.addErrback(function (anError) { | 239 | this.addErrback(function (anError) { |
250 | aLock.release(); | 240 | aLock.release(); |
251 | 241 | ||
252 | return anError; | 242 | return anError; |
253 | }); | 243 | }); |
254 | }, | 244 | }, |
255 | 245 | ||
256 | //============================================================================= | 246 | //============================================================================= |
257 | 247 | ||
258 | 'collectResults': function (someRequests) { | 248 | 'collectResults': function (someRequests) { |
259 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); | 249 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); |
260 | }, | 250 | }, |
261 | 251 | ||
262 | 'addCallbackList': function (aRequestList) { | 252 | 'addCallbackList': function (aRequestList) { |
263 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); | 253 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); |
264 | }, | 254 | }, |
265 | 255 | ||
266 | //============================================================================= | 256 | //============================================================================= |
267 | 257 | ||
268 | 'vars': function () { | 258 | 'vars': function () { |
269 | if (this._vars == null) { | 259 | if (this._vars == null) { |
270 | this._vars = {} | 260 | this._vars = {} |
271 | } | 261 | } |
272 | 262 | ||
273 | return this._vars; | 263 | return this._vars; |
274 | }, | 264 | }, |
275 | 265 | ||
276 | 'setValue': function (aKey) { | 266 | 'setValue': function (aKey) { |
277 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 267 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
278 | this.vars()[aKey] = aValue; | 268 | this.vars()[aKey] = aValue; |
279 | return aValue; | 269 | return aValue; |
280 | }, this)); | 270 | }, this)); |
281 | }, | 271 | }, |
282 | 272 | ||
283 | 'getValue': function (aKey) { | 273 | 'getValue': function (aKey) { |
284 | this.addCallback(MochiKit.Base.bind(function () { | 274 | this.addCallback(MochiKit.Base.bind(function () { |
285 | return this.vars()[aKey]; | 275 | return this.vars()[aKey]; |
286 | }, this)); | 276 | }, this)); |
287 | }, | 277 | }, |
288 | 278 | ||
@@ -332,97 +322,97 @@ MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { | |||
332 | 322 | ||
333 | //----------------------------------------------------------------------------- | 323 | //----------------------------------------------------------------------------- |
334 | 324 | ||
335 | 'name': function() { | 325 | 'name': function() { |
336 | return this._name; | 326 | return this._name; |
337 | }, | 327 | }, |
338 | 328 | ||
339 | //----------------------------------------------------------------------------- | 329 | //----------------------------------------------------------------------------- |
340 | 330 | ||
341 | 'methods': function() { | 331 | 'methods': function() { |
342 | return this._methods; | 332 | return this._methods; |
343 | }, | 333 | }, |
344 | 334 | ||
345 | 'methodResults': function() { | 335 | 'methodResults': function() { |
346 | return this._methodResults; | 336 | return this._methodResults; |
347 | }, | 337 | }, |
348 | 338 | ||
349 | //----------------------------------------------------------------------------- | 339 | //----------------------------------------------------------------------------- |
350 | 340 | ||
351 | 'result': function() { | 341 | 'result': function() { |
352 | return this._result; | 342 | return this._result; |
353 | }, | 343 | }, |
354 | 344 | ||
355 | //----------------------------------------------------------------------------- | 345 | //----------------------------------------------------------------------------- |
356 | 346 | ||
357 | 'numberOfMethodsDone':function() { | 347 | 'numberOfMethodsDone':function() { |
358 | return this._numberOfMethodsDone; | 348 | return this._numberOfMethodsDone; |
359 | }, | 349 | }, |
360 | 350 | ||
361 | 'incrementNumberOfMethodsDone': function() { | 351 | 'incrementNumberOfMethodsDone': function() { |
362 | this._numberOfMethodsDone ++; | 352 | this._numberOfMethodsDone ++; |
363 | }, | 353 | }, |
364 | 354 | ||
365 | //----------------------------------------------------------------------------- | 355 | //----------------------------------------------------------------------------- |
366 | 356 | ||
367 | 'run': function(args, aValue) { | 357 | 'run': function(args, aValue) { |
368 | var deferredResults; | 358 | var deferredResults; |
369 | var i, c; | 359 | var i, c; |
370 | 360 | ||
371 | deferredResults = []; | 361 | deferredResults = []; |
372 | args = args || {}; | 362 | args = args || {}; |
373 | 363 | ||
374 | c = this.methods().length; | 364 | c = this.methods().length; |
375 | for (i=0; i<c; i++) { | 365 | for (i=0; i<c; i++) { |
376 | var deferredResult; | 366 | var deferredResult; |
377 | varmethodCalls; | 367 | varmethodCalls; |
378 | var ii, cc; | 368 | var ii, cc; |
379 | 369 | ||
380 | //console.log("TYPEOF", typeof(this.methods()[i])); | 370 | //Clipperz.log("TYPEOF", typeof(this.methods()[i])); |
381 | if (typeof(this.methods()[i]) == 'function') { | 371 | if (typeof(this.methods()[i]) == 'function') { |
382 | methodCalls = [ this.methods()[i] ]; | 372 | methodCalls = [ this.methods()[i] ]; |
383 | } else { | 373 | } else { |
384 | methodCalls = this.methods()[i]; | 374 | methodCalls = this.methods()[i]; |
385 | } | 375 | } |
386 | 376 | ||
387 | cc = methodCalls.length; | 377 | cc = methodCalls.length; |
388 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); | 378 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); |
389 | for (ii=0; ii<cc; ii++) { | 379 | for (ii=0; ii<cc; ii++) { |
390 | deferredResult.addCallback(methodCalls[ii]); | 380 | deferredResult.addCallback(methodCalls[ii]); |
391 | } | 381 | } |
392 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); | 382 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); |
393 | 383 | ||
394 | deferredResults.push(deferredResult); | 384 | deferredResults.push(deferredResult); |
395 | } | 385 | } |
396 | 386 | ||
397 | for (i=0; i<c; i++) { | 387 | for (i=0; i<c; i++) { |
398 | deferredResults[i].callback(aValue); | 388 | deferredResults[i].callback(aValue); |
399 | } | 389 | } |
400 | 390 | ||
401 | return this.result(); | 391 | return this.result(); |
402 | }, | 392 | }, |
403 | 393 | ||
404 | //----------------------------------------------------------------------------- | 394 | //----------------------------------------------------------------------------- |
405 | 395 | ||
406 | 'handleMethodCallDone': function(anIndexValue, aResult) { | 396 | 'handleMethodCallDone': function(anIndexValue, aResult) { |
407 | this.incrementNumberOfMethodsDone(); | 397 | this.incrementNumberOfMethodsDone(); |
408 | this.methodResults()[anIndexValue] = aResult; | 398 | this.methodResults()[anIndexValue] = aResult; |
409 | 399 | ||
410 | if (this.numberOfMethodsDone() < this.methods().length) { | 400 | if (this.numberOfMethodsDone() < this.methods().length) { |
411 | //nothing to do here other than possibly log something | 401 | //nothing to do here other than possibly log something |
412 | } else if (this.numberOfMethodsDone() == this.methods().length) { | 402 | } else if (this.numberOfMethodsDone() == this.methods().length) { |
413 | this.result().callback(); | 403 | this.result().callback(); |
414 | } else if (this.numberOfMethodsDone() > this.methods().length) { | 404 | } else if (this.numberOfMethodsDone() > this.methods().length) { |
415 | alert("Clipperz.Async.Deferred.handleMethodCallDone -> WTF!"); | 405 | alert("Clipperz.Async.Deferred.handleMethodCallDone -> WTF!"); |
416 | //WTF!!! :( | 406 | //WTF!!! :( |
417 | } | 407 | } |
418 | 408 | ||
419 | }, | 409 | }, |
420 | 410 | ||
421 | //----------------------------------------------------------------------------- | 411 | //----------------------------------------------------------------------------- |
422 | 412 | ||
423 | __syntaxFix__: "syntax fix" | 413 | __syntaxFix__: "syntax fix" |
424 | }); | 414 | }); |
425 | 415 | ||
426 | //############################################################################# | 416 | //############################################################################# |
427 | 417 | ||
428 | MochiKit.Base.update(Clipperz.Async, { | 418 | MochiKit.Base.update(Clipperz.Async, { |
@@ -592,120 +582,120 @@ MochiKit.Base.update(Clipperz.Async, { | |||
592 | return deferredResult; | 582 | return deferredResult; |
593 | }, | 583 | }, |
594 | 584 | ||
595 | //------------------------------------------------------------------------- | 585 | //------------------------------------------------------------------------- |
596 | 586 | ||
597 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { | 587 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { |
598 | var deferredResult; | 588 | var deferredResult; |
599 | var i, c; | 589 | var i, c; |
600 | 590 | ||
601 | if (aSortedResult.length == 0) { | 591 | if (aSortedResult.length == 0) { |
602 | deferredResult = MochiKit.Async.succeed([anObject]); | 592 | deferredResult = MochiKit.Async.succeed([anObject]); |
603 | } else { | 593 | } else { |
604 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); | 594 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); |
605 | c = aSortedResult.length + 1; | 595 | c = aSortedResult.length + 1; |
606 | for (i=0; i<c; i++) { | 596 | for (i=0; i<c; i++) { |
607 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { | 597 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { |
608 | var innerDeferredResult; | 598 | var innerDeferredResult; |
609 | 599 | ||
610 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); | 600 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); |
611 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); | 601 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); |
612 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); | 602 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); |
613 | innerDeferredResult.callback(); | 603 | innerDeferredResult.callback(); |
614 | 604 | ||
615 | return innerDeferredResult; | 605 | return innerDeferredResult; |
616 | }, aDeferredComparator, anObject, aSortedResult[i], i); | 606 | }, aDeferredComparator, anObject, aSortedResult[i], i); |
617 | } | 607 | } |
618 | deferredResult.addMethod(aSortedResult, 'push', anObject); | 608 | deferredResult.addMethod(aSortedResult, 'push', anObject); |
619 | deferredResult.addErrback(function (anError) { | 609 | deferredResult.addErrback(function (anError) { |
620 | aSortedResult.splice(anError.message, 0, anObject); | 610 | aSortedResult.splice(anError.message, 0, anObject); |
621 | }) | 611 | }) |
622 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); | 612 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); |
623 | deferredResult.callback(); | 613 | deferredResult.callback(); |
624 | } | 614 | } |
625 | 615 | ||
626 | return deferredResult; | 616 | return deferredResult; |
627 | }, | 617 | }, |
628 | 618 | ||
629 | //------------------------------------------------------------------------- | 619 | //------------------------------------------------------------------------- |
630 | 620 | ||
631 | 'deferredSort': function (aDeferredComparator, someObjects) { | 621 | 'deferredSort': function (aDeferredComparator, someObjects) { |
632 | var deferredResult; | 622 | var deferredResult; |
633 | var i, c; | 623 | var i, c; |
634 | 624 | ||
635 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); | 625 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); |
636 | c = someObjects.length; | 626 | c = someObjects.length; |
637 | for (i=0; i<c; i++) { | 627 | for (i=0; i<c; i++) { |
638 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); | 628 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); |
639 | if ((i % 50) == 0) { | 629 | if ((i % 50) == 0) { |
640 | //console.log("######### sort wait ##########"); | 630 | //Clipperz.log("######### sort wait ##########"); |
641 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); | 631 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); |
642 | } | 632 | } |
643 | } | 633 | } |
644 | deferredResult.callback([]); | 634 | deferredResult.callback([]); |
645 | 635 | ||
646 | return deferredResult; | 636 | return deferredResult; |
647 | }, | 637 | }, |
648 | 638 | ||
649 | //========================================================================= | 639 | //========================================================================= |
650 | 640 | ||
651 | 'deferredFilter': function (aFunction, someObjects) { | 641 | 'deferredFilter': function (aFunction, someObjects) { |
652 | vardeferredResult; | 642 | vardeferredResult; |
653 | vari, c; | 643 | vari, c; |
654 | 644 | ||
655 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); | 645 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); |
656 | c = someObjects.length; | 646 | c = someObjects.length; |
657 | for (i=0; i<c; i++) { | 647 | for (i=0; i<c; i++) { |
658 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { | 648 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { |
659 | var innerDeferredResult; | 649 | var innerDeferredResult; |
660 | 650 | ||
661 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); | 651 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); |
662 | innerDeferredResult.addCallback(aFunction, anObject); | 652 | innerDeferredResult.addCallback(aFunction, anObject); |
663 | innerDeferredResult.addCallback(function (aFilterResult) { | 653 | innerDeferredResult.addCallback(function (aFilterResult) { |
664 | if (aFilterResult) { | 654 | if (aFilterResult) { |
665 | aResult.push(anObject); | 655 | aResult.push(anObject); |
666 | }; | 656 | }; |
667 | }); | 657 | }); |
668 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); | 658 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); |
669 | innerDeferredResult.callback(); | 659 | innerDeferredResult.callback(); |
670 | 660 | ||
671 | return innerDeferredResult; | 661 | return innerDeferredResult; |
672 | }, aFunction, someObjects[i], i); | 662 | }, aFunction, someObjects[i], i); |
673 | } | 663 | } |
674 | deferredResult.callback([]); | 664 | deferredResult.callback([]); |
675 | 665 | ||
676 | return deferredResult; | 666 | return deferredResult; |
677 | }, | 667 | }, |
678 | 668 | ||
679 | 'forEach': function (aFunction) { | 669 | 'forEach': function (aFunction) { |
680 | return MochiKit.Base.partial(function (aFunction, anIterable) { | 670 | return MochiKit.Base.partial(function (aFunction, anIterable) { |
681 | MochiKit.Iter.forEach(anIterable, aFunction); | 671 | MochiKit.Iter.forEach(anIterable, aFunction); |
682 | }, aFunction); | 672 | }, aFunction); |
683 | }, | 673 | }, |
684 | 674 | ||
685 | //========================================================================= | 675 | //========================================================================= |
686 | 676 | ||
687 | 'or': function (someValues) { | 677 | 'or': function (someValues) { |
688 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ | 678 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ |
689 | MochiKit.Base.values, | 679 | MochiKit.Base.values, |
690 | MochiKit.Base.flattenArguments, | 680 | MochiKit.Base.flattenArguments, |
691 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, | 681 | //function (aValue) { Clipperz.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, |
692 | function(someInnerValues) { | 682 | function(someInnerValues) { |
693 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); | 683 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); |
694 | } | 684 | } |
695 | ], {trace:false}, someValues); | 685 | ], {trace:false}, someValues); |
696 | }, | 686 | }, |
697 | 687 | ||
698 | //========================================================================= | 688 | //========================================================================= |
699 | 689 | ||
700 | 'clearResult': function () {}, | 690 | 'clearResult': function () {}, |
701 | 691 | ||
702 | //========================================================================= | 692 | //========================================================================= |
703 | __syntaxFix__: "syntax fix" | 693 | __syntaxFix__: "syntax fix" |
704 | }); | 694 | }); |
705 | 695 | ||
706 | 696 | ||
707 | //############################################################################# | 697 | //############################################################################# |
708 | 698 | ||
709 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; | 699 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; |
710 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; | 700 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; |
711 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; | 701 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; |