Last active
October 13, 2016 18:29
-
-
Save jaredhoberock/e4aacafe8d66af6458359ff5b7775fcf to your computer and use it in GitHub Desktop.
Example of an executor whose asynchronous operations always return a ready future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
class always_ready_future | |
{ | |
public: | |
always_ready_future(T&& value) | |
: value_(std::move(value)) | |
{} | |
// never blocks | |
void wait(){} | |
// never blocks | |
T get() | |
{ | |
return std::move(value_); | |
} | |
private: | |
T value_; | |
}; | |
template<class BulkExecutor> | |
struct eager_executor | |
{ | |
template<class T> | |
using future = always_ready_future<T>; | |
using shape_type = executor_shape_t<BulkExecutor>; | |
// bulk_async_execute() always calls the adapted executor's synchronous operations | |
// and returns the result as an (always ready) future | |
template<class Function, class ResultFactory, class SharedFactory> | |
always_ready_future<auto> bulk_async_execute(Function f, shape_type shape, ResultFactory result_factory, SharedFactory shared_factory) | |
{ | |
auto result = execution::bulk_sync_execute(exec_, f, shape, result_factory, shared_factory); | |
return always_ready_future<decltype(result)>(std::move(result)); | |
} | |
BulkExecutor exec_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment