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 /** Entrypoint to set up the dartcombat sample. */ | 5 /** Entrypoint to set up the dartcombat sample. */ |
6 void setUpGame() { | 6 void setUpGame() { |
7 setupUI(); | 7 setupUI(); |
8 createPlayers(); | 8 createPlayers(); |
9 } | 9 } |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 /** | 66 /** |
67 * A proxy between ports that randomly drops messages to simulate isolates | 67 * A proxy between ports that randomly drops messages to simulate isolates |
68 * across the network. | 68 * across the network. |
69 */ | 69 */ |
70 class FlakyProxy { | 70 class FlakyProxy { |
71 ReceivePort proxy; | 71 ReceivePort proxy; |
72 | 72 |
73 SendPort _target; | 73 SendPort _target; |
74 | 74 |
75 SendPort get sendPort() => proxy.toSendPort(); | 75 SendPort get sendPort => proxy.toSendPort(); |
76 | 76 |
77 FlakyProxy(this._target) { | 77 FlakyProxy(this._target) { |
78 proxy = new ReceivePort(); | 78 proxy = new ReceivePort(); |
79 | 79 |
80 proxy.receive((message, SendPort reply) { | 80 proxy.receive((message, SendPort reply) { |
81 window.setTimeout(() { | 81 window.setTimeout(() { |
82 if (randomlyFail()) { | 82 if (randomlyFail()) { |
83 reply.send(const [false, "There was an error"], null); | 83 reply.send(const [false, "There was an error"], null); |
84 } else { | 84 } else { |
85 _target.send(message, reply); | 85 _target.send(message, reply); |
86 } | 86 } |
87 }, 200); | 87 }, 200); |
88 }); | 88 }); |
89 } | 89 } |
90 | 90 |
91 // TODO(sigmund): introduce UI to control flakiness, then do: | 91 // TODO(sigmund): introduce UI to control flakiness, then do: |
92 // => Math.random() > 0.9; | 92 // => Math.random() > 0.9; |
93 bool randomlyFail() => false; | 93 bool randomlyFail() => false; |
94 } | 94 } |
OLD | NEW |