userver: engine::current_task Namespace Reference
Loading...
Searching...
No Matches
engine::current_task Namespace Reference

Detailed Description

Namespace with functions to work with current task from within it.

Functions

bool IsCancelRequested () noexcept
 
bool ShouldCancel () noexcept
 
TaskCancellationReason CancellationReason () noexcept
 
void CancellationPoint ()
 Throws an exception if a cancellation request for this task is pending.
 
void SetDeadline (Deadline deadline)
 
TaskCancellationToken GetCancellationToken ()
 Return cancellation token for current coroutine.
 
bool IsTaskProcessorThread () noexcept
 
TaskProcessor & GetTaskProcessor ()
 Returns reference to the task processor executing the caller.
 
std::size_t GetStackSize ()
 Returns task coroutine stack size.
 

Function Documentation

◆ CancellationPoint()

void engine::current_task::CancellationPoint ( )

Throws an exception if a cancellation request for this task is pending.

Exceptions
unspecified(non-std) exception if cancellation is pending and not blocked
Warning
cathching this exception without a rethrow in the same scope leads to undefined behavior.
See also
task_cancellation_intro

◆ CancellationReason()

TaskCancellationReason engine::current_task::CancellationReason ( )
noexcept

Returns task cancellation reason for the current task

See also
task_cancellation_intro

◆ IsCancelRequested()

bool engine::current_task::IsCancelRequested ( )
noexcept

Checks for pending cancellation requests, use engine::current_task::ShouldCancel() instead, as the latter respects engine::TaskCancellationBlocker.

See also
task_cancellation_intro

◆ IsTaskProcessorThread()

bool engine::current_task::IsTaskProcessorThread ( )
noexcept

Returns true only when running in userver coroutine environment, i.e. in an engine::TaskProcessor thread.

◆ SetDeadline()

void engine::current_task::SetDeadline ( Deadline deadline)

Set deadline for the current task. The task will be cancelled when the deadline is reached.

◆ ShouldCancel()

bool engine::current_task::ShouldCancel ( )
noexcept