Skip to content

Remove dead ThrowIfCancellationRequested() in WaitForFullBootAsync#363

Open
jonathanpeppers wants to merge 2 commits intomainfrom
op-remove-dead-throwifcancelled-boot
Open

Remove dead ThrowIfCancellationRequested() in WaitForFullBootAsync#363
jonathanpeppers wants to merge 2 commits intomainfrom
op-remove-dead-throwifcancelled-boot

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented May 8, 2026

Summary

The while (!cancellationToken.IsCancellationRequested) loop condition in WaitForFullBootAsync already guarantees the token is not cancelled at the start of each iteration. The immediately following cancellationToken.ThrowIfCancellationRequested() call was therefore unreachable dead code — it could never throw.

Actual cancellation propagates correctly via OperationCanceledException thrown by the awaited adb call and Task.Delay(..., cancellationToken) when the token fires asynchronously.

The redundant check also misled readers into thinking it provided an extra cancellation checkpoint, when in reality it added nothing.

Changes

  • EmulatorRunner.cs: Removed the dead cancellationToken.ThrowIfCancellationRequested(); line from inside the polling loop in WaitForFullBootAsync. This matches the pattern already used in BootEmulatorAsync's while (newSerial == null) loop, which has no such redundant check.

No behavior change

Cancellation behavior is identical — Task.Delay and the awaited adb calls already handle it.

The while (!cancellationToken.IsCancellationRequested) loop condition
already guarantees the token is not cancelled at the start of each
iteration, making the immediate ThrowIfCancellationRequested() call
unreachable. Actual cancellation propagates via OperationCanceledException
from the awaited adb call and Task.Delay.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 21:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes an in-loop cancellation check in EmulatorRunner.WaitForFullBootAsync, aiming to simplify the boot polling loop used by the Android SDK tooling.

Changes:

  • Removed an in-loop cancellationToken.ThrowIfCancellationRequested() call from the boot polling loop.
  • Adjusted the polling loop body accordingly (but introduced a minor formatting issue).

Comment thread src/Xamarin.Android.Tools.AndroidSdk/Runners/EmulatorRunner.cs
cancellationToken.ThrowIfCancellationRequested ();

var bootCompleted = await adbRunner.GetShellPropertyAsync (serial, "sys.boot_completed", cancellationToken).ConfigureAwait (false);
var bootCompleted= await adbRunner.GetShellPropertyAsync (serial, "sys.boot_completed", cancellationToken).ConfigureAwait (false);
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge. label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants