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 IsTaskProcessorThread () noexcept
TaskProcessor & GetTaskProcessor ()
 Returns reference to the task processor executing the caller.
std::size_t GetWorkerCount ()
 Get the number of worker threads in the current task processor.
TaskProcessor & GetBlockingTaskProcessor ()
 Returns reference to the blocking task processor.
std::size_t GetStackSize ()
 Returns task coroutine stack size.
bool IsCancelRequested () noexcept
bool ShouldCancel () noexcept
TaskCancellationReason CancellationReason () noexcept
void CancellationPoint ()
 Throws an exception if a cancellation request for this task is pending.
void CancellationPointWeak ()
 Throw a standard exception if cancellation is pending and not blocked.
void SetDeadline (Deadline deadline)
void RequestCancel ()
TaskCancellationToken GetCancellationToken ()
 Return cancellation token for current coroutine.

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
catching this exception without a rethrow in the same scope leads to undefined behavior.
See also
task_cancellation_intro

◆ CancellationPointWeak()

void engine::current_task::CancellationPointWeak ( )

Throw a standard exception if cancellation is pending and not blocked.

Unlike engine::current_task::CancellationPoint, the exception can be handled by catch (const std::exception&) without rethrowing. The cancellation request remains pending; this function does not disable cancellation.

Exceptions
engine::WaitInterruptedExceptionIf engine::current_task::ShouldCancel returns true.
See also
engine::TaskCancellationBlocker

◆ CancellationReason()

TaskCancellationReason engine::current_task::CancellationReason ( )
noexcept

Returns task cancellation reason for the current task

See also
task_cancellation_intro

◆ GetCancellationToken()

TaskCancellationToken engine::current_task::GetCancellationToken ( )

Return cancellation token for current coroutine.

Note
Prefer engine::current_task::RequestCancel in most cases.

◆ GetWorkerCount()

std::size_t engine::current_task::GetWorkerCount ( )

Get the number of worker threads in the current task processor.

The value is configured with the task_processors.*NAME*.worker_threads static option of components::ManagerControllerComponent.

See also
engine::GetWorkerCount

◆ 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.

◆ RequestCancel()

void engine::current_task::RequestCancel ( )

◆ 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()