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

#include <albert/backgroundexecutor.h>

Description

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

Convenience class for recurring indexing tasks.

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

Public Member Functions

 BackgroundExecutor ()=default
 Constructs the background executor.
 
 ~BackgroundExecutor ()
 Destructs the background executor.
 
void run ()
 Run or schedule a rerun of the task.
 
void stop ()
 Stops the current execution.
 
bool isRunning () const
 Returns true if the asynchronous computation is currently running; otherwise returns false.
 
void waitForFinished ()
 Blocks until the current task finished.
 
takeResult ()
 Takes the result from the future.
 

Public Attributes

std::function< T(const bool &abort)> parallel
 The task to be executed in a thread.
 
std::function< void()> finish
 The finish callback.
 

Constructor & Destructor Documentation

◆ BackgroundExecutor()

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

Constructs the background executor.

◆ ~BackgroundExecutor()

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

Destructs the background executor.

Silently blocks execution until a running task is finished. See isRunning() and waitForFinished().

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.

◆ stop()

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

Stops the current execution.

◆ takeResult()

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

Takes the result from the future.

Must be called from finish only. Rethrows any exception thrown in parallel.

◆ waitForFinished()

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

Blocks until the current task finished.

Member Data Documentation

◆ finish

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

The finish callback.

When the parallel function finished, this function will be called in the main thread. Use BackgroundExecutor::takeResult to get the results returned from parallel.

◆ parallel

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

The task to be executed in a thread.

Return the results of type T. Abort if abort is true.


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