OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // VMOptions=--compile_all --error_on_bad_type --error_on_bad_override --checked | 4 // VMOptions=--compile_all --error_on_bad_type --error_on_bad_override --checked |
5 | 5 |
6 library test_helper; | 6 library test_helper; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 subscription.cancel(); | 230 subscription.cancel(); |
231 completer.complete(); | 231 completer.complete(); |
232 } | 232 } |
233 }); | 233 }); |
234 }); | 234 }); |
235 isolate.resume(); | 235 isolate.resume(); |
236 return completer.future; | 236 return completer.future; |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 Future streamEvent(Isolate isolate, stream, onEvent) async { | |
241 Completer completer = new Completer(); | |
242 var sub; | |
243 sub = await isolate.vm.listenEventStream( | |
244 stream, | |
245 (ServiceEvent event) { | |
246 var r = onEvent(event); | |
247 if (r is! Future) { | |
248 r = new Future.value(r); | |
249 } | |
250 r.then((x) => sub.cancel().then((_) { | |
251 completer.complete(); | |
252 })); | |
253 }); | |
254 await isolate.resume(); | |
255 return completer.future; | |
256 } | |
257 | |
258 IsolateTest isolateStreamEvent(stream, onEvent) { | |
rmacnak
2015/07/21 00:20:15
This name doesn't suggest it resumes the isolate.
Cutch
2015/07/21 14:51:44
Done.
| |
259 return (Isolate isolate) async => streamEvent(isolate, stream, onEvent); | |
260 } | |
261 | |
262 | |
240 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { | 263 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { |
241 Library rootLib = await isolate.rootLibrary.load(); | 264 Library rootLib = await isolate.rootLibrary.load(); |
242 for (var i = 0; i < rootLib.classes.length; i++) { | 265 for (var i = 0; i < rootLib.classes.length; i++) { |
243 Class cls = rootLib.classes[i]; | 266 Class cls = rootLib.classes[i]; |
244 if (cls.name == className) { | 267 if (cls.name == className) { |
245 return cls; | 268 return cls; |
246 } | 269 } |
247 } | 270 } |
248 return null; | 271 return null; |
249 } | 272 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 }, onError: (e, st) { | 311 }, onError: (e, st) { |
289 process.requestExit(); | 312 process.requestExit(); |
290 if (!_isWebSocketDisconnect(e)) { | 313 if (!_isWebSocketDisconnect(e)) { |
291 print('Unexpected exception in service tests: $e $st'); | 314 print('Unexpected exception in service tests: $e $st'); |
292 throw e; | 315 throw e; |
293 } | 316 } |
294 }); | 317 }); |
295 }); | 318 }); |
296 } | 319 } |
297 } | 320 } |
OLD | NEW |