Commit 199aa7f2 authored by Dominik Charousset's avatar Dominik Charousset

Support ASIO-like post()/dispatch() in multiplexer

parent 3a88e9f7
...@@ -78,7 +78,7 @@ class middleman : public detail::abstract_singleton { ...@@ -78,7 +78,7 @@ class middleman : public detail::abstract_singleton {
*/ */
template <class F> template <class F>
void run_later(F fun) { void run_later(F fun) {
m_backend->dispatch(fun); m_backend->post(fun);
} }
/** /**
...@@ -105,7 +105,7 @@ class middleman : public detail::abstract_singleton { ...@@ -105,7 +105,7 @@ class middleman : public detail::abstract_singleton {
void add_hook(Ts&&... args) { void add_hook(Ts&&... args) {
// if only we could move a unique_ptr into a lambda in C++11 // if only we could move a unique_ptr into a lambda in C++11
auto ptr = new C(std::forward<Ts>(args)...); auto ptr = new C(std::forward<Ts>(args)...);
run_later([=] { backend().dispatch([=] {
ptr->next.swap(m_hooks); ptr->next.swap(m_hooks);
m_hooks.reset(ptr); m_hooks.reset(ptr);
}); });
......
...@@ -122,6 +122,14 @@ class multiplexer { ...@@ -122,6 +122,14 @@ class multiplexer {
fun(); fun();
return; return;
} }
post(std::move(fun));
}
/**
* Invokes @p fun in the multiplexer's event loop.
*/
template <class F>
void post(F fun) {
struct impl : runnable { struct impl : runnable {
F f; F f;
impl(F&& mf) : f(std::move(mf)) { } impl(F&& mf) : f(std::move(mf)) { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment