{% setvar book_path %}/android/reference/kotlin/_book.yaml{% endsetvar %} {% include "/android/_dackka-meta-tags.html" %}

CancellationTokenSource

{% setvar page_path %}com/google/android/gms/tasks/CancellationTokenSource.html{% endsetvar %} {% setvar doc_root_path %}/android/reference{% endsetvar %} {% setvar can_switch %}1{% endsetvar %} {% include "android/_kotlin_switcher2.md" %}

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.

See also
CancellationToken

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.