OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Timer heap implemented as a array-based binary heap[0]. | 5 // Timer heap implemented as a array-based binary heap[0]. |
6 // This allows for O(1) `first`, O(log(n)) `remove`/`removeFirst` and O(log(n)) | 6 // This allows for O(1) `first`, O(log(n)) `remove`/`removeFirst` and O(log(n)) |
7 // `add`. | 7 // `add`. |
8 // | 8 // |
9 // To ensure the timers are ordered by insertion time, the _Timer class has a | 9 // To ensure the timers are ordered by insertion time, the _Timer class has a |
10 // `_id` field set when added to the heap. | 10 // `_id` field set when added to the heap. |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Mark timer as inactive. | 389 // Mark timer as inactive. |
390 timer._callback = null; | 390 timer._callback = null; |
391 } | 391 } |
392 callback(timer); | 392 callback(timer); |
393 // Re-insert repeating timer if not canceled. | 393 // Re-insert repeating timer if not canceled. |
394 if (timer._repeating && (timer._callback != null)) { | 394 if (timer._repeating && (timer._callback != null)) { |
395 timer._advanceWakeupTime(); | 395 timer._advanceWakeupTime(); |
396 timer._addTimerToHeap(); | 396 timer._addTimerToHeap(); |
397 } | 397 } |
398 // Execute pending micro tasks. | 398 // Execute pending micro tasks. |
399 _runPendingImmediateCallback(); | 399 var immediateCallback = _removePendingImmediateCallback(); |
| 400 if (immediateCallback != null) { |
| 401 immediateCallback(); |
| 402 } |
400 } | 403 } |
401 } | 404 } |
402 } finally { | 405 } finally { |
403 _handlingCallbacks = false; | 406 _handlingCallbacks = false; |
404 _notifyEventHandler(); | 407 _notifyEventHandler(); |
405 } | 408 } |
406 } | 409 } |
407 | 410 |
408 // Creates a receive port and registers an empty handler on that port. Just | 411 // Creates a receive port and registers an empty handler on that port. Just |
409 // the triggering of the event loop will ensure that timers are executed. | 412 // the triggering of the event loop will ensure that timers are executed. |
(...skipping 24 matching lines...) Expand all Loading... |
434 if (repeating) { | 437 if (repeating) { |
435 return new _Timer.periodic(milliSeconds, callback); | 438 return new _Timer.periodic(milliSeconds, callback); |
436 } | 439 } |
437 return new _Timer(milliSeconds, callback); | 440 return new _Timer(milliSeconds, callback); |
438 } | 441 } |
439 } | 442 } |
440 | 443 |
441 _setupHooks() { | 444 _setupHooks() { |
442 VMLibraryHooks.timerFactory = _Timer._factory; | 445 VMLibraryHooks.timerFactory = _Timer._factory; |
443 } | 446 } |
OLD | NEW |