Skip to content

Calling ToCancellationToken on completed task throws ObjectDisposedException #724

Description

@Trarizon

When calling ToCancellationToken on a completed task, an exception occurred

UniTask.CompletedTask.ToCancellationToken();
// System.ObjectDisposedException: The CancellationTokenSource has been disposed.

The source code of ToCancellationToken is

var cts = new CancellationTokenSource();
Core(task, cts).Forget();
return cts.Token;

If the task is completed, cts will be disposed synchronously in Core() and then accessing cts.Token causes ObjectDisposeException

Is this a bug or by design?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions