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

Side by Side 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, 8 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 | « tools/dom/src/Timer.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of html; 5 part of html;
6 6
7 class _Utils { 7 class _Utils {
8 static double dateTimeToDouble(DateTime dateTime) => 8 static double dateTimeToDouble(DateTime dateTime) =>
9 dateTime.millisecondsSinceEpoch.toDouble(); 9 dateTime.millisecondsSinceEpoch.toDouble();
10 static DateTime doubleToDateTime(double dateTime) { 10 static DateTime doubleToDateTime(double dateTime) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 181 }
182 }); 182 });
183 } 183 }
184 184
185 final _printClosure = window.console.log; 185 final _printClosure = window.console.log;
186 final _pureIsolatePrintClosure = (s) { 186 final _pureIsolatePrintClosure = (s) {
187 _sendToHelperIsolate([_PRINT, s], null); 187 _sendToHelperIsolate([_PRINT, s], null);
188 }; 188 };
189 189
190 final _forwardingPrintClosure = _Utils.forwardingPrint; 190 final _forwardingPrintClosure = _Utils.forwardingPrint;
191
192 class _Timer implements Timer {
193 final canceller;
194
195 _Timer(this.canceller);
196
197 void cancel() { canceller(); }
198 }
199
200 get _timerFactoryClosure => (int milliSeconds, void callback(Timer timer), bool repeating) {
vsm 2013/04/04 13:41:49 nit length
201 var maker;
202 var canceller;
203 if (repeating) {
204 maker = window._setInterval;
205 canceller = window._clearInterval;
206 } else {
207 maker = window._setTimeout;
208 canceller = window._clearTimeout;
209 }
210 Timer timer;
211 final int id = maker(() { callback(timer); }, milliSeconds);
212 timer = new _Timer(() { canceller(id); });
213 return timer;
214 };
215
216 class _PureIsolateTimer implements Timer {
217 final ReceivePort _port = new ReceivePort();
218 SendPort _sendPort; // Effectively final.
219
220 static SendPort _SEND_PORT;
221
222 _PureIsolateTimer(int milliSeconds, callback, repeating) {
223 _sendPort = _port.toSendPort();
224 _port.receive((msg, replyTo) {
225 assert(msg == _TIMER_PING);
226 callback(this);
227 if (!repeating) _cancel();
228 });
229
230 _send([_NEW_TIMER, milliSeconds, repeating]);
231 }
232
233 void cancel() {
234 _cancel();
235 _send([_CANCEL_TIMER]);
236 }
237
238 void _cancel() {
239 _port.close();
240 }
241
242 _send(msg) {
243 _sendToHelperIsolate(msg, _sendPort);
244 }
245 }
246
247 get _pureIsolateTimerFactoryClosure =>
248 ((int milliSeconds, void callback(Timer time), bool repeating) =>
249 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW
« 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