Seastar
High performance C++ framework for concurrent servers
|
Facility to communicate a cancellation request to a fiber. Callbacks can be registered with the abort_source
, which are called atomically with a call to request_abort().
#include <seastar/core/abort_source.hh>
Classes | |
class | subscription |
Public Member Functions | |
abort_source (abort_source &&)=default | |
abort_source & | operator= (abort_source &&)=default |
template<typename Func > requires (std::is_nothrow_invocable_r_v<void, Func, const std::optional<std::exception_ptr>&> || std::is_nothrow_invocable_r_v<void, Func>) | |
optimized_optional< subscription > | subscribe (Func &&f) |
void | request_abort () noexcept |
void | request_abort_ex (std::exception_ptr ex) noexcept |
template<typename Exception > | |
void | request_abort_ex (Exception &&e) noexcept |
bool | abort_requested () const noexcept |
Returns whether an abort has been requested. | |
void | check () const |
Throws a abort_requested_exception if cancellation has been requested. | |
const std::exception_ptr & | abort_requested_exception_ptr () const noexcept |
Returns an exception with which an abort was requested. | |
virtual std::exception_ptr | get_default_exception () const noexcept |
|
inlinevirtualnoexcept |
Returns the default exception type (abort_requested_exception) for this abort source. Overridable by derived classes.
|
inlinenoexcept |
Requests that the target operation be aborted. Current subscriptions are invoked inline with this call with a disengaged optional<std::exception_ptr>, and no new ones can be registered.
|
inlinenoexcept |
Requests that the target operation be aborted with a given Exception
object. Current subscriptions are invoked inline with this exception, converted to std::exception_ptr, and no new ones can be registered.
|
inlinenoexcept |
Requests that the target operation be aborted with a given exception_ptr
. Current subscriptions are invoked inline with this exception, and no new ones can be registered.
|
inline |
Delays the invocation of the callback f
until request_abort() is called.
f
.Note: the returned optimized_optional evaluates to true
if and only if abort_requested() is false
at the time subscribe is called, and therefore the subscription is linked to the abort_source subscriptions list.
Once request_abort() is called or the subscription's on_abort() method are called, the callback f
is called (exactly once), and the subscription is unlinked from the about_source, causing the optimized_optional to evaluate to false
.
The returned optimized_optional would initially evaluate to false
if request_abort() was already called. In this case, an unlinked subscription is returned as optimized_optional. That subscription still allows the user to call on_abort() to invoke the callback f
.