14 #include <core/Future.h>
16 #include <parallelism/Barrier.h>
17 #include <tasking/Event_mthread.h>
101 template <
class ErrorType = mel::core::WaitErrorAsException,
class T>
105 EVENTMT_WAIT_INFINITE ) noexcept( std::
109 WaitErrorNoException>::
112 constexpr
bool NotuseException =
113 std::is_same<ErrorType,
115 constexpr
bool UseException =
116 std::is_same<ErrorType,
118 static_assert( NotuseException || UseException,
119 "WaitForFutureMThread must specify either "
120 "WaitErrorNoException or WaitErrorAsException" );
121 using ::mel::tasking::Event_mthread;
124 _Receiver() : mEvent(
false,
false ) {}
129 EEventMTWaitCode eventResult;
131 eventResult = mEvent.waitAndDo(
134 evId = f.subscribeCallback(
135 [
this](
typename futT::ValueType& )
136 { this->mEvent.set(); } );
142 switch ( eventResult )
144 case EEventMTWaitCode::EVENTMT_WAIT_OK:
145 return ::mel::core::EWaitError::FUTURE_WAIT_OK;
146 case EEventMTWaitCode::EVENTMT_WAIT_KILL:
148 return ::mel::core::EWaitError::
149 FUTURE_RECEIVED_KILL_SIGNAL;
151 case EEventMTWaitCode::EVENTMT_WAIT_TIMEOUT:
152 return ::mel::core::EWaitError::FUTURE_WAIT_TIMEOUT;
155 return ::mel::core::EWaitError::
165 auto receiver = std::make_unique<_Receiver>();
167 if constexpr ( NotuseException )
171 case ::mel::core::EWaitError::FUTURE_WAIT_OK:
173 case ::mel::core::EWaitError::FUTURE_RECEIVED_KILL_SIGNAL:
177 "Kill signal received" ) ) );
179 case ::mel::core::EWaitError::FUTURE_WAIT_TIMEOUT:
183 "Time out exceeded" ) ) );
185 case ::mel::core::EWaitError::FUTURE_UNKNOWN_ERROR:
189 "Unknown error" ) ) );
195 "Unknown error" ) ) );
203 case ::mel::core::EWaitError::FUTURE_WAIT_OK:
204 if ( f.getValue().isValid() )
205 return ::mel::core::WaitResult( f );
207 std::rethrow_exception( f.getValue().error() );
209 case ::mel::core::EWaitError::FUTURE_RECEIVED_KILL_SIGNAL:
212 "Kill signal received" );
214 case ::mel::core::EWaitError::FUTURE_WAIT_TIMEOUT:
217 "Time out exceeded" );
219 case ::mel::core::EWaitError::FUTURE_UNKNOWN_ERROR:
240 const ::mel::parallelism::Barrier& b,
241 unsigned int msecs = ::mel::tasking::EVENTMT_WAIT_INFINITE );
int unsubscribeCallback(int id) const
Unsubscribe given callback.
Definition: Future.h:695
Represents a value that maybe is not present at the current moment.
Definition: Future.h:750
Exception class generated by WaitResult when wait for future gets an error.
Definition: Future.h:882
Wrapper for future value after wait.
Definition: Future.h:902
class similar to Event Class (which is for thread synchronization) but for Process (with Microthread ...
Definition: Event_mthread.h:167
base functionalities
Definition: Callback_Impl.h:13
EWaitError
Generic result error codes for future waiting.
Definition: Future.h:29
@ FUTURE_RECEIVED_KILL_SIGNAL
@ FUTURE_WAIT_TIMEOUT
Time out expired while waiting for Future.
@ FUTURE_UNKNOWN_ERROR
Unknow error while waiting for Future.
MEL_API ::mel::tasking::EEventMTWaitCode waitForBarrierMThread(const ::mel::parallelism::Barrier &b, unsigned int msecs=::mel::tasking::EVENTMT_WAIT_INFINITE)
Wait for a barrier to activated in the context of a microthread.
::mel::core::WaitResult< T > waitForFutureMThread(const mel::core::Future< T > &f, unsigned int msecs=EVENTMT_WAIT_INFINITE) noexcept(std::is_same< ErrorType, ::mel::core::WaitErrorNoException >::value)
Waits for future completion, returning a wapper around the internal vale.
Definition: utilities.h:102
Definition: Callback_Impl.h:11
Policy for treating error as exception in future wait functions.
Definition: Future.h:936
Policy for not treating error as exception in future wait functions.
Definition: Future.h:941