CancellationTokenSource

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 functions

Unit

Cancels the CancellationToken if cancellation has not been requested yet.

CancellationToken

Gets the CancellationToken for this CancellationTokenSource.

Public constructors

CancellationTokenSource

CancellationTokenSource()

Creates a new CancellationTokenSource instance.

Public functions

cancel

fun cancel(): Unit

Cancels the CancellationToken if cancellation has not been requested yet.

getToken

fun getToken(): CancellationToken

Gets the CancellationToken for this CancellationTokenSource.

Returns
CancellationToken

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