| 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 // TODO(antonm): support not DOM isolates too. | 7 // TODO(antonm): support not DOM isolates too. |
| 8 class _Timer implements Timer { | 8 class _Timer implements Timer { |
| 9 final canceller; | 9 final canceller; |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 class _PureIsolateTimer implements Timer { | 32 class _PureIsolateTimer implements Timer { |
| 33 final ReceivePort _port = new ReceivePort(); | 33 final ReceivePort _port = new ReceivePort(); |
| 34 SendPort _sendPort; // Effectively final. | 34 SendPort _sendPort; // Effectively final. |
| 35 | 35 |
| 36 _PureIsolateTimer(int milliSeconds, callback, repeating) { | 36 _PureIsolateTimer(int milliSeconds, callback, repeating) { |
| 37 _sendPort = _port.toSendPort(); | 37 _sendPort = _port.toSendPort(); |
| 38 _port.receive((msg, replyTo) { | 38 _port.receive((msg, replyTo) { |
| 39 assert(msg == _TIMER_PING); | 39 assert(msg == _TIMER_PING); |
| 40 assert(replyTo == _HELPER_ISOLATE_PORT); | |
| 41 callback(this); | 40 callback(this); |
| 42 if (!repeating) _cancel(); | 41 if (!repeating) _cancel(); |
| 43 }); | 42 }); |
| 44 _HELPER_ISOLATE_PORT.then((port) { | 43 _HELPER_ISOLATE_PORT.then((port) { |
| 45 port.send([_NEW_TIMER, milliSeconds, repeating], _sendPort); | 44 port.send([_NEW_TIMER, milliSeconds, repeating], _sendPort); |
| 46 }); | 45 }); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void cancel() { | 48 void cancel() { |
| 50 _cancel(); | 49 _cancel(); |
| 51 _HELPER_ISOLATE_PORT.then((port) { | 50 _HELPER_ISOLATE_PORT.then((port) { |
| 52 port.send([_CANCEL_TIMER], _sendPort); | 51 port.send([_CANCEL_TIMER], _sendPort); |
| 53 }); | 52 }); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void _cancel() { | 55 void _cancel() { |
| 57 _port.close(); | 56 _port.close(); |
| 58 } | 57 } |
| 59 } | 58 } |
| 60 | 59 |
| 61 get _pureIsolateTimerFactoryClosure => | 60 get _pureIsolateTimerFactoryClosure => |
| 62 ((int milliSeconds, void callback(Timer time), bool repeating) => | 61 ((int milliSeconds, void callback(Timer time), bool repeating) => |
| 63 new _PureIsolateTimer(milliSeconds, callback, repeating)); | 62 new _PureIsolateTimer(milliSeconds, callback, repeating)); |
| OLD | NEW |