Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
callback_job.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
13#pragma once
14
15#include <functional>
16#include <memory>
17#include <optional>
18#include <string>
19#include <vector>
20
21#include "job.h"
22
23namespace kcenon::thread
24{
43 class callback_job : public job
44 {
45 public:
67 callback_job(const std::function<std::optional<std::string>(void)>& callback,
68 const std::string& name = "callback_job");
69
77 callback_job(const std::function<common::VoidResult(void)>& callback,
78 const std::string& name = "callback_job");
79
111 callback_job(const std::function<std::optional<std::string>(const std::vector<uint8_t>&)>&
112 data_callback,
113 const std::vector<uint8_t>& data,
114 const std::string& name = "data_callback_job");
115
126 callback_job(const std::function<common::VoidResult(const std::vector<uint8_t>&)>&
127 data_callback,
128 const std::vector<uint8_t>& data,
129 const std::string& name = "data_callback_job");
130
134 ~callback_job(void) override;
135
150 [[nodiscard]] auto do_work(void) -> common::VoidResult override;
151
152 protected:
159 std::function<common::VoidResult(void)> callback_;
160
167 std::function<common::VoidResult(const std::vector<uint8_t>&)> data_callback_;
168
172 std::function<std::optional<std::string>(void)> old_callback_;
173 std::function<std::optional<std::string>(const std::vector<uint8_t>&)> old_data_callback_;
174 };
175} // namespace kcenon::thread
A specialized job class that encapsulates user-defined callbacks.
std::function< common::VoidResult(void)> callback_
Stores the user-defined callback that does not take any parameters.
callback_job(const std::function< std::optional< std::string >(void)> &callback, const std::string &name="callback_job")
Constructs a new callback_job instance with a parameterless callback.
std::function< std::optional< std::string >(const std::vector< uint8_t > &)> old_data_callback_
std::function< common::VoidResult(const std::vector< uint8_t > &)> data_callback_
Stores the user-defined callback that takes a std::vector<uint8_t>.
~callback_job(void) override
Virtual destructor for proper cleanup in derived classes.
std::function< std::optional< std::string >(void)> old_callback_
Compatibility layer for the old style callbacks.
auto do_work(void) -> common::VoidResult override
Executes the appropriate callback function to perform the job's work.
Represents a unit of work (task) to be executed, typically by a job queue.
Definition job.h:136
@ callback
Call user callback for custom decision.
Base job class for schedulable work units in the thread system.
Core threading foundation of the thread system library.
Definition thread_impl.h:17