PMT Renovated main-branch
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
Helper::AsyncManager< RetT > Class Template Reference

A simple class for easily managing asynchronous operations. More...

#include <management.hpp>

Public Member Functions

template<typename... Args>
void addProcess (Args &&...args)
 Add new processes.
 
void startAll ()
 Start all defined threads.
 
std::vector< RetT > getResults ()
 Get results of threads.
 
bool resultsReceived () const
 Check the status of the results being provided.
 
bool finalize () const
 Print results. getResults() must have been called beforehand.
 
bool operator() ()
 Calls getResults() and finalize() .
 

Public Attributes

bool print = true
 Turn printing on/off.
 

Detailed Description

template<typename RetT>
class Helper::AsyncManager< RetT >

A simple class for easily managing asynchronous operations.

int some_func(int x) {
return x;
}
int main(void) {
AsyncManager<int> a_manager;
// Define threads.
a_manager.addProcess(&some_func, 2);
a_manager.addProcess(&some_func, 102);
a_manager.addProcess(&some_func, 84923);
// Start threads.
a_manager.startAll();
// Get results and print.
auto vec = a_manager.getResults();
std::cout << vec << std::endl;
// Results are already get?
if (a_manager.resultsReceived())
std::cout << "Result are already get." << std::endl;
// ONLY FOR std::pair<std::string, bool> LIKE RETURN TYPES //
// Get result and print.
a_manager.finalize();
// getResults() + finalize()
a_manager();
return 0;
}
A simple class for easily managing asynchronous operations.
Definition management.hpp:146
void addProcess(Args &&...args)
Add new processes.
Definition management.hpp:179
void startAll()
Start all defined threads.
Definition management.hpp:185
bool resultsReceived() const
Check the status of the results being provided.
Definition management.hpp:208
std::vector< RetT > getResults()
Get results of threads.
Definition management.hpp:199
bool finalize() const
Print results. getResults() must have been called beforehand.
Definition management.hpp:215
T endl(T... args)
T sleep_for(T... args)
Template Parameters
RetTReturn type of target function(s).

Member Function Documentation

◆ addProcess()

template<typename RetT >
template<typename... Args>
void Helper::AsyncManager< RetT >::addProcess ( Args &&...  args)
inline

Add new processes.

class SomeClass {
public:
int func(int x) {
return x;
}
SomeClass() {
AsyncManager<int> a_manager;
a_manager.addProcess(&SomeClass::func, this, 2);
a_manager.addProcess(&SomeClass::func, this, 392);
a_manager.addProcess(&SomeClass::func, this, 950302);
// ...
}
};
Parameters
argsstd::thread like input.

◆ finalize()

template<typename RetT >
bool Helper::AsyncManager< RetT >::finalize ( ) const
inline

Print results. getResults() must have been called beforehand.

Note
It is only available for return types like std::pair<std::string, bool> and similar types.

◆ getResults()

template<typename RetT >
std::vector< RetT > Helper::AsyncManager< RetT >::getResults ( )
inline

Get results of threads.

Note
It waits for unfinished threads.
Returns
List of results.

◆ operator()()

template<typename RetT >
bool Helper::AsyncManager< RetT >::operator() ( )
inline

Calls getResults() and finalize() .

// ...
a_manager();
Note
It is only available for return types like std::pair<std::string, bool> and similar types.

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