Skip to content

Commit fbae28c

Browse files
committed
Use function that returns a Future instead of a stream + completer
1 parent 938d4ce commit fbae28c

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ class ChromeProxyService implements VmServiceInterface {
117117
final _resumeAfterRestartEventsController =
118118
StreamController<String>.broadcast();
119119

120-
final _resumeAfterHotReloadEventsController =
121-
StreamController<Completer<void>>.broadcast();
122-
123120
/// A global stream of resume events for hot restart.
124121
///
125122
/// The values in the stream are the isolates IDs for the resume event.
@@ -130,16 +127,11 @@ class ChromeProxyService implements VmServiceInterface {
130127
Stream<String> get resumeAfterRestartEventsStream =>
131128
_resumeAfterRestartEventsController.stream;
132129

133-
/// A global stream of resume events for hot reload.
134-
///
135-
/// The values in the stream are [Completer]s that should be completed after
136-
/// finishing the hot reload.
130+
/// If non-null, a resume event should await the result of this after resuming
131+
/// execution.
137132
///
138-
/// IMPORTANT: This should only be listened to during a hot reload. The
139-
/// debugger ignores any resume events as long as there is a subscriber to
140-
/// this stream.
141-
Stream<Completer<void>> get resumeAfterHotReloadEventsStream =>
142-
_resumeAfterHotReloadEventsController.stream;
133+
/// This is used to complete a hot reload.
134+
Future<void> Function()? _finishHotReloadOnResume;
143135

144136
final _logger = Logger('ChromeProxyService');
145137

@@ -1223,22 +1215,17 @@ class ChromeProxyService implements VmServiceInterface {
12231215
// If `pause_isolates_on_start` is enabled, pause and then the reload
12241216
// should finish later after the client removes breakpoints, reregisters
12251217
// breakpoints, and resumes.
1226-
StreamSubscription<Completer<void>>? resumeEventsSubscription;
1227-
resumeEventsSubscription = resumeAfterHotReloadEventsStream.listen((
1228-
Completer<void> completer,
1229-
) async {
1218+
_finishHotReloadOnResume = () async {
12301219
// Client finished setting breakpoints, called resume, and now the
12311220
// execution has resumed. Finish the hot reload so we start executing
12321221
// the new code instead.
1233-
await resumeEventsSubscription!.cancel();
12341222
_logger.info('Issuing \$dartHotReloadEndDwds request');
12351223
await inspector.jsEvaluate(
12361224
'\$dartHotReloadEndDwds();',
12371225
awaitPromise: true,
12381226
);
12391227
_logger.info('\$dartHotReloadEndDwds request complete.');
1240-
completer.complete();
1241-
});
1228+
};
12421229

12431230
// Pause and wait for the pause to occur before managing breakpoints.
12441231
final pausedEvent = _firstStreamEvent(
@@ -1350,11 +1337,10 @@ class ChromeProxyService implements VmServiceInterface {
13501337
}, (result) => DwdsEvent.resume(step));
13511338
}
13521339

1353-
if (_resumeAfterHotReloadEventsController.hasListener) {
1340+
if (_finishHotReloadOnResume != null) {
13541341
await resumeWhenAppHasStarted();
1355-
final completer = Completer<void>();
1356-
_resumeAfterHotReloadEventsController.add(completer);
1357-
await completer.future;
1342+
await _finishHotReloadOnResume!();
1343+
_finishHotReloadOnResume = null;
13581344
return Success();
13591345
}
13601346
if (inspector.appConnection.isStarted) {

0 commit comments

Comments
 (0)