| 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 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const _CANCEL_TIMER = 'CANCEL_TIMER'; | 140 const _CANCEL_TIMER = 'CANCEL_TIMER'; |
| 141 const _TIMER_PING = 'TIMER_PING'; | 141 const _TIMER_PING = 'TIMER_PING'; |
| 142 const _PRINT = 'PRINT'; | 142 const _PRINT = 'PRINT'; |
| 143 | 143 |
| 144 _helperIsolateMain() { | 144 _helperIsolateMain() { |
| 145 port.receive((msg, replyTo) { | 145 port.receive((msg, replyTo) { |
| 146 final cmd = msg[0]; | 146 final cmd = msg[0]; |
| 147 if (cmd == _NEW_TIMER) { | 147 if (cmd == _NEW_TIMER) { |
| 148 final duration = new Duration(milliseconds: msg[1]); | 148 final duration = new Duration(milliseconds: msg[1]); |
| 149 bool periodic = msg[2]; | 149 bool periodic = msg[2]; |
| 150 final callback = () { replyTo.send(_TIMER_PING); }; | 150 ping() { replyTo.send(_TIMER_PING); }; |
| 151 _TIMER_REGISTRY[replyTo] = periodic ? | 151 _TIMER_REGISTRY[replyTo] = periodic ? |
| 152 new Timer.periodic(duration, callback) : | 152 new Timer.periodic(duration, (_) { ping(); }) : |
| 153 new Timer(duration, callback); | 153 new Timer(duration, ping); |
| 154 } else if (cmd == _CANCEL_TIMER) { | 154 } else if (cmd == _CANCEL_TIMER) { |
| 155 _TIMER_REGISTRY.remove(replyTo).cancel(); | 155 _TIMER_REGISTRY.remove(replyTo).cancel(); |
| 156 } else if (cmd == _PRINT) { | 156 } else if (cmd == _PRINT) { |
| 157 final message = msg[1]; | 157 final message = msg[1]; |
| 158 // TODO(antonm): we need somehow identify those isolates. | 158 // TODO(antonm): we need somehow identify those isolates. |
| 159 print('[From isolate] $message'); | 159 print('[From isolate] $message'); |
| 160 } | 160 } |
| 161 }); | 161 }); |
| 162 } | 162 } |
| 163 | 163 |
| 164 final _printClosure = window.console.log; | 164 final _printClosure = window.console.log; |
| 165 final _pureIsolatePrintClosure = (s) { | 165 final _pureIsolatePrintClosure = (s) { |
| 166 _HELPER_ISOLATE_PORT.then((sendPort) { | 166 _HELPER_ISOLATE_PORT.then((sendPort) { |
| 167 sendPort.send([_PRINT, s]); | 167 sendPort.send([_PRINT, s]); |
| 168 }); | 168 }); |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 final _forwardingPrintClosure = _Utils.forwardingPrint; | 171 final _forwardingPrintClosure = _Utils.forwardingPrint; |
| OLD | NEW |