userver: engine::TaskCancellationToken Class Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
engine::TaskCancellationToken Class Referencefinal

Cancellation token to given task object. More...

#include <userver/engine/task/cancel.hpp>

Public Member Functions

 TaskCancellationToken () noexcept
 Creates an invalid TaskCancellationToken.
 
 TaskCancellationToken (Task &task)
 
 TaskCancellationToken (const TaskCancellationToken &) noexcept
 
 TaskCancellationToken (TaskCancellationToken &&) noexcept
 
TaskCancellationTokenoperator= (const TaskCancellationToken &) noexcept
 
TaskCancellationTokenoperator= (TaskCancellationToken &&) noexcept
 
void RequestCancel ()
 
bool IsValid () const noexcept
 True if this token is associated with a task.
 

Friends

TaskCancellationToken current_task::GetCancellationToken ()
 

Detailed Description

Cancellation token to given task object.

Unlike Task, TaskCancellationToken object doesn't wait for task finish in its destructor. It is allowed to outlive the task object it was created from. However, as long as there is any cancellation token associated with given task, some internal structures of a task will not be freed.

General rule: whenever possible, prefer using engine::Task object instead.

Definition at line 91 of file cancel.hpp.

Constructor & Destructor Documentation

◆ TaskCancellationToken()

engine::TaskCancellationToken::TaskCancellationToken ( Task task)
explicit

Creates a TaskCancellationToken associated with a task. The task must be valid.

Member Function Documentation

◆ RequestCancel()

void engine::TaskCancellationToken::RequestCancel ( )
See also
engine::Task::RequestCancel This method should not be called on invalid TaskCancellationToken

The documentation for this class was generated from the following file: