DASH  0.3.0
dash::Future< void > Class Template Reference

Overload of dash::Future for operations returning void. More...

#include <Future.h>

Public Types

typedef Future< void > self_t
 
typedef std::function< void(void)> get_func_t
 Callback function to wait for completion. More...
 
typedef std::function< bool(void)> test_func_t
 Callback function to test for completion. More...
 
typedef std::function< void(void)> destroy_func_t
 Callback function called upon destruction. More...
 

Public Member Functions

 Future () noexcept=default
 Default constructor, creates a future that invalid. More...
 
 Future (get_func_t get_func) noexcept
 Create a future using a function that returns the value. More...
 
 Future (get_func_t get_func, test_func_t test_func) noexcept
 Create a future using a function that returns the value and a function to test whether the result value is available. More...
 
 Future (get_func_t get_func, test_func_t test_func, destroy_func_t destroy_func) noexcept
 Create a future using a function to wait for completion and a function to test for completion, plus a function to be called upon destruction of the future. More...
 
 Future (const self_t &other)=delete
 Copy construction is not permited. More...
 
 Future (self_t &&other) noexcept
 Move constructor. More...
 
 ~Future ()
 Destructor. More...
 
self_toperator= (const self_t &other)=delete
 Copy assignment is not permited. More...
 
self_toperator= (self_t &&other) noexcept
 Move assignment. More...
 
void wait ()
 Wait for the value to become available. More...
 
bool test ()
 Test whether the operation has completed. More...
 
void get ()
 Return after making sure that the operation is completed. More...
 
bool valid () noexcept
 Check whether the future is valid, i.e., a function to wait for completion has been provided. More...
 

Friends

template<typename ResultT_ >
std::ostream & operator<< (std::ostream &os, const Future< ResultT_ > &future)
 

Detailed Description

template<>
class dash::Future< void >

Overload of dash::Future for operations returning void.

Definition at line 235 of file Future.h.

Member Typedef Documentation

◆ destroy_func_t

typedef std::function<void (void)> dash::Future< void >::destroy_func_t

Callback function called upon destruction.

Definition at line 253 of file Future.h.

◆ get_func_t

typedef std::function<void (void)> dash::Future< void >::get_func_t

Callback function to wait for completion.

Definition at line 243 of file Future.h.

◆ test_func_t

typedef std::function<bool (void)> dash::Future< void >::test_func_t

Callback function to test for completion.

Definition at line 248 of file Future.h.

Constructor & Destructor Documentation

◆ Future() [1/6]

dash::Future< void >::Future ( )
defaultnoexcept

Default constructor, creates a future that invalid.

See also
dash::Future::valid

◆ Future() [2/6]

dash::Future< void >::Future ( get_func_t  get_func)
inlinenoexcept

Create a future using a function that returns the value.

Parameters
get_funcFunction blocking until the operation is complete.

Definition at line 292 of file Future.h.

293  : _get_func(std::move(get_func))
294  {
295  }

◆ Future() [3/6]

dash::Future< void >::Future ( get_func_t  get_func,
test_func_t  test_func 
)
inlinenoexcept

Create a future using a function that returns the value and a function to test whether the result value is available.

Parameters
get_funcFunction blocking until the operation is complete.
test_funcFunction returning true if the value is available.

Definition at line 304 of file Future.h.

305  : _get_func(std::move(get_func))
306  , _test_func(std::move(test_func))
307  {
308  }

◆ Future() [4/6]

dash::Future< void >::Future ( get_func_t  get_func,
test_func_t  test_func,
destroy_func_t  destroy_func 
)
inlinenoexcept

Create a future using a function to wait for completion and a function to test for completion, plus a function to be called upon destruction of the future.

Parameters
get_funcFunction to wait for completion.
test_funcFunction returning true if the operation is complete.
destroy_funcFunction called upon destruction of the future.

Definition at line 319 of file Future.h.

References dash::Future< ResultT >::Future().

323  : _get_func(std::move(get_func)),
324  _test_func(std::move(test_func)),
325  _destroy_func(std::move(destroy_func))
326  { }

◆ Future() [5/6]

dash::Future< void >::Future ( const self_t other)
delete

Copy construction is not permited.

◆ Future() [6/6]

dash::Future< void >::Future ( self_t &&  other)
inlinenoexcept

Move constructor.

Definition at line 336 of file Future.h.

337  {
338  *this = std::move(other);
339  }

◆ ~Future()

dash::Future< void >::~Future ( )
inline

Destructor.

Calls the destroy_func passed to the constructor, if available.

Definition at line 345 of file Future.h.

References dash::Future< ResultT >::operator=().

345  {
346  if (_destroy_func) {
347  _destroy_func();
348  }
349  }

Member Function Documentation

◆ get()

void dash::Future< void >::get ( )
inline

Return after making sure that the operation is completed.

Definition at line 416 of file Future.h.

References dash::Future< ResultT >::wait().

417  {
418  DASH_LOG_TRACE_VAR("Future.get()", _ready);
419  wait();
420  DASH_LOG_TRACE("Future.get >");
421  }
void wait()
Wait for the value to become available.
Definition: Future.h:372

◆ operator=() [1/2]

self_t& dash::Future< void >::operator= ( const self_t other)
delete

Copy assignment is not permited.

◆ operator=() [2/2]

self_t& dash::Future< void >::operator= ( self_t &&  other)
inlinenoexcept

Move assignment.

Definition at line 359 of file Future.h.

360  {
361  _get_func = std::move(other._get_func);
362  _test_func = std::move(other._test_func);
363  _destroy_func = std::move(other._destroy_func);
364  _ready = other._ready;
365  return *this;
366  }

◆ test()

bool dash::Future< void >::test ( )
inline

Test whether the operation has completed.

Blocks if no test-function has been provided.

Returns
true if the value is available, false otherwise.

Definition at line 396 of file Future.h.

397  {
398  if (!_ready) {
399  if (_test_func) {
400  _ready = _test_func();
401  } else if (_get_func) {
402  _get_func();
403  _ready = true;
404  } else {
405  DASH_THROW(
407  "Future not initialized with function");
408  }
409  }
410  return _ready;
411  }

◆ valid()

bool dash::Future< void >::valid ( )
inlinenoexcept

Check whether the future is valid, i.e., a function to wait for completion has been provided.

Definition at line 427 of file Future.h.

428  {
429  return (_get_func != nullptr);
430  }

◆ wait()

void dash::Future< void >::wait ( )
inline

Wait for the value to become available.

It is safe to call get after this call returned.

Definition at line 372 of file Future.h.

373  {
374  DASH_LOG_TRACE_VAR("Future.wait()", _ready);
375  if (_ready) {
376  return;
377  }
378  if (!_get_func) {
379  DASH_LOG_ERROR("Future.wait()", "No function");
380  DASH_THROW(
382  "Future not initialized with function");
383  }
384  _get_func();
385  _ready = true;
386  DASH_LOG_TRACE_VAR("Future.wait >", _ready);
387  }

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