OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:_internal' hide Symbol; | 5 import 'dart:_internal' hide Symbol; |
6 | 6 |
7 @patch | 7 @patch class Timer { |
8 class Timer { | 8 @patch static Timer _createTimer(Duration duration, void callback()) { |
9 @patch | |
10 static Timer _createTimer(Duration duration, void callback()) { | |
11 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. | 9 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. |
12 if (_TimerFactory._factory == null) { | 10 if (_TimerFactory._factory == null) { |
13 _TimerFactory._factory = VMLibraryHooks.timerFactory; | 11 _TimerFactory._factory = VMLibraryHooks.timerFactory; |
14 } | 12 } |
15 if (_TimerFactory._factory == null) { | 13 if (_TimerFactory._factory == null) { |
16 throw new UnsupportedError("Timer interface not supported."); | 14 throw new UnsupportedError("Timer interface not supported."); |
17 } | 15 } |
18 int milliseconds = duration.inMilliseconds; | 16 int milliseconds = duration.inMilliseconds; |
19 if (milliseconds < 0) milliseconds = 0; | 17 if (milliseconds < 0) milliseconds = 0; |
20 return _TimerFactory._factory(milliseconds, (_) { | 18 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); |
21 callback(); | |
22 }, false); | |
23 } | 19 } |
24 | 20 |
25 @patch | 21 @patch static Timer _createPeriodicTimer(Duration duration, |
26 static Timer _createPeriodicTimer( | 22 void callback(Timer timer)) { |
27 Duration duration, void callback(Timer timer)) { | |
28 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. | 23 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. |
29 if (_TimerFactory._factory == null) { | 24 if (_TimerFactory._factory == null) { |
30 _TimerFactory._factory = VMLibraryHooks.timerFactory; | 25 _TimerFactory._factory = VMLibraryHooks.timerFactory; |
31 } | 26 } |
32 if (_TimerFactory._factory == null) { | 27 if (_TimerFactory._factory == null) { |
33 throw new UnsupportedError("Timer interface not supported."); | 28 throw new UnsupportedError("Timer interface not supported."); |
34 } | 29 } |
35 int milliseconds = duration.inMilliseconds; | 30 int milliseconds = duration.inMilliseconds; |
36 if (milliseconds < 0) milliseconds = 0; | 31 if (milliseconds < 0) milliseconds = 0; |
37 return _TimerFactory._factory(milliseconds, callback, true); | 32 return _TimerFactory._factory(milliseconds, callback, true); |
38 } | 33 } |
39 } | 34 } |
40 | 35 |
41 typedef Timer _TimerFactoryClosure( | 36 typedef Timer _TimerFactoryClosure(int milliseconds, |
42 int milliseconds, void callback(Timer timer), bool repeating); | 37 void callback(Timer timer), |
| 38 bool repeating); |
43 | 39 |
44 // Warning: Dartium sets _TimerFactory._factory instead of setting things up | 40 // Warning: Dartium sets _TimerFactory._factory instead of setting things up |
45 // through VMLibraryHooks.timerFactory. | 41 // through VMLibraryHooks.timerFactory. |
46 class _TimerFactory { | 42 class _TimerFactory { |
47 static _TimerFactoryClosure _factory; | 43 static _TimerFactoryClosure _factory; |
48 } | 44 } |
OLD | NEW |