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

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

Functions

bool IsCancelRequested () noexcept
 Checks for pending cancellation requests.
 
bool ShouldCancel () noexcept
 
TaskCancellationReason CancellationReason () noexcept
 Returns task cancellation reason for the current task.
 
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.
 

Detailed Description

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

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.

◆ 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