refactor app.* daemon events (#6679)
This commit is contained in:
@@ -361,16 +361,25 @@ class AppDomain extends Domain {
|
||||
_sendAppEvent(app, 'debugPort', params);
|
||||
});
|
||||
}
|
||||
Completer<Null> appStartedCompleter = new Completer<Null>();
|
||||
appStartedCompleter.future.then((_) {
|
||||
_sendAppEvent(app, 'started');
|
||||
});
|
||||
|
||||
app._runInZone(this, () {
|
||||
runner.run(connectionInfoCompleter: connectionInfoCompleter, route: route).then((_) {
|
||||
app._runInZone(this, () async {
|
||||
try {
|
||||
await runner.run(
|
||||
connectionInfoCompleter: connectionInfoCompleter,
|
||||
appStartedCompleter: appStartedCompleter,
|
||||
route: route,
|
||||
);
|
||||
_sendAppEvent(app, 'stop');
|
||||
}).catchError((dynamic error) {
|
||||
_sendAppEvent(app, 'stop', <String, dynamic>{ 'error' : error.toString() });
|
||||
}).whenComplete(() {
|
||||
} catch (error) {
|
||||
_sendAppEvent(app, 'stop', <String, dynamic>{'error': error.toString()});
|
||||
} finally {
|
||||
Directory.current = cwd;
|
||||
_apps.remove(app);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return app;
|
||||
|
||||
@@ -139,6 +139,7 @@ class HotRunner extends ResidentRunner {
|
||||
@override
|
||||
Future<int> run({
|
||||
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
||||
Completer<Null> appStartedCompleter,
|
||||
String route,
|
||||
bool shouldBuild: true
|
||||
}) {
|
||||
@@ -146,6 +147,7 @@ class HotRunner extends ResidentRunner {
|
||||
return Chain.capture(() {
|
||||
return _run(
|
||||
connectionInfoCompleter: connectionInfoCompleter,
|
||||
appStartedCompleter: appStartedCompleter,
|
||||
route: route,
|
||||
shouldBuild: shouldBuild
|
||||
);
|
||||
@@ -173,6 +175,7 @@ class HotRunner extends ResidentRunner {
|
||||
|
||||
Future<int> _run({
|
||||
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
||||
Completer<Null> appStartedCompleter,
|
||||
String route,
|
||||
bool shouldBuild: true
|
||||
}) async {
|
||||
@@ -304,6 +307,12 @@ class HotRunner extends ResidentRunner {
|
||||
|
||||
registerSignalHandlers();
|
||||
|
||||
printTrace('Finishing file synchronization');
|
||||
// Finish the file sync now.
|
||||
await _updateDevFS();
|
||||
|
||||
appStartedCompleter?.complete();
|
||||
|
||||
if (benchmarkMode) {
|
||||
// We are running in benchmark mode.
|
||||
printStatus('Running in benchmark mode.');
|
||||
|
||||
@@ -40,6 +40,7 @@ abstract class ResidentRunner {
|
||||
/// Start the app and keep the process running during its lifetime.
|
||||
Future<int> run({
|
||||
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
||||
Completer<Null> appStartedCompleter,
|
||||
String route,
|
||||
bool shouldBuild: true
|
||||
});
|
||||
|
||||
@@ -45,6 +45,7 @@ class RunAndStayResident extends ResidentRunner {
|
||||
@override
|
||||
Future<int> run({
|
||||
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
||||
Completer<Null> appStartedCompleter,
|
||||
String route,
|
||||
bool shouldBuild: true
|
||||
}) {
|
||||
@@ -55,6 +56,7 @@ class RunAndStayResident extends ResidentRunner {
|
||||
traceStartup: traceStartup,
|
||||
benchmark: benchmark,
|
||||
connectionInfoCompleter: connectionInfoCompleter,
|
||||
appStartedCompleter: appStartedCompleter,
|
||||
route: route,
|
||||
shouldBuild: shouldBuild
|
||||
);
|
||||
@@ -101,6 +103,7 @@ class RunAndStayResident extends ResidentRunner {
|
||||
bool traceStartup: false,
|
||||
bool benchmark: false,
|
||||
Completer<DebugConnectionInfo> connectionInfoCompleter,
|
||||
Completer<Null> appStartedCompleter,
|
||||
String route,
|
||||
bool shouldBuild: true
|
||||
}) async {
|
||||
@@ -185,8 +188,8 @@ class RunAndStayResident extends ResidentRunner {
|
||||
|
||||
startTime.stop();
|
||||
|
||||
if (connectionInfoCompleter != null && _result.hasObservatory)
|
||||
connectionInfoCompleter.complete(new DebugConnectionInfo(_result.observatoryPort));
|
||||
if (_result.hasObservatory)
|
||||
connectionInfoCompleter?.complete(new DebugConnectionInfo(_result.observatoryPort));
|
||||
|
||||
// Connect to observatory.
|
||||
if (debuggingOptions.debuggingEnabled) {
|
||||
@@ -218,6 +221,8 @@ class RunAndStayResident extends ResidentRunner {
|
||||
registerSignalHandlers();
|
||||
}
|
||||
|
||||
appStartedCompleter?.complete();
|
||||
|
||||
if (benchmark) {
|
||||
await new Future<Null>.delayed(new Duration(seconds: 4));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user