Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: lib/isolate/dart2js/timer_provider.dart

Issue 10830230: Add Timer implementation for dart2js. Also moves tests to appropriate location. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/isolate/dart2js/isolateimpl.dart ('k') | lib/isolate/isolate_dart2js.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5
6 // We don't want to import the DOM library just because of window.setTimeout,
7 // so we reconstruct the Window class here. The only conflict that could happen
8 // with the other DOMWindow class would be because of subclasses.
9 // Currently, none of the two Dart classes have subclasses.
10 typedef void _TimeoutHandler();
11
12 class _Window native "@*DOMWindow" {
13 int setTimeout(_TimeoutHandler handler, int timeout) native;
14 int setInterval(_TimeoutHandler handler, int timeout) native;
15 }
16
17 _Window get _window() =>
18 JS('bool', 'typeof window != "undefined"') ? JS('_Window', 'window') : null;
19
20 class _Timer implements Timer {
21 final bool _once;
22 int _handle;
23
24 _Timer(int milliSeconds, void callback(Timer timer))
25 : _once = true {
26 _handle = _window.setTimeout(() => callback(this), milliSeconds);
27 }
28
29 _Timer.repeating(int milliSeconds, void callback(Timer timer))
30 : _once = false {
31 _handle = _window.setInterval(() => callback(this), milliSeconds);
32 }
33
34 void cancel() {
35 if (_once) {
36 _window.clearTimeout(_handle);
37 } else {
38 _window.clearInterval(_handle);
39 }
40 }
41 }
42
43 Timer _timerFactory(int millis, void callback(Timer timer), bool repeating) =>
44 repeating ? new _Timer.repeating(millis, callback)
45 : new _Timer(millis, callback);
OLDNEW
« no previous file with comments | « lib/isolate/dart2js/isolateimpl.dart ('k') | lib/isolate/isolate_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698