summaryrefslogtreecommitdiff
path: root/includes/Task.h
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-02 10:28:03 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-02 10:28:03 +0200
commit11e1cea6667467b2fa5b5791c86b64444420a16a (patch)
tree606d63bf2b9fe0b0e5f12ef72bdcced69c45dddf /includes/Task.h
parentc6dd17a1435db36eeaff24e40a7cc212ee7214a0 (diff)
Introducing the concept of Future.
Diffstat (limited to 'includes/Task.h')
-rw-r--r--includes/Task.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/includes/Task.h b/includes/Task.h
index e8aea70..dcbdf91 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -1,6 +1,7 @@
#pragma once
#include <stdlib.h>
+#include <functional>
#ifndef _WIN32
#include <coro.h>
#endif
@@ -260,6 +261,27 @@ class QueueBase {
pthread_cond_t m_cond;
};
+template<class R>
+struct Future {
+ typedef std::function<R()> func_t;
+ R get();
+ func_t m_run;
+};
+
+template<class R>
+R Future<R>::get() {
+ R r;
+ for (;;) {
+ try {
+ r = m_run();
+ return r;
+ }
+ catch (EAgain & e) {
+ Task::operationYield(e.getEvent(), Task::INTERRUPTIBLE);
+ }
+ }
+}
+
template<class T>
class Queue : public QueueBase {
public: