trantor
Non-blocking I/O cross-platform TCP network library, using C++14
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>
21namespace trantor
22{
28class 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
This class is a pure virtual class that can be implemented as a SerialTaskQueue or a ConcurrentTaskQu...
Definition TaskQueue.h:29
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
Definition EventLoop.h:34