summaryrefslogtreecommitdiff
path: root/zen/async_task.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2015-10-02 14:56:27 +0200
committerDaniel Wilhelm <daniel@wili.li>2015-10-02 14:56:27 +0200
commit19eb73ff543c81c6886725a20dea0060cb0c0c26 (patch)
tree91442c0fdb9cac90c75dfb6bb84def9df297cd77 /zen/async_task.h
parent7.2 (diff)
downloadFreeFileSync-19eb73ff543c81c6886725a20dea0060cb0c0c26.tar.gz
FreeFileSync-19eb73ff543c81c6886725a20dea0060cb0c0c26.tar.bz2
FreeFileSync-19eb73ff543c81c6886725a20dea0060cb0c0c26.zip
7.3
Diffstat (limited to 'zen/async_task.h')
-rw-r--r--zen/async_task.h26
1 files changed, 14 insertions, 12 deletions
diff --git a/zen/async_task.h b/zen/async_task.h
index 5c6f7f6e..d8f489a3 100644
--- a/zen/async_task.h
+++ b/zen/async_task.h
@@ -11,7 +11,6 @@
#include <functional>
#include "thread.h"
#include "scope_guard.h"
-//#include "type_tools.h"
namespace zen
{
@@ -19,25 +18,25 @@ namespace zen
class AsyncTasks
{
public:
- AsyncTasks() : inRecursion(false) {}
+ AsyncTasks() {}
template <class Fun, class Fun2>
- void add(Fun doAsync, Fun2 evalOnGui)
- //equivalent to "evalOnGui(doAsync())"
- // -> doAsync: the usual thread-safety requirements apply!
+ void add(Fun runAsync, Fun2 evalOnGui)
+ //equivalent to "evalOnGui(runAsync())"
+ // -> runAsync: the usual thread-safety requirements apply!
// -> evalOnGui: no thread-safety concerns, but must only reference variables with greater-equal lifetime than the AsyncTask instance!
{
tasks.push_back(zen::runAsync([=]() -> std::function<void()>
{
- auto result = doAsync();
+ auto result = runAsync();
return [=]{ evalOnGui(result); };
}));
}
template <class Fun, class Fun2>
- void add2(Fun doAsync, Fun2 evalOnGui) //for evalOnGui taking no parameters
+ void add2(Fun runAsync, Fun2 evalOnGui) //for evalOnGui taking no parameters
{
- tasks.push_back(zen::runAsync([doAsync, evalOnGui]() -> std::function<void()> { doAsync(); return [evalOnGui]{ evalOnGui(); }; }));
+ tasks.push_back(zen::runAsync([runAsync, evalOnGui]() -> std::function<void()> { runAsync(); return [evalOnGui]{ evalOnGui(); }; }));
}
void evalResults() //call from gui thread repreatedly
@@ -47,9 +46,9 @@ public:
inRecursion = true;
ZEN_ON_SCOPE_EXIT(inRecursion = false);
- tasks.remove_if([](boost::unique_future<std::function<void()>>& ft) -> bool
+ tasks.remove_if([](std::future<std::function<void()>>& ft) -> bool
{
- if (ft.is_ready())
+ if (isReady(ft))
{
(ft.get())();
return true;
@@ -62,8 +61,11 @@ public:
bool empty() const { return tasks.empty(); }
private:
- bool inRecursion;
- std::list<boost::unique_future<std::function<void()>>> tasks;
+ AsyncTasks (const AsyncTasks&) = delete;
+ AsyncTasks& operator=(const AsyncTasks&) = delete;
+
+ bool inRecursion = false;
+ std::list<std::future<std::function<void()>>> tasks;
};
}
bgstack15