Skip to content

Commit 1af2c68

Browse files
authored
Move EventLoop::runAfter to a template (#193)
1 parent b85e279 commit 1af2c68

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

trantor/net/EventLoop.cc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,28 +202,6 @@ void EventLoop::abortNotInLoopThread()
202202
"thread";
203203
exit(1);
204204
}
205-
void EventLoop::runInLoop(const Func &cb)
206-
{
207-
if (isInLoopThread())
208-
{
209-
cb();
210-
}
211-
else
212-
{
213-
queueInLoop(cb);
214-
}
215-
}
216-
void EventLoop::runInLoop(Func &&cb)
217-
{
218-
if (isInLoopThread())
219-
{
220-
cb();
221-
}
222-
else
223-
{
224-
queueInLoop(std::move(cb));
225-
}
226-
}
227205
void EventLoop::queueInLoop(const Func &cb)
228206
{
229207
funcs_.enqueue(cb);

trantor/net/EventLoop.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,18 @@ class TRANTOR_EXPORT EventLoop : NonCopyable
121121
* @note If the current thread is the thread of the event loop, the function
122122
* f is executed directly before the method exiting.
123123
*/
124-
void runInLoop(const Func &f);
125-
void runInLoop(Func &&f);
124+
template <typename Functor>
125+
inline void runInLoop(Functor &&f)
126+
{
127+
if (isInLoopThread())
128+
{
129+
f();
130+
}
131+
else
132+
{
133+
queueInLoop(std::forward<Functor>(f));
134+
}
135+
}
126136

127137
/**
128138
* @brief Run the function f in the thread of the event loop.

0 commit comments

Comments
 (0)