← API Reference Class

template<typename _Callable, typename... _Args> asge::concurrent::_internal::WorkerJob

A type-erased, executable unit of work that optionally produces a future value.

#include <ThreadPool.hpp>

Inherits from asge::concurrent::_internal::IExecuter, asge::functools::Callable< _Callable, _Args... >.

Inheritance

classDiagram
    class N3["asge::functools::Callable"]
    class N2["asge::concurrent::_internal::IExecuter"]
    class N1["asge::concurrent::_internal::WorkerJob"]
    N2 <|-- N1
    N3 <|-- N1
    click N3 href "classasge_1_1functools_1_1Callable.html"
    click N2 href "structasge_1_1concurrent_1_1__internal_1_1IExecuter.html"
    click N1 href "classasge_1_1concurrent_1_1__internal_1_1WorkerJob.html"

Collaboration

classDiagram
    class N3["asge::functools::Callable"]
    class N2["asge::concurrent::_internal::IExecuter"]
    class N1["asge::concurrent::_internal::WorkerJob"]
    N2 <|-- N1
    N3 <|-- N1
    click N3 href "classasge_1_1functools_1_1Callable.html"
    click N2 href "structasge_1_1concurrent_1_1__internal_1_1IExecuter.html"
    click N1 href "classasge_1_1concurrent_1_1__internal_1_1WorkerJob.html"

WorkerJob wraps a callable and its bound arguments into a concrete implementation of IExecuter, allowing it to be queued and dispatched by the thread pool without the pool itself needing to know the callable's type or return type.

It inherits from functools::Callable to manage the callable and its arguments, and from IExecuter to expose a uniform Execute() interface to the pool's workers.

Internally, a std::promise is used to communicate the result back to the caller. If the callable returns void, the promise is left untouched and no future value is produced. Otherwise, the return value is set on the promise at execution time and can be retrieved via the std::future returned by GetFuture().

Note

GetFuture() must be called before the job is submitted to the queue, since once ownership is transferred via unique_ptr the job is no longer accessible from the submitting thread.

Template Parameters
_Callable

The type of the callable to be executed.

_Args

The types of the arguments bound to the callable.

Private Types

#using CallableBase = functools::Callable< _Callable, _Args... >private
#using return_type = typename CallableBase::return_typeprivate

Public Types

#using future_type = std::future< return_type >

Private Attributes

#std::promise< return_type > m_RetPromiseprivate

Public Member Functions

#~WorkerJob() override=default
#future_type GetFuture()
#virtual void Execute() override
Overrides Execute