Robowflex  v0.1
Making MoveIt Easy
robowflex::Pool::Job< RT > Class Template Reference

A job that returns RT. More...

#include <pool.h>

+ Inheritance diagram for robowflex::Pool::Job< RT >:

Public Member Functions

template<typename... Args>
 Job (const std::function< RT(Args...)> &&function, Args &&... args)
 Constructor. More...
 
void execute () override
 Executes the task and stores the result in future_. More...
 
RT get ()
 Blocking call to retrieve the result of the function. Note that if the job was canceled it is not guaranteed that this function will return, as the job might never be executed. More...
 
void wait () const
 Waits until result of the job is available. More...
 
bool isDone () const
 Returns true if the task is done, false otherwise. More...
 
bool waitFor (double time) const
 Waits for a number of seconds to see if the task completes. More...
 
- Public Member Functions inherited from robowflex::Pool::Joblet
void cancel ()
 Cancels this job. More...
 
bool isCancled () const
 Checks if this job has been cancled. More...
 

Private Attributes

std::function< RT()> function_
 Bound function to execute. More...
 
std::packaged_task< RT()> task_
 Task of function. More...
 
std::future< RT > future_
 Future of function result. More...
 

Additional Inherited Members

- Protected Attributes inherited from robowflex::Pool::Joblet
bool canceled {false}
 Whether the job is cancled or not. More...
 

Detailed Description

template<typename RT>
class robowflex::Pool::Job< RT >

A job that returns RT.

Template Parameters
RTReturn type of function to be executed.

Definition at line 123 of file pool.h.

Constructor & Destructor Documentation

◆ Job()

template<typename RT >
template<typename... Args>
robowflex::Pool::Job< RT >::Job ( const std::function< RT(Args...)> &&  function,
Args &&...  args 
)
inline

Constructor.

Parameters
[in]functionFunction to execute.
[in]argsArguments to function.
Template Parameters
ArgsTypes of the function arguments.

Definition at line 132 of file pool.h.

133  : function_(std::bind(function, args...)), task_(function_), future_(task_.get_future())
134  {
135  }
T bind(T... args)
std::future< RT > future_
Future of function result.
Definition: pool.h:180
std::function< RT()> function_
Bound function to execute.
Definition: pool.h:178
std::packaged_task< RT()> task_
Task of function.
Definition: pool.h:179
T get_future(T... args)

Member Function Documentation

◆ execute()

template<typename RT >
void robowflex::Pool::Job< RT >::execute ( )
inlineoverridevirtual

Executes the task and stores the result in future_.

Implements robowflex::Pool::Joblet.

Definition at line 139 of file pool.h.

140  {
141  task_();
142  }

◆ get()

template<typename RT >
RT robowflex::Pool::Job< RT >::get ( )
inline

Blocking call to retrieve the result of the function. Note that if the job was canceled it is not guaranteed that this function will return, as the job might never be executed.

Returns
The result of the job.

Definition at line 149 of file pool.h.

150  {
151  return future_.get();
152  }
T get(T... args)

◆ isDone()

template<typename RT >
bool robowflex::Pool::Job< RT >::isDone ( ) const
inline

Returns true if the task is done, false otherwise.

Returns
True if task is done, false otherwise.

Definition at line 164 of file pool.h.

165  {
166  return waitFor(0);
167  }
bool waitFor(double time) const
Waits for a number of seconds to see if the task completes.
Definition: pool.h:172

◆ wait()

template<typename RT >
void robowflex::Pool::Job< RT >::wait ( ) const
inline

Waits until result of the job is available.

Definition at line 156 of file pool.h.

157  {
158  future_.wait();
159  }
T wait(T... args)

◆ waitFor()

template<typename RT >
bool robowflex::Pool::Job< RT >::waitFor ( double  time) const
inline

Waits for a number of seconds to see if the task completes.

Returns
True if task is complete, false otherwise.

Definition at line 172 of file pool.h.

173  {
174  return future_.wait_for(std::chrono::duration<double>(time)) == std::future_status::ready;
175  }
T wait_for(T... args)

Member Data Documentation

◆ function_

template<typename RT >
std::function<RT()> robowflex::Pool::Job< RT >::function_
private

Bound function to execute.

Definition at line 178 of file pool.h.

◆ future_

template<typename RT >
std::future<RT> robowflex::Pool::Job< RT >::future_
private

Future of function result.

Definition at line 180 of file pool.h.

◆ task_

template<typename RT >
std::packaged_task<RT()> robowflex::Pool::Job< RT >::task_
private

Task of function.

Definition at line 179 of file pool.h.


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