OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:async/async.dart'; | 9 import 'package:async/async.dart'; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 /// Returns the Observatory URL for the Dartium executable with the given | 106 /// Returns the Observatory URL for the Dartium executable with the given |
107 /// [stdout] stream, or `null` if the correct one couldn't be found. | 107 /// [stdout] stream, or `null` if the correct one couldn't be found. |
108 /// | 108 /// |
109 /// Dartium prints out three different Observatory URLs when it starts. Only | 109 /// Dartium prints out three different Observatory URLs when it starts. Only |
110 /// one of them is connected to the VM instance running the host page, and the | 110 /// one of them is connected to the VM instance running the host page, and the |
111 /// ordering isn't guaranteed, so we need to figure out which one is correct. | 111 /// ordering isn't guaranteed, so we need to figure out which one is correct. |
112 /// We do so by connecting to the VM service via WebSockets and looking for | 112 /// We do so by connecting to the VM service via WebSockets and looking for |
113 /// the Observatory instance that actually contains an isolate, and returning | 113 /// the Observatory instance that actually contains an isolate, and returning |
114 /// the corresponding URI. | 114 /// the corresponding URI. |
115 static Future<Uri> _getObservatoryUrl(Stream<List<int>> stdout) async { | 115 static Future<Uri> _getObservatoryUrl(Stream<List<int>> stdout) async { |
116 var urlQueue = new StreamQueue<Uri>(lineSplitter.bind(stdout).map((line) { | 116 var urlQueue = new StreamQueue<Uri>(transformUtf8ToLines(stdout).map((line)
{ |
117 var match = _observatoryRegExp.firstMatch(line); | 117 var match = _observatoryRegExp.firstMatch(line); |
118 return match == null ? null : Uri.parse(match[1]); | 118 return match == null ? null : Uri.parse(match[1]); |
119 }).where((line) => line != null)); | 119 }).where((line) => line != null)); |
120 | 120 |
121 var operations = [ | 121 var operations = [ |
122 urlQueue.next, | 122 urlQueue.next, |
123 urlQueue.next, | 123 urlQueue.next, |
124 urlQueue.next | 124 urlQueue.next |
125 ].map((future) => _checkObservatoryUrl(future)); | 125 ].map((future) => _checkObservatoryUrl(future)); |
126 | 126 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // incorrect WebSocket that already closed. | 241 // incorrect WebSocket that already closed. |
242 return null; | 242 return null; |
243 } | 243 } |
244 }).catchError((error, stackTrace) { | 244 }).catchError((error, stackTrace) { |
245 if (!completer.isCompleted) completer.completeError(error, stackTrace); | 245 if (!completer.isCompleted) completer.completeError(error, stackTrace); |
246 }); | 246 }); |
247 | 247 |
248 return completer.operation; | 248 return completer.operation; |
249 } | 249 } |
250 } | 250 } |
OLD | NEW |