#pragma once #include #include #include #include #include namespace Jobs { // Represents a single task to complete on any thread, with optionally a task to complete when finished. class Job { public: Job(); Job(std::function Task, std::function OnFinished, bool IsAwaiter); ~Job() = default; // Executes the job, sets the state to finished, and calls the finalizer. void Execute(); // Forcefully sets the job state to finished. void SetIsFinished(); // Returns whether or not the job is completed. bool IsFinished(); // Returns whether or not the job is being used as an awaitable object. bool IsAwaiter(); private: // Internal cached states for the job std::function _Task; std::function _Finished; std::atomic_bool _IsFinished; std::atomic_bool _IsAwaiter; }; }