Github   Telegram
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions
cancel.hpp File Reference

Task cancellation helpers. More...

#include <string>
#include <boost/smart_ptr/intrusive_ptr.hpp>
#include <userver/engine/deadline.hpp>
+ Include dependency graph for cancel.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  engine::TaskCancellationBlocker
 
class  engine::TaskCancellationToken
 Cancellation token to given task object. More...
 

Namespaces

namespace  engine
 Asynchronous engine primitives.
 

Enumerations

enum class  engine::TaskCancellationReason {
  engine::kNone ,
  engine::kUserRequest ,
  engine::kDeadline ,
  engine::kOverload ,
  engine::kAbandoned ,
  engine::kShutdown
}
 Task cancellation reason. More...
 

Functions

bool engine::current_task::IsCancelRequested () noexcept
 Checks for pending cancellation requests.
 
bool engine::current_task::ShouldCancel () noexcept
 
TaskCancellationReason engine::current_task::CancellationReason () noexcept
 Returns task cancellation reason for the current task.
 
void engine::current_task::CancellationPoint ()
 Throws an exception if a cancellation request for this task is pending.
 
void engine::current_task::SetDeadline (Deadline deadline)
 
TaskCancellationToken engine::current_task::GetCancellationToken ()
 Return cancellation token for current coroutine.
 
std::string engine::ToString (TaskCancellationReason reason)
 Returns a string representation of a cancellation reason.
 

Detailed Description

Task cancellation helpers.

Definition in file cancel.hpp.

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 whithout a rethrow in the same scope leads to undefined behavior.

◆ 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

Checks for pending non-blocked cancellation requests

See also
TaskCancellationBlocker
Examples
samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp, and samples/tcp_service/tcp_service.cpp.