Skip to content

Commit 4bebd62

Browse files
authored
ServiceExtensionManager: return early... earlier (#9287)
1 parent 131c9de commit 4bebd62

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

packages/devtools_app_shared/lib/src/service/service_extension_manager.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ final class ServiceExtensionManager with DisposerMixin {
309309
final expectedValueType =
310310
extensions.serviceExtensionsAllowlist[name]!.values.first.runtimeType;
311311

312+
if (isolateRef != _mainIsolate) return false;
313+
314+
final isolate = await _isolateManager.isolateState(isolateRef).isolate;
315+
if (isolateRef != _mainIsolate) return false;
316+
312317
/// Restores the service extension named [name].
313318
///
314319
/// Returns whether isolates in the connected app are prepared for the
@@ -355,11 +360,6 @@ final class ServiceExtensionManager with DisposerMixin {
355360
return true;
356361
}
357362

358-
if (isolateRef != _mainIsolate) return false;
359-
360-
final isolate = await _isolateManager.isolateState(isolateRef).isolate;
361-
if (isolateRef != _mainIsolate) return false;
362-
363363
// Do not try to restore Dart IO extensions for a paused isolate.
364364
if (extensions.isDartIoExtension(name) &&
365365
isolate?.pauseEvent?.kind?.contains('Pause') == true) {
@@ -399,6 +399,11 @@ final class ServiceExtensionManager with DisposerMixin {
399399
if (_service == null) return false;
400400

401401
final mainIsolate = _mainIsolate;
402+
if (mainIsolate == null) return false;
403+
404+
final isolate = await _isolateManager.isolateState(mainIsolate).isolate;
405+
if (_mainIsolate != mainIsolate) return false;
406+
402407
Future<bool> callExtension() async {
403408
if (_mainIsolate != mainIsolate) return false;
404409

@@ -423,18 +428,18 @@ final class ServiceExtensionManager with DisposerMixin {
423428
await call(isolate.id, value);
424429
});
425430
} else {
426-
await call(mainIsolate?.id, value);
431+
await call(mainIsolate.id, value);
427432
}
428433
} else if (value is String) {
429434
await _service!.callServiceExtension(
430435
name,
431-
isolateId: mainIsolate?.id,
436+
isolateId: mainIsolate.id,
432437
args: {'value': value},
433438
);
434439
} else if (value is double) {
435440
await _service!.callServiceExtension(
436441
name,
437-
isolateId: mainIsolate?.id!,
442+
isolateId: mainIsolate.id,
438443
// The param name for a numeric service extension will be the last part
439444
// of the extension name (ext.flutter.extensionName => extensionName).
440445
args: {name.substring(name.lastIndexOf('.') + 1): value},
@@ -451,11 +456,6 @@ final class ServiceExtensionManager with DisposerMixin {
451456
return true;
452457
}
453458

454-
if (mainIsolate == null) return false;
455-
456-
final isolate = await _isolateManager.isolateState(mainIsolate).isolate;
457-
if (_mainIsolate != mainIsolate) return false;
458-
459459
// Do not try to call Dart IO extensions for a paused isolate.
460460
if (extensions.isDartIoExtension(name) &&
461461
isolate?.pauseEvent?.kind?.contains('Pause') == true) {

0 commit comments

Comments
 (0)