trantor
Non-blocking I/O cross-platform TCP network library, using C++14
Toggle main menu visibility
Loading...
Searching...
No Matches
TaskQueue.h
Go to the documentation of this file.
1
14
15
#pragma once
16
17
#include "
NonCopyable.h
"
18
#include <functional>
19
#include <future>
20
#include <string>
21
namespace
trantor
22
{
28
class
TaskQueue
:
public
NonCopyable
29
{
30
public
:
31
virtual
void
runTaskInQueue(
const
std::function<
void
()> &task) = 0;
32
virtual
void
runTaskInQueue(std::function<
void
()> &&task) = 0;
33
virtual
std::string getName()
const
34
{
35
return
""
;
36
};
37
44
void
syncTaskInQueue
(
const
std::function<
void
()> &task)
45
{
46
std::promise<int> prom;
47
std::future<int> fut = prom.get_future();
48
runTaskInQueue([&]() {
49
task();
50
prom.set_value(1);
51
});
52
fut.get();
53
};
54
virtual
~TaskQueue
()
55
{
56
}
57
};
58
}
// namespace trantor
NonCopyable.h
trantor::TaskQueue
This class is a pure virtual class that can be implemented as a SerialTaskQueue or a ConcurrentTaskQu...
Definition
TaskQueue.h:29
trantor::TaskQueue::syncTaskInQueue
void syncTaskInQueue(const std::function< void()> &task)
Run a task in the queue synchronously. This means that the task is executed before the method returns...
Definition
TaskQueue.h:44
trantor
Definition
EventLoop.h:34
trantor
utils
TaskQueue.h
Generated by
1.17.0