Skip to content

AsyncCommand cancellation issue. #4

Closed
@ChebanovDD

Description

@ChebanovDD

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions