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 abstract class Timer { | 5 abstract class Timer { |
6 /** | 6 /** |
7 * Creates a new timer. The [callback] callback is invoked after | 7 * Creates a new timer. The [callback] callback is invoked after |
8 * [milliSeconds] milliseconds. | 8 * [milliSeconds] milliseconds. |
9 */ | 9 */ |
10 factory Timer(int milliSeconds, void callback(Timer timer)) { | 10 factory Timer(int milliSeconds, void callback(Timer timer)) { |
11 if (_TimerFactory._factory == null) { | 11 if (_TimerFactory._factory == null) { |
12 throw new UnsupportedOperationException("Timer interface not supported."); | 12 throw new UnsupportedError("Timer interface not supported."); |
13 } | 13 } |
14 return _TimerFactory._factory(milliSeconds, callback, false); | 14 return _TimerFactory._factory(milliSeconds, callback, false); |
15 } | 15 } |
16 | 16 |
17 /** | 17 /** |
18 * Creates a new repeating timer. The [callback] is invoked every | 18 * Creates a new repeating timer. The [callback] is invoked every |
19 * [milliSeconds] millisecond until cancelled. | 19 * [milliSeconds] millisecond until cancelled. |
20 */ | 20 */ |
21 factory Timer.repeating(int milliSeconds, void callback(Timer timer)) { | 21 factory Timer.repeating(int milliSeconds, void callback(Timer timer)) { |
22 if (_TimerFactory._factory == null) { | 22 if (_TimerFactory._factory == null) { |
23 throw new UnsupportedOperationException("Timer interface not supported."); | 23 throw new UnsupportedError("Timer interface not supported."); |
24 } | 24 } |
25 return _TimerFactory._factory(milliSeconds, callback, true); | 25 return _TimerFactory._factory(milliSeconds, callback, true); |
26 } | 26 } |
27 | 27 |
28 /** | 28 /** |
29 * Cancels the timer. | 29 * Cancels the timer. |
30 */ | 30 */ |
31 void cancel(); | 31 void cancel(); |
32 } | 32 } |
33 | 33 |
34 // TODO(ajohnsen): Patch timer once we have support for patching named | 34 // TODO(ajohnsen): Patch timer once we have support for patching named |
35 // factory constructors in the VM. | 35 // factory constructors in the VM. |
36 | 36 |
37 typedef Timer _TimerFactoryClosure(int milliSeconds, | 37 typedef Timer _TimerFactoryClosure(int milliSeconds, |
38 void callback(Timer timer), | 38 void callback(Timer timer), |
39 bool repeating); | 39 bool repeating); |
40 | 40 |
41 class _TimerFactory { | 41 class _TimerFactory { |
42 static _TimerFactoryClosure _factory; | 42 static _TimerFactoryClosure _factory; |
43 } | 43 } |
44 | 44 |
45 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | 45 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets |
46 // [_TimerFactory._factory] directly. | 46 // [_TimerFactory._factory] directly. |
47 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | 47 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { |
48 _TimerFactory._factory = closure; | 48 _TimerFactory._factory = closure; |
49 } | 49 } |
OLD | NEW |