From 11e1cea6667467b2fa5b5791c86b64444420a16a Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 2 Aug 2013 10:28:03 +0200 Subject: Introducing the concept of Future. --- includes/Task.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'includes/Task.h') 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 +#include #ifndef _WIN32 #include #endif @@ -260,6 +261,27 @@ class QueueBase { pthread_cond_t m_cond; }; +template +struct Future { + typedef std::function func_t; + R get(); + func_t m_run; +}; + +template +R Future::get() { + R r; + for (;;) { + try { + r = m_run(); + return r; + } + catch (EAgain & e) { + Task::operationYield(e.getEvent(), Task::INTERRUPTIBLE); + } + } +} + template class Queue : public QueueBase { public: -- cgit v1.2.3