cmake-template
Loading...
Searching...
No Matches
Task< ResultType > Class Template Reference

#include <task.hpp>

Inheritance diagram for Task< ResultType >:
[legend]

Public Member Functions

 Task (std::function< ResultType()> function)
 Construct a new Task object. More...
 
void execute () override
 Executes the task's function and sets the result in the promise. More...
 
ResultType get ()
 Retrieves the result of the task. More...
 
- Public Member Functions inherited from ITask
virtual ~ITask ()=default
 
virtual void execute ()=0
 

Friends

class Exkit
 

Constructor & Destructor Documentation

◆ Task()

template<typename ResultType >
Task< ResultType >::Task ( std::function< ResultType()>  function)
explicit

Construct a new Task object.

This constructor initializes a new Task object with the provided function. The function will be executed when the task is run, and its result will be stored in a promise that can be accessed through the task's future. The function can be any callable object, such as a lambda, function pointer, or std::function

Parameters
functionThe function to be executed as a task. This can be any callable object, such as a lambda, function pointer, or std::function

Member Function Documentation

◆ execute()

template<typename ResultType >
void Task< ResultType >::execute
overridevirtual

Executes the task's function and sets the result in the promise.

This method is responsible for executing the task's function and then setting the result in the associated promise. If the function throws an exception, it will be caught and set as an exception in the promise instead

Implements ITask.

◆ get()

template<typename ResultType >
ResultType Task< ResultType >::get

Retrieves the result of the task.

This method blocks until the task has been completed and then returns the result. If the task's function threw an exception, this method will rethrow that exception when called

Returns
ResultType The result of the task, as produced by the task's function

Friends And Related Function Documentation

◆ Exkit

template<typename ResultType >
friend class Exkit
friend

The documentation for this class was generated from the following file: