Adding a setup function for hot restart (#18921)

* Adding a setup function for hot restart that can be overwritten to perform any necessary initialization before a restart is started.

* Adding a test for setupHotRestart

* Removing local pubspec change

* Fixing some type annotation errors

* Responding to comments
This commit is contained in:
abykov2
2018-07-06 15:18:57 -07:00
committed by Alexander Aprelev
parent d5d129803a
commit e5d9feb59d
2 changed files with 60 additions and 0 deletions

View File

@@ -27,6 +27,11 @@ class HotRunnerConfig {
bool computeDartDependencies = true;
/// Should the hot runner assume that the minimal Dart dependencies do not change?
bool stableDartDependencies = false;
/// A hook for implementations to perform any necessary initialization prior
/// to a hot restart. Should return true if the hot restart should continue.
Future<bool> setupHotRestart() async {
return true;
}
}
HotRunnerConfig get hotRunnerConfig => context[HotRunnerConfig];
@@ -477,6 +482,10 @@ class HotRunner extends ResidentRunner {
);
try {
final Stopwatch timer = new Stopwatch()..start();
if (!(await hotRunnerConfig.setupHotRestart())) {
status.cancel();
return new OperationResult(1, 'setupHotRestart failed');
}
await _restartFromSources();
timer.stop();
status.cancel();