Async++ unknown
Async (co_await/co_return) code for C++
Loading...
Searching...
No Matches
dispatcher.h
1#pragma once
2#include <functional>
3
4namespace asyncpp {
8 class dispatcher {
9#if defined(ASYNCPP_SO_COMPAT)
10 static thread_local dispatcher* g_current_dispatcher;
11#else
12 static thread_local inline dispatcher* g_current_dispatcher = nullptr;
13#endif
14
15 protected:
16 ~dispatcher() = default;
17
28 static dispatcher* current(dispatcher* disp) {
29 const auto old = g_current_dispatcher;
30 g_current_dispatcher = disp;
31 return old;
32 }
33
34 public:
41 virtual void push(std::function<void()> cbfn) = 0;
48 static dispatcher* current() noexcept { return g_current_dispatcher; }
49 };
50
51#if defined(ASYNCPP_SO_COMPAT_IMPL)
52 thread_local dispatcher* dispatcher::g_current_dispatcher = nullptr;
53#endif
54} // namespace asyncpp
Basic dispatcher interface class.
Definition dispatcher.h:8
static dispatcher * current(dispatcher *disp)
Set the current dispatcher for this thread and reurns the current one. Implementers of dispatchers ca...
Definition dispatcher.h:28
static dispatcher * current() noexcept
Definition dispatcher.h:48
virtual void push(std::function< void()> cbfn)=0