Skip to content

Instantly share code, notes, and snippets.

@jaredhoberock
Last active October 13, 2016 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredhoberock/e4aacafe8d66af6458359ff5b7775fcf to your computer and use it in GitHub Desktop.
Save jaredhoberock/e4aacafe8d66af6458359ff5b7775fcf to your computer and use it in GitHub Desktop.
Example of an executor whose asynchronous operations always return a ready future
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