ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
scheduled_task.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <cstdint>
11#include <utility>
12
13namespace threadschedule
14{
15namespace detail
16{
17struct scheduled_task_access;
18}
19
21{
22public:
23 scheduled_task(scheduled_task const&) = default;
24 scheduled_task(scheduled_task&&) noexcept = default;
25 auto operator=(scheduled_task const&) -> scheduled_task& = default;
26 auto operator=(scheduled_task&&) noexcept -> scheduled_task& = default;
27
34 void
36 {
37 impl_.cancel();
38 }
39
43 [[nodiscard]] auto
44 is_cancelled() const noexcept -> bool
45 {
46 return impl_.is_cancelled();
47 }
48
52 [[nodiscard]] auto
53 id() const noexcept -> std::uint64_t
54 {
55 return impl_.id();
56 }
57
58private:
59 explicit scheduled_task(detail::scheduled_task_backend value) : impl_(std::move(value)) {}
60
61 detail::scheduled_task_backend impl_;
62 friend class scheduled_pool;
64};
65
66namespace detail
67{
68struct scheduled_task_access
69{
70 [[nodiscard]] static auto
71 make(scheduled_task_backend value) -> scheduled_task
72 {
73 return scheduled_task(std::move(value));
74 }
75};
76} // namespace detail
77
78} // namespace threadschedule
Copyable handle for a cancellable scheduled task.
Scheduler that executes delayed and periodic tasks on worker threads.
scheduled_task(scheduled_task &&) noexcept=default
friend struct detail::scheduled_task_access
scheduled_task(scheduled_task const &)=default
auto id() const noexcept -> std::uint64_t
Return the backend-assigned task identifier.
auto is_cancelled() const noexcept -> bool
Return whether cancellation has been requested/observed.
void cancel()
Request cancellation of the scheduled task.