Skip to content

AsyncCommand cancellation issue. #4

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

Closed
ChebanovDD opened this issue May 4, 2023 · 0 comments · Fixed by #7
Closed

AsyncCommand cancellation issue. #4

ChebanovDD opened this issue May 4, 2023 · 0 comments · Fixed by #7
Assignees
Labels
bug Something isn't working

Comments

@ChebanovDD
Copy link
Collaborator

Bug description

When multiple async commands are running at the same time, cancellation only works for the last async command.

Minimal reproduction code and steps

  1. Execute StartCommand several times
  2. Execute CancelCommand
public MainViewModel()
{
    StartCommand = new AsyncCommand(StartAsync).WithCancellation();
    CancelCommand = new Command(() => StartCommand.Cancel());
}

public IAsyncCommand StartCommand { get; }

public ICommand CancelCommand { get; }

private async UniTask StartAsync(CancellationToken cancellationToken)
{
    while (cancellationToken.IsCancellationRequested == false)
    {
        await UniTask.Delay(1000, cancellationToken: cancellationToken);
        Debug.Log(nameof(StartAsync));
    }
}

Current result

Only the last command will be canceled.

Expected result

All running commands should be canceled.

@ChebanovDD ChebanovDD added the bug Something isn't working label May 4, 2023
@ChebanovDD ChebanovDD self-assigned this May 4, 2023
ChebanovDD added a commit that referenced this issue May 4, 2023
@ChebanovDD ChebanovDD mentioned this issue May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant