8#ifndef HPP_ALIB_THREADS_PROMISE
9#define HPP_ALIB_THREADS_PROMISE 1
15#include "alib/time/ticks.hpp"
25namespace alib {
namespace threads {
116 "Promise not fulfilled on destruction." )
118 "Promise not awaited on destruction." )
146 <<
"Promise was already fulfilled. Repeated calls not allowed.\n"
147 <<
" This call: " << ci<<
"\n"
166 <<
"Promise was already awaited. Repeated calls not allowed.\n"
174 while (
future.wait_for( (waitDuration - waitTimer.
Age()).Export() )
175 != std::future_status::ready )
177 if ( waitTimer.
Age() < waitDuration )
181 msg <<
"Waiting for a Promise since " << overallTimer.
Age()
183 .InAbsoluteMilliseconds() <<
"ms"
186 DbgSimpleALibMsg( ci, 1,
"THREADS", msg );
208 <<
"Promise was already awaited. Repeated calls not allowed.\n"
211 if (
future.wait_for(maxWaitTimeSpan) == std::future_status::timeout )
219 State WaitFor(
const Ticks::Duration::TDuration& maxWaitTimeSpan )
221 return future.wait_for(maxWaitTimeSpan) == std::future_status::timeout
235 {
return WaitFor( maxWaitTimeSpan.Export(), ci ); }
238 {
return WaitFor( maxWaitTimeSpan.Export() ); }
252 <<
"Promise was already awaited. Repeated calls not allowed.\n"
255 if (
future.wait_until(wakeUpTime.
Export()) == std::future_status::timeout )
265 return future.wait_until(wakeUpTime.
Export()) == std::future_status::timeout
void Fulfill(const CallerInfo &ci, State state=State::OK)
State WaitFor(const Ticks::Duration::TDuration &maxWaitTimeSpan, const CallerInfo &ci)
lang::CallerInfo DbgWaitCI
std::promise< State > promise
Used for implementation.
State Wait(ALIB_DBG_TAKE_CI)
void DbgOmitDestructionWarning()
Promise()
Default constructor. Sets the state to State::Unfulfilled.
State WaitFor(const Ticks::Duration &maxWaitTimeSpan, const CallerInfo &ci)
@ Unfulfilled
The state after construction.
@ Error
A default error state. (Use-case dependent.)
@ OK
The default state of successful fulfillment.
std::future< State > future
Used for implementation.
lang::CallerInfo DbgFulfillCI
Ticks::Duration DbgWaitTimeLimit
State WaitUntil(const Ticks &wakeUpTime, const CallerInfo &ci)
TTimePoint Export() const
#define ALIB_ASSERT_MODULE(modulename)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT_WARNING(cond,...)
const char * File
The name of the source file as given by compiler.
int Line
The line number within File.