|
262 | 262 | var newResult = {}, |
263 | 263 | nEventsDone = 0, |
264 | 264 | nEvents = 0, |
| 265 | + recordResult = function( key, event, result ) { |
| 266 | + // Record the result |
| 267 | + newResult[ key ] = $.extend( {}, event, result ); |
| 268 | + // Increment the number of received responses |
| 269 | + nEventsDone++; |
| 270 | + if ( nEventsDone === nEvents ) { |
| 271 | + // clear the timeout and move on to the next step when all events have been received |
| 272 | + if ( warnTimer ) { |
| 273 | + clearTimeout( warnTimer ); |
| 274 | + } |
| 275 | + setTimeout( function() { |
| 276 | + self.detailedEventCascade( seq, newResult ); |
| 277 | + }, 0); |
| 278 | + } |
| 279 | + }, |
265 | 280 | // set a failsafe timer in case one of the events never happens |
266 | 281 | warnTimer = setTimeout( function() { |
| 282 | + warnTimer = 0; |
267 | 283 | $.each( events, function( key, event ) { |
268 | | - if ( newResult[ key ] === undefined ) { |
| 284 | + // Timeouts are left out of this, because they will complete for |
| 285 | + // sure, calling recordResult when they do |
| 286 | + if ( newResult[ key ] === undefined && event.src ) { |
269 | 287 | // clean up the unused handler |
270 | 288 | derefSrc( event.src ).unbind( event.event ); |
271 | | - newResult[ key ] = $.extend( {}, event, { timedOut: true } ); |
| 289 | + recordResult( key, event, { timedOut: true } ); |
272 | 290 | } |
273 | 291 | }); |
274 | | - |
275 | | - // Move on to the next step |
276 | | - self.detailedEventCascade( seq, newResult ); |
277 | 292 | }, 20000); |
278 | 293 |
|
279 | | - function recordResult( key, event, result ) { |
280 | | - // Record the result |
281 | | - newResult[ key ] = $.extend( {}, event, result ); |
282 | | - // Increment the number of received responses |
283 | | - nEventsDone++; |
284 | | - if ( nEventsDone === nEvents ) { |
285 | | - // clear the timeout and move on to the next step when all events have been received |
286 | | - clearTimeout( warnTimer ); |
287 | | - setTimeout( function() { |
288 | | - self.detailedEventCascade( seq, newResult ); |
289 | | - }, 0); |
290 | | - } |
291 | | - } |
292 | | - |
293 | 294 | $.each( events, function( key, event ) { |
294 | 295 | // Count the events so that we may know how many responses to expect |
295 | 296 | nEvents++; |
|
0 commit comments