Albert
Loading...
Searching...
No Matches
albert::BackgroundExecutor< T > Class Template Reference

#include <backgroundexecutor.h>

Detailed Description

template<typename T>
class albert::BackgroundExecutor< T >

Provides a lean interface for recurring indexing tasks.

Takes care of the QtConcurrent boilerplate code to start, abort and schedule restarts of threads.

Template Parameters
TThe type of results this executor produces.

Public Member Functions

 BackgroundExecutor ()
 
 ~BackgroundExecutor ()
 
void run ()
 Run or schedule a rerun of the task. More...
 
bool isRunning () const
 Returns true if the asynchronous computation is currently running; otherwise returns false. More...
 

Public Attributes

std::function< T(const bool &abort)> parallel
 The task that should be executed in background. More...
 
std::function< void(T &&results)> finish
 The results handler. More...
 
std::chrono::milliseconds runtime
 The runtime of the last execution of parallel. More...
 

Constructor & Destructor Documentation

◆ BackgroundExecutor()

template<typename T >
albert::BackgroundExecutor< T >::BackgroundExecutor ( )
inline

◆ ~BackgroundExecutor()

template<typename T >
albert::BackgroundExecutor< T >::~BackgroundExecutor ( )
inline

Member Function Documentation

◆ isRunning()

template<typename T >
bool albert::BackgroundExecutor< T >::isRunning ( ) const
inline

Returns true if the asynchronous computation is currently running; otherwise returns false.

◆ run()

template<typename T >
void albert::BackgroundExecutor< T >::run ( )
inline

Run or schedule a rerun of the task.

If a task is running this function sets the abort flag and schedules a rerun. finish will not be called for the cancelled run.

Member Data Documentation

◆ finish

template<typename T >
std::function<void(T && results)> albert::BackgroundExecutor< T >::finish

The results handler.

When the parallel function finished, this function will be called in the main thread with the results returned by the parallel function.

Parameters
resultsThe results parallel returned.

◆ parallel

template<typename T >
std::function<T(const bool &abort)> albert::BackgroundExecutor< T >::parallel

The task that should be executed in background.

This function is executed in a separate thread.

Parameters
abortThe abort flag
Returns
The results of the task.

◆ runtime

template<typename T >
std::chrono::milliseconds albert::BackgroundExecutor< T >::runtime

The runtime of the last execution of parallel.


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