Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During hot-restart, wait to run main when pause_isolates_on_start is true #2378

Merged
merged 9 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Rename `dart_library.js` to `ddc_module_loader.js` to match SDK naming changes. - [#2360](https://github.com/dart-lang/webdev/pull/2360)
- Implement `setFlag` when it is called with `pause_isolates_on_start`. - [#2373](https://github.com/dart-lang/webdev/pull/2373)
- Do not persist breakpoints across hot restarts or page reloads. - [#2371](https://github.com/dart-lang/webdev/pull/2371)
- If `pause_isolates_on_start` is `true`, wait for `resume` to run the app's `main` method. - [#2378](https://github.com/dart-lang/webdev/pull/2378)

## 23.3.0

Expand Down
33 changes: 31 additions & 2 deletions dwds/lib/src/dwds_vm_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:dwds/src/events.dart';
import 'package:dwds/src/services/chrome_debug_exception.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:dwds/src/services/debug_service.dart';
import 'package:dwds/src/utilities/shared.dart';
import 'package:dwds/src/utilities/synchronized.dart';
import 'package:logging/logging.dart';
import 'package:uuid/uuid.dart';
Expand Down Expand Up @@ -252,11 +253,19 @@ Future<Map<String, dynamic>> _hotRestart(
// restart. Only return success after the isolate has fully started.
final stream = chromeProxyService.onEvent('Isolate');
try {
// If we should pause isolates on start, then only run main once we get a
// resume event.
final pauseIsolatesOnStart = chromeProxyService.pauseIsolatesOnStart;
if (pauseIsolatesOnStart) {
_waitForResumeEventToRunMain(chromeProxyService);
}
// Generate run id to hot restart all apps loaded into the tab.
final runId = const Uuid().v4().toString();
_logger.info('Issuing \$dartHotRestartDwds request');
await chromeProxyService.inspector
.jsEvaluate('\$dartHotRestartDwds(\'$runId\');', awaitPromise: true);
await chromeProxyService.inspector.jsEvaluate(
'\$dartHotRestartDwds(\'$runId\', $pauseIsolatesOnStart);',
awaitPromise: true,
);
_logger.info('\$dartHotRestartDwds request complete.');
} on WipError catch (exception) {
final code = exception.error?['code'];
Expand Down Expand Up @@ -289,6 +298,26 @@ Future<Map<String, dynamic>> _hotRestart(
return {'result': Success().toJson()};
}

void _waitForResumeEventToRunMain(
ChromeProxyService chromeProxyService,
) {
final issuedReadyToRunMainCompleter = Completer<void>();

final resumeEventsSubscription =
chromeProxyService.resumeAfterHotRestartEventsStream.listen((_) async {
await chromeProxyService.inspector.jsEvaluate('\$dartReadyToRunMain();');
if (!issuedReadyToRunMainCompleter.isCompleted) {
issuedReadyToRunMainCompleter.complete();
}
});

safeUnawaited(
issuedReadyToRunMainCompleter.future.then((_) {
resumeEventsSubscription.cancel();
}),
);
}

Future<Map<String, dynamic>> _fullReload(
ChromeProxyService chromeProxyService,
) async {
Expand Down
Loading
Loading