mirror of
https://github.com/matrix-construct/construct
synced 2025-02-19 18:20:19 +01:00
ircd::ctx::pool: Add async() member functions to post to a pool.
This commit is contained in:
parent
284bad47e9
commit
9de2b00e34
1 changed files with 41 additions and 0 deletions
|
@ -48,10 +48,51 @@ struct pool
|
|||
void del(const size_t & = 1);
|
||||
|
||||
void operator()(closure);
|
||||
template<class F, class... A> future_void<F, A...> async(F&&, A&&...);
|
||||
template<class F, class... A> future_value<F, A...> async(F&&, A&&...);
|
||||
|
||||
pool(const size_t & = 0, const size_t &stack_size = DEFAULT_STACK_SIZE);
|
||||
~pool() noexcept;
|
||||
};
|
||||
|
||||
template<class F,
|
||||
class... A>
|
||||
future_value<F, A...>
|
||||
pool::async(F&& f,
|
||||
A&&... a)
|
||||
{
|
||||
using R = typename std::result_of<F (A...)>::type;
|
||||
|
||||
auto func(std::bind(std::forward<F>(f), std::forward<A>(a)...));
|
||||
auto p(std::make_shared<promise<R>>());
|
||||
(*this)([p, func(std::move(func))]
|
||||
() -> void
|
||||
{
|
||||
p->set_value(func());
|
||||
});
|
||||
|
||||
return future<R>(*p);
|
||||
}
|
||||
|
||||
template<class F,
|
||||
class... A>
|
||||
future_void<F, A...>
|
||||
pool::async(F&& f,
|
||||
A&&... a)
|
||||
{
|
||||
using R = typename std::result_of<F (A...)>::type;
|
||||
|
||||
auto func(std::bind(std::forward<F>(f), std::forward<A>(a)...));
|
||||
auto p(std::make_shared<promise<R>>());
|
||||
(*this)([p, func(std::move(func))]
|
||||
() -> void
|
||||
{
|
||||
func();
|
||||
p->set_value();
|
||||
});
|
||||
|
||||
return future<R>(*p);
|
||||
}
|
||||
|
||||
} // namespace ctx
|
||||
} // namespace ircd
|
||||
|
|
Loading…
Add table
Reference in a new issue