Commit 1f1adcaa authored by Dan Rubel's avatar Dan Rubel Committed by GitHub

refactor app.* daemon events (#6679)

parent 984b6239
...@@ -361,16 +361,25 @@ class AppDomain extends Domain { ...@@ -361,16 +361,25 @@ class AppDomain extends Domain {
_sendAppEvent(app, 'debugPort', params); _sendAppEvent(app, 'debugPort', params);
}); });
} }
Completer<Null> appStartedCompleter = new Completer<Null>();
appStartedCompleter.future.then((_) {
_sendAppEvent(app, 'started');
});
app._runInZone(this, () { app._runInZone(this, () async {
runner.run(connectionInfoCompleter: connectionInfoCompleter, route: route).then((_) { try {
await runner.run(
connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
route: route,
);
_sendAppEvent(app, 'stop'); _sendAppEvent(app, 'stop');
}).catchError((dynamic error) { } catch (error) {
_sendAppEvent(app, 'stop', <String, dynamic>{ 'error' : error.toString() }); _sendAppEvent(app, 'stop', <String, dynamic>{'error': error.toString()});
}).whenComplete(() { } finally {
Directory.current = cwd; Directory.current = cwd;
_apps.remove(app); _apps.remove(app);
}); }
}); });
return app; return app;
......
...@@ -139,6 +139,7 @@ class HotRunner extends ResidentRunner { ...@@ -139,6 +139,7 @@ class HotRunner extends ResidentRunner {
@override @override
Future<int> run({ Future<int> run({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) { }) {
...@@ -146,6 +147,7 @@ class HotRunner extends ResidentRunner { ...@@ -146,6 +147,7 @@ class HotRunner extends ResidentRunner {
return Chain.capture(() { return Chain.capture(() {
return _run( return _run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
route: route, route: route,
shouldBuild: shouldBuild shouldBuild: shouldBuild
); );
...@@ -173,6 +175,7 @@ class HotRunner extends ResidentRunner { ...@@ -173,6 +175,7 @@ class HotRunner extends ResidentRunner {
Future<int> _run({ Future<int> _run({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) async { }) async {
...@@ -304,6 +307,12 @@ class HotRunner extends ResidentRunner { ...@@ -304,6 +307,12 @@ class HotRunner extends ResidentRunner {
registerSignalHandlers(); registerSignalHandlers();
printTrace('Finishing file synchronization');
// Finish the file sync now.
await _updateDevFS();
appStartedCompleter?.complete();
if (benchmarkMode) { if (benchmarkMode) {
// We are running in benchmark mode. // We are running in benchmark mode.
printStatus('Running in benchmark mode.'); printStatus('Running in benchmark mode.');
......
...@@ -40,6 +40,7 @@ abstract class ResidentRunner { ...@@ -40,6 +40,7 @@ abstract class ResidentRunner {
/// Start the app and keep the process running during its lifetime. /// Start the app and keep the process running during its lifetime.
Future<int> run({ Future<int> run({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}); });
......
...@@ -45,6 +45,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -45,6 +45,7 @@ class RunAndStayResident extends ResidentRunner {
@override @override
Future<int> run({ Future<int> run({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) { }) {
...@@ -55,6 +56,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -55,6 +56,7 @@ class RunAndStayResident extends ResidentRunner {
traceStartup: traceStartup, traceStartup: traceStartup,
benchmark: benchmark, benchmark: benchmark,
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
appStartedCompleter: appStartedCompleter,
route: route, route: route,
shouldBuild: shouldBuild shouldBuild: shouldBuild
); );
...@@ -101,6 +103,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -101,6 +103,7 @@ class RunAndStayResident extends ResidentRunner {
bool traceStartup: false, bool traceStartup: false,
bool benchmark: false, bool benchmark: false,
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<Null> appStartedCompleter,
String route, String route,
bool shouldBuild: true bool shouldBuild: true
}) async { }) async {
...@@ -185,8 +188,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -185,8 +188,8 @@ class RunAndStayResident extends ResidentRunner {
startTime.stop(); startTime.stop();
if (connectionInfoCompleter != null && _result.hasObservatory) if (_result.hasObservatory)
connectionInfoCompleter.complete(new DebugConnectionInfo(_result.observatoryPort)); connectionInfoCompleter?.complete(new DebugConnectionInfo(_result.observatoryPort));
// Connect to observatory. // Connect to observatory.
if (debuggingOptions.debuggingEnabled) { if (debuggingOptions.debuggingEnabled) {
...@@ -218,6 +221,8 @@ class RunAndStayResident extends ResidentRunner { ...@@ -218,6 +221,8 @@ class RunAndStayResident extends ResidentRunner {
registerSignalHandlers(); registerSignalHandlers();
} }
appStartedCompleter?.complete();
if (benchmark) { if (benchmark) {
await new Future<Null>.delayed(new Duration(seconds: 4)); await new Future<Null>.delayed(new Duration(seconds: 4));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment