|
cppcore
A small, portable C++ core library
|
This template class implements a simple loader which runs load requests asynchronously. More...
#include <TAsyncLoader.h>
Public Types | |
| using | LoadFunc = std::function<T()> |
| The load function type, describes the blocking load operation to run asynchronously. | |
Public Member Functions | |
| TAsyncLoader ()=default | |
| The default class constructor. | |
| ~TAsyncLoader () | |
| The class destructor, will wait for all pending loads to finish. | |
| std::future< T > | load (LoadFunc loadFunc) |
| Will start a new load request which runs asynchronously. | |
| size_t | numPending () const |
| Returns the number of load requests which have not finished yet. | |
| bool | hasPending () const |
| Returns true, if there is at least one load request which has not finished yet. | |
| void | waitForAll () |
| Blocks the calling thread until all pending load requests have finished. | |
This template class implements a simple loader which runs load requests asynchronously.
A load request is described by a user-provided load function which returns the loaded resource of type T. Each request is dispatched onto its own worker via std::async and a std::future is handed back to the caller to retrieve the result once it is ready. The loader keeps track of the number of outstanding requests, so you can wait until all of them have finished. The class destructor will block until all pending loads are done, so no request can outlive the loader instance it was started from.
Definition at line 55 of file TAsyncLoader.h.
| using cppcore::TAsyncLoader< T >::LoadFunc = std::function<T()> |
The load function type, describes the blocking load operation to run asynchronously.
Definition at line 58 of file TAsyncLoader.h.
|
default |
|
inline |
The class destructor, will wait for all pending loads to finish.
Definition at line 95 of file TAsyncLoader.h.
References waitForAll().
|
inline |
Returns true, if there is at least one load request which has not finished yet.
Definition at line 139 of file TAsyncLoader.h.
References numPending().
|
inline |
Will start a new load request which runs asynchronously.
| [in] | loadFunc | The load function to execute, must be valid. |
Definition at line 100 of file TAsyncLoader.h.
References TAsyncLoader().
|
inline |
Returns the number of load requests which have not finished yet.
Definition at line 133 of file TAsyncLoader.h.
Referenced by hasPending().
|
inline |
Blocks the calling thread until all pending load requests have finished.
Definition at line 144 of file TAsyncLoader.h.
Referenced by ~TAsyncLoader().