Seastar
High performance C++ framework for concurrent servers
Classes | Public Member Functions | List of all members
seastar::abort_source Class Reference

Detailed Description

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_sourceoperator= (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< subscriptionsubscribe (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
 

Member Function Documentation

◆ get_default_exception()

virtual std::exception_ptr seastar::abort_source::get_default_exception ( ) const
inlinevirtualnoexcept

Returns the default exception type (abort_requested_exception) for this abort source. Overridable by derived classes.

◆ request_abort()

void seastar::abort_source::request_abort ( )
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.

◆ request_abort_ex() [1/2]

template<typename Exception >
void seastar::abort_source::request_abort_ex ( Exception &&  e)
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.

◆ request_abort_ex() [2/2]

void seastar::abort_source::request_abort_ex ( std::exception_ptr  ex)
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.

◆ subscribe()

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 > seastar::abort_source::subscribe ( Func &&  f)
inline

Delays the invocation of the callback f until request_abort() is called.

Returns
optimized_optional containing a subscription that can be used to control the lifetime of the callback 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.


The documentation for this class was generated from the following file: