| Index: sdk/lib/html/dart2js/html_dart2js.dart
|
| ===================================================================
|
| --- sdk/lib/html/dart2js/html_dart2js.dart (revision 20693)
|
| +++ sdk/lib/html/dart2js/html_dart2js.dart (working copy)
|
| @@ -32781,6 +32781,10 @@
|
| return timer;
|
| };
|
|
|
| +const _NEW_TIMER = 'NEW_TIMER';
|
| +const _CANCEL_TIMER = 'CANCEL_TIMER';
|
| +const _TIMER_PING = 'TIMER_PING';
|
| +
|
| class _PureIsolateTimer implements Timer {
|
| final ReceivePort _port = new ReceivePort();
|
| SendPort _sendPort; // Effectively final.
|
| @@ -32808,8 +32812,29 @@
|
| void _cancel() {
|
| _port.close();
|
| }
|
| +
|
| + static final Future<SendPort> _HELPER_ISOLATE_PORT =
|
| + spawnDomFunction(_helperIsolateMain);
|
| }
|
|
|
| +final _TIMER_REGISTRY = new Map<SendPort, Timer>();
|
| +
|
| +_helperIsolateMain() {
|
| + port.receive((msg, replyTo) {
|
| + final cmd = msg[0];
|
| + if (cmd == _NEW_TIMER) {
|
| + final duration = new Duration(milliseconds: msg[1]);
|
| + bool periodic = msg[2];
|
| + final callback = () { replyTo.send(_TIMER_PING); };
|
| + _TIMER_REGISTRY[replyTo] = periodic ?
|
| + new Timer.periodic(duration, callback) :
|
| + new Timer(duration, callback);
|
| + } else if (cmd == _CANCEL_TIMER) {
|
| + _TIMER_REGISTRY.remove(replyTo).cancel();
|
| + }
|
| + });
|
| +}
|
| +
|
| get _pureIsolateTimerFactoryClosure =>
|
| ((int milliSeconds, void callback(Timer time), bool repeating) =>
|
| new _PureIsolateTimer(milliSeconds, callback, repeating));
|
|
|