mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
mrs_lib::coro::internal::CancellableContinuation Class Reference

Owning coroutine handle supporting cancellation. More...

#include <continuation.hpp>

Public Member Functions

 CancellableContinuation ()=default
 Construct empty continuation.
 
 CancellableContinuation (std::coroutine_handle< void >)=delete
 Cancellable continuation cannot be constructed from type erased handle.
 
template<typename T >
 CancellableContinuation (std::coroutine_handle< T > handle)
 Construct continuation that will own the passed handle.
 
 ~CancellableContinuation ()
 Destroy stored continuation if there is any.
 
 CancellableContinuation (const CancellableContinuation &)=delete
 
CancellableContinuationoperator= (const CancellableContinuation &)=delete
 
 CancellableContinuation (CancellableContinuation &&other) noexcept
 
CancellableContinuationoperator= (CancellableContinuation &&other) noexcept
 
std::coroutine_handle release ()
 Release ownership of the stored handle, giving it to the caller.
 
void cancel_and_destroy ()
 Cancel the stored continuation, if there is any.
 
std::stop_token get_token () const
 Get stop token associated with the continuation.
 

Friends

bool operator== (const CancellableContinuation &continuation, std::nullptr_t)
 Check if the current continuation is empty.
 

Detailed Description

Owning coroutine handle supporting cancellation.

This class can be used to hold coroutine handle as owner. If it is destroyed while holding a handle, it cancels the coroutine.

Coroutine cancellation is performed in a way that should not exhaust stack space.

Constructor & Destructor Documentation

◆ CancellableContinuation()

template<typename T >
mrs_lib::coro::internal::CancellableContinuation::CancellableContinuation ( std::coroutine_handle< T >  handle)
inlineexplicit

Construct continuation that will own the passed handle.

Parameters
handleHandle to the continuation to store.

Member Function Documentation

◆ cancel_and_destroy()

void mrs_lib::coro::internal::CancellableContinuation::cancel_and_destroy ( )
inline

Cancel the stored continuation, if there is any.

The continuation will be empty after this call.

◆ release()

std::coroutine_handle mrs_lib::coro::internal::CancellableContinuation::release ( )
inline

Release ownership of the stored handle, giving it to the caller.

The continuation will be empty after this call.


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