mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
30
libs/base/task_loop.hpp
Normal file
30
libs/base/task_loop.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
namespace base
|
||||
{
|
||||
class TaskLoop
|
||||
{
|
||||
public:
|
||||
using Task = std::function<void()>;
|
||||
using TaskId = uint64_t;
|
||||
|
||||
static TaskId constexpr kNoId = 0;
|
||||
|
||||
struct PushResult
|
||||
{
|
||||
// Contains true when task is posted successfully.
|
||||
bool m_isSuccess = false;
|
||||
// Contains id of posted task which can be used to access the task to cancel/suspend/etc it.
|
||||
// kNoId is returned for tasks that cannot be accessed.
|
||||
TaskId m_id = kNoId;
|
||||
};
|
||||
|
||||
virtual ~TaskLoop() = default;
|
||||
|
||||
virtual PushResult Push(Task && task) = 0;
|
||||
virtual PushResult Push(Task const & task) = 0;
|
||||
};
|
||||
} // namespace base
|
||||
Reference in New Issue
Block a user