threadman 0.1.0
Header-only C++23 managed threads, dynamic pools, futures, and executors
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
future.hpp File Reference

threadman::Future<T> (one-shot), threadman::SharedFuture<T> (multi-shot), and threadman::Promise<T> — composable async result types with .then continuations dispatched through any executor. More...

#include <threadman/exceptions.hpp>
#include <threadman/log.hpp>
#include <threadman/metrics.hpp>
#include <threadman/stats.hpp>
#include <commons/display_info.hpp>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
Include dependency graph for future.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  threadman::detail::FutureSlot< T >
 
struct  threadman::detail::FutureSlot< void >
 
class  threadman::detail::FutureState< T >
 
class  threadman::Future< T >
 
class  threadman::SharedFuture< T >
 
class  threadman::Promise< T >
 

Namespaces

namespace  threadman
 
namespace  threadman::detail
 

Functions

void threadman::detail::execute_on (IExecutor &exec, std::function< void()> task)
 Dispatch helper used by Future::then / SharedFuture::then.
 

Detailed Description

threadman::Future<T> (one-shot), threadman::SharedFuture<T> (multi-shot), and threadman::Promise<T> — composable async result types with .then continuations dispatched through any executor.

Both Future and SharedFuture are backed by a heap-resident detail::FutureState<T> held via std::shared_ptr. The state owns the result (or exception_ptr), the ready flag, and the list of registered continuations.

Future<T> is move-only and supports at most one .get() and one .then(); a second .then() throws ContinuationAlreadyRegisteredError. SharedFuture<T> is copyable and supports many .get()s and many .then()s — convert with Future::share().

Continuations are always dispatched via executor.execute(...) and never run synchronously on the satisfying thread, except through threadman::InlineExecutor (when the producer thread satisfies the promise and a continuation is already attached — the executor itself chooses to run inline). When a continuation is registered against an already-ready future, dispatch goes through the executor too (deferred, not on the calling thread).