template class EE::TaskResolver

Overview

Completes a Task : call it with the value. More…

#include <task.hpp>

template <typename T>
class TaskResolver {
public:
    // construction

    TaskResolver();
    TaskResolver(const TaskResolver& other);
    TaskResolver(TaskResolver&&);
    ~TaskResolver();

    // methods

    TaskResolver& operator=(const TaskResolver& other);
    TaskResolver& operator=(TaskResolver&& other);

    template <typename... Args>
    bool operator()(Args&&... args) const;
};

Detailed Documentation

Completes a Task : call it with the value.

Filled in by Task<T>::create(), which returns its task. Copyable: every copy completes the same task, so it can be captured by several callbacks, and the first call wins (a later call reports TaskDiagnostic::ResolvedTwice). Calling it runs the continuations attached without an executor (then( fn ), onComplete( fn )) on the calling thread before it returns.

When the last copy is destroyed without having been called, the task is abandoned and TaskDiagnostic::Abandoned is reported: its consumer is still told (then() skips its function, onComplete() receives std::nullopt), so it never waits forever.

A default-constructed resolver belongs to no task until create() fills it; calling it before that only reports ResolvedTwice.

Methods

template <typename... Args>
bool operator()(Args&&... args) const

Completes the task with the value built from args.

Returns:

False (and reports TaskDiagnostic::ResolvedTwice) if it was already completed.