MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mtcore::thread::SendOption< S, Callback > Struct Template Reference

Select option to send a message. More...

#include <select.hpp>

Collaboration diagram for mtcore::thread::SendOption< S, Callback >:

Public Types

using Message = typename S::Message
 

Public Member Functions

Result< void, SelectOptionErrorsattempt ()
 
bool prevents_deadlock () const noexcept
 Checks if option is still valid (invalidates on channel close)
 

Public Attributes

S & channel
 
Message m
 
Callback callback
 
bool valid = true
 

Detailed Description

template<Sender S, typename Callback>
struct mtcore::thread::SendOption< S, Callback >

Select option to send a message.

Calls a callback on send

Template Parameters
SSender to wait on
CallbackCallback to call. Should be compatible with std::function<void (void)>

Definition at line 113 of file select.hpp.

Member Typedef Documentation

◆ Message

template<Sender S, typename Callback>
using mtcore::thread::SendOption< S, Callback >::Message = typename S::Message

Definition at line 114 of file select.hpp.

Member Function Documentation

◆ attempt()

template<Sender S, typename Callback>
Result< void, SelectOptionErrors > mtcore::thread::SendOption< S, Callback >::attempt ( )
inline

Definition at line 120 of file select.hpp.

120 {
121 auto res = channel.try_send(m);
122 if (res.is_success()) {
123 callback();
124 return success();
125 }
126 auto err = res.error().code;
127 if constexpr (has_closed_error<std::remove_const_t<decltype(err)>>) {
128 if (err == decltype(err)::CHANNEL_CLOSED) {
129 valid = false;
131 }
132 }
134 }
Success< void > success()
Creates a successful void Result object.
Definition result.hpp:398
Error< Underlying > error(Underlying err)
Creates an error.
Definition result.hpp:425
Select option to send a message.
Definition select.hpp:113
Here is the call graph for this function:

◆ prevents_deadlock()

template<Sender S, typename Callback>
bool mtcore::thread::SendOption< S, Callback >::prevents_deadlock ( ) const
inlinenodiscardnoexcept

Checks if option is still valid (invalidates on channel close)

Definition at line 137 of file select.hpp.

137{ return valid; }

Member Data Documentation

◆ callback

template<Sender S, typename Callback>
Callback mtcore::thread::SendOption< S, Callback >::callback

Definition at line 117 of file select.hpp.

◆ channel

template<Sender S, typename Callback>
S& mtcore::thread::SendOption< S, Callback >::channel

Definition at line 115 of file select.hpp.

◆ m

template<Sender S, typename Callback>
Message mtcore::thread::SendOption< S, Callback >::m

Definition at line 116 of file select.hpp.

◆ valid

template<Sender S, typename Callback>
bool mtcore::thread::SendOption< S, Callback >::valid = true

Definition at line 118 of file select.hpp.


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