fix a race condition with isolate notification (#4286)

* fix a race condition with isolate notification

* return a future
This commit is contained in:
Devon Carew 2016-06-01 15:17:04 -07:00
parent 2a2bd7b6f4
commit 9e9dfc3d2d
2 changed files with 6 additions and 1 deletions

View File

@ -394,10 +394,10 @@ class _RunAndStayResident {
observatory = await Observatory.connect(result.observatoryPort);
printTrace('Connected to observatory port: ${result.observatoryPort}.');
observatory.populateIsolateInfo();
observatory.onExtensionEvent.listen((Event event) {
printTrace(event.toString());
});
observatory.onIsolateEvent.listen((Event event) {
printTrace(event.toString());
});

View File

@ -74,6 +74,11 @@ class Observatory {
_getEventController(data['streamId']).add(event);
}
Future<Null> populateIsolateInfo() async {
// Calling this has the side effect of populating the isolate information.
await waitFirstIsolate;
}
Future<IsolateRef> get waitFirstIsolate async {
if (isolates.isNotEmpty)
return isolates.first;