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

Select option to receive a message and calls a callback on receive. More...

#include <select.hpp>

Collaboration diagram for mtcore::thread::ReceiveOption< R, Callback >:

Public Types

using Message = typename R::Message
 

Public Member Functions

Result< void, SelectOptionErrorsattempt ()
 
bool prevents_deadlock () const noexcept
 

Public Attributes

R & channel
 
Callback callback
 

Detailed Description

template<Receiver R, typename Callback>
struct mtcore::thread::ReceiveOption< R, Callback >

Select option to receive a message and calls a callback on receive.

Template Parameters
RReceiver to receive from
CallbackCallback on receive

Definition at line 286 of file select.hpp.

Member Typedef Documentation

◆ Message

template<Receiver R, typename Callback>
using mtcore::thread::ReceiveOption< R, Callback >::Message = typename R::Message

Definition at line 287 of file select.hpp.

Member Function Documentation

◆ attempt()

template<Receiver R, typename Callback>
Result< void, SelectOptionErrors > mtcore::thread::ReceiveOption< R, Callback >::attempt ( )
inline

Definition at line 291 of file select.hpp.

291 {
292 auto res = channel.try_receive();
293 if (res.is_success()) {
294 callback(res.value());
295 return success();
296 }
298 }
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 receive a message and calls a callback on receive.
Definition select.hpp:286
Here is the call graph for this function:

◆ prevents_deadlock()

template<Receiver R, typename Callback>
bool mtcore::thread::ReceiveOption< R, Callback >::prevents_deadlock ( ) const
inlinenodiscardnoexcept

Definition at line 300 of file select.hpp.

300{ return true; }

Member Data Documentation

◆ callback

template<Receiver R, typename Callback>
Callback mtcore::thread::ReceiveOption< R, Callback >::callback

Definition at line 289 of file select.hpp.

◆ channel

template<Receiver R, typename Callback>
R& mtcore::thread::ReceiveOption< R, Callback >::channel

Definition at line 288 of file select.hpp.


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