Skip to content

Commit d7dad51

Browse files
committed
implemented pause/resume logic
1 parent 871f388 commit d7dad51

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

dwds/lib/src/services/web_socket_proxy_service.dart

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class WebSocketProxyService implements VmServiceInterface {
146146
vm_service.IsolateRef? _isolateRef;
147147
bool _isolateRunning = false;
148148
vm_service.Event? _currentPauseEvent;
149+
bool _mainHasStarted = false;
149150

150151
/// Creates a new isolate for WebSocket debugging.
151152
Future<void> createIsolate([AppConnection? appConnectionOverride]) async {
@@ -241,6 +242,7 @@ class WebSocketProxyService implements VmServiceInterface {
241242
_isolateRef = null;
242243
_isolateRunning = false;
243244
_currentPauseEvent = null;
245+
_mainHasStarted = false;
244246

245247
if (_initializedCompleter.isCompleted) {
246248
_initializedCompleter = Completer<void>();
@@ -757,6 +759,26 @@ class WebSocketProxyService implements VmServiceInterface {
757759
return UriList(uris: uris.map(DartUri.toResolvedUri).toList());
758760
}
759761

762+
/// Pauses execution of the isolate.
763+
@override
764+
Future<Success> pause(String isolateId) =>
765+
wrapInErrorHandlerAsync('pause', () => _pause(isolateId));
766+
767+
Future<Success> _pause(String isolateId) async {
768+
// Create a pause event and store it
769+
if (_isolateRef != null) {
770+
final pauseEvent = vm_service.Event(
771+
kind: vm_service.EventKind.kPauseInterrupted,
772+
timestamp: DateTime.now().millisecondsSinceEpoch,
773+
isolate: _isolateRef!,
774+
);
775+
_currentPauseEvent = pauseEvent;
776+
_streamNotify(vm_service.EventStreams.kDebug, pauseEvent);
777+
}
778+
779+
return Success();
780+
}
781+
760782
/// Resumes execution of the isolate.
761783
@override
762784
Future<Success> resume(String isolateId, {String? step, int? frameIndex}) =>
@@ -773,7 +795,18 @@ class WebSocketProxyService implements VmServiceInterface {
773795
if (hasPendingRestart && !_resumeAfterRestartEventsController.isClosed) {
774796
_resumeAfterRestartEventsController.add(isolateId);
775797
} else {
776-
appConnection.runMain();
798+
if (!_mainHasStarted) {
799+
try {
800+
appConnection.runMain();
801+
_mainHasStarted = true;
802+
} catch (e) {
803+
if (e.toString().contains('Main has already started')) {
804+
_mainHasStarted = true;
805+
} else {
806+
rethrow;
807+
}
808+
}
809+
}
777810
}
778811

779812
// Clear pause state and send resume event to notify debugging tools

0 commit comments

Comments
 (0)