CancellationTokenSource

public class CancellationTokenSource


Creates a new CancellationToken or cancels one that has already created. There is a 1:1 CancellationTokenSource to CancellationToken relationship.

To create a CancellationToken, create a CancellationTokenSource first and then call getToken to get the CancellationToken for this CancellationTokenSource.

Summary

Public constructors

Creates a new CancellationTokenSource instance.

Public methods

void

Cancels the CancellationToken if cancellation has not been requested yet.

@NonNull CancellationToken

Gets the CancellationToken for this CancellationTokenSource.

Public constructors

CancellationTokenSource

public CancellationTokenSource()

Creates a new CancellationTokenSource instance.

Public methods

cancel

public void cancel()

Cancels the CancellationToken if cancellation has not been requested yet.

getToken

public @NonNull CancellationToken getToken()

Gets the CancellationToken for this CancellationTokenSource.

Returns
@NonNull CancellationToken

the CancellationToken that can be passed to asynchronous Task to cancel the Task.