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

Unified Diff: tools/dom/src/native_DOMImplementation.dart

Issue 13515004: Remove pseudo-shared Timer implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index 0e62774be0ed0d408bb5ab3d7e8469e2598e44a8..aeb37756aeda201ee250c9a6f233856c739120c4 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -188,3 +188,62 @@ final _pureIsolatePrintClosure = (s) {
};
final _forwardingPrintClosure = _Utils.forwardingPrint;
+
+class _Timer implements Timer {
+ final canceller;
+
+ _Timer(this.canceller);
+
+ void cancel() { canceller(); }
+}
+
+get _timerFactoryClosure => (int milliSeconds, void callback(Timer timer), bool repeating) {
vsm 2013/04/04 13:41:49 nit length
+ var maker;
+ var canceller;
+ if (repeating) {
+ maker = window._setInterval;
+ canceller = window._clearInterval;
+ } else {
+ maker = window._setTimeout;
+ canceller = window._clearTimeout;
+ }
+ Timer timer;
+ final int id = maker(() { callback(timer); }, milliSeconds);
+ timer = new _Timer(() { canceller(id); });
+ return timer;
+};
+
+class _PureIsolateTimer implements Timer {
+ final ReceivePort _port = new ReceivePort();
+ SendPort _sendPort; // Effectively final.
+
+ static SendPort _SEND_PORT;
+
+ _PureIsolateTimer(int milliSeconds, callback, repeating) {
+ _sendPort = _port.toSendPort();
+ _port.receive((msg, replyTo) {
+ assert(msg == _TIMER_PING);
+ callback(this);
+ if (!repeating) _cancel();
+ });
+
+ _send([_NEW_TIMER, milliSeconds, repeating]);
+ }
+
+ void cancel() {
+ _cancel();
+ _send([_CANCEL_TIMER]);
+ }
+
+ void _cancel() {
+ _port.close();
+ }
+
+ _send(msg) {
+ _sendToHelperIsolate(msg, _sendPort);
+ }
+}
+
+get _pureIsolateTimerFactoryClosure =>
+ ((int milliSeconds, void callback(Timer time), bool repeating) =>
+ new _PureIsolateTimer(milliSeconds, callback, repeating));
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698