Add async/resilience/reflection primitives + FSM v2 rewrite

A round of new universal capabilities (all generic — templated/reflection
based, no app coupling), verified by the test suite (1103 passing):

Data reflection:
- Reflect.hpp now (de)serializes chrono::duration, chrono::time_point,
  std::variant (tagged), std::array, and non-string-keyed std::map;
  Meta.hpp gains is_time_point_v et al.

Async:
- EventBus gains Mode::Async (worker-thread dispatch + flush()).
- ThreadPool gains a bounded queue, try_submit(), and rejection stats.

New modules / containers:
- Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker,
  ResourceMonitor.
- Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V>
  (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats).
- System: process/CPU/memory metrics (Metrics.hpp) and a streaming
  Process API.

Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions,
history states, deferred events), Configuration/Logging reflection
helpers, and the accompanying test suites.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-22 15:45:16 +03:00
1 parent 43b5a81504
commit 80293ee56f
93 files changed
+8500 -3312

No files matched your search

+94 -74
View File
@@ -8,15 +8,16 @@ using Void::Coro::Task;
using Void::Fsm::ChildFailure;
using Void::Fsm::ChildSuccess;
using Void::Fsm::FsmError;
using Void::Fsm::Step;
using Void::Fsm::State;
using Void::Fsm::StateKey;
namespace Fsm = Void::Fsm;
// startMachine<Sub, Next>(data) launches a full sub-FSM on the parent's shared
// executor/events/services (startup data routed to Sub's initial-state
// startup-entry), then enters Next. The engine dispatches the sub's typed
// outcome to Next's signature-matched handler — a member taking
// `ChildSuccess auto` (success) or `ChildFailure auto` (failure). No override,
// no fixed names.
// outcome to Next's signature-matched handler — a member taking `ChildSuccess`
// (success) or `ChildFailure` (failure); the typed value is read with
// `.as<T>()`. No override, no fixed names.
namespace
{
@@ -29,16 +30,17 @@ namespace
using Success = int;
using Failure = Void::Fsm::FsmError;
struct Run : State {
Task<Step> run(int seed)
{
if (seed < 0) {
co_return fail("negative");
}
co_return succeed(seed * 2);
}
struct States {
struct Run : State {
Task<StateKey> run(int seed)
{
if (seed < 0) {
co_return fail("negative");
}
co_return succeed(seed * 2);
}
};
};
using States = Fsm::States<Run>;
};
class Calc : public Fsm::Machine<Calc>
@@ -49,24 +51,27 @@ namespace
int input = 0;
struct Start : State {
Task<Step> run()
{
co_return startMachine<Doubler, AfterDouble>(
self().input);
}
struct States {
struct Start : State {
Task<StateKey> run()
{
co_return startMachine<Doubler, AfterDouble>(
self().input);
}
};
struct AfterDouble : State {
Task<StateKey> ok(ChildSuccess s)
{
co_return succeed("doubled:" +
std::to_string(s.as<int>()));
}
Task<StateKey> no(ChildFailure f)
{
co_return succeed("failed:" +
f.as<FsmError>().message);
}
};
};
struct AfterDouble : State {
Task<Step> ok(ChildSuccess auto s)
{
co_return succeed("doubled:" + std::to_string(s.value));
}
Task<Step> no(ChildFailure auto f)
{
co_return succeed("failed:" + f.value.message);
}
};
using States = Fsm::States<Start, AfterDouble>;
explicit Calc(int in) : input(in) {}
};
@@ -98,10 +103,11 @@ namespace
{
public:
struct Ping : State {
Task<Step> run() { co_return succeed(); }
struct States {
struct Ping : State {
Task<StateKey> run() { co_return succeed(); }
};
};
using States = Fsm::States<Ping>;
};
class Host : public Fsm::Machine<Host>
@@ -110,14 +116,21 @@ namespace
using Success = int;
struct Go : State {
Task<Step> run() { co_return startMachine<Pinger, Done>(); }
struct States {
struct Go : State {
Task<StateKey> run()
{
co_return startMachine<Pinger, Done>();
}
};
struct Done : State {
// void-result sub: ChildSuccess box has no value.
Task<StateKey> ok(ChildSuccess)
{
co_return succeed(42);
}
};
};
struct Done : State {
// void-result sub: ChildSuccess box has no value.
Task<Step> ok(ChildSuccess auto) { co_return succeed(42); }
};
using States = Fsm::States<Go, Done>;
};
} // namespace
@@ -140,25 +153,27 @@ namespace
using Success = int;
struct A : State {
Task<Step> run()
{
co_return startMachine<Doubler, B>(3); // 3 -> 6
}
struct States {
struct A : State {
Task<StateKey> run()
{
co_return startMachine<Doubler, B>(3); // 3 -> 6
}
};
struct B : State {
Task<StateKey> ok(ChildSuccess s)
{
// 6 -> 12
co_return startMachine<Doubler, C>(s.as<int>());
}
};
struct C : State {
Task<StateKey> ok(ChildSuccess s)
{
co_return succeed(s.as<int>());
}
};
};
struct B : State {
Task<Step> ok(ChildSuccess auto s)
{
co_return startMachine<Doubler, C>(s.value); // 6 -> 12
}
};
struct C : State {
Task<Step> ok(ChildSuccess auto s)
{
co_return succeed(s.value);
}
};
using States = Fsm::States<A, B, C>;
};
} // namespace
@@ -184,14 +199,15 @@ namespace
using Success = int;
struct W : State {
Task<Step> run()
{
co_await await_event<Tick>();
co_return succeed(7);
}
struct States {
struct W : State {
Task<StateKey> run()
{
co_await await_event<Tick>();
co_return succeed(7);
}
};
};
using States = Fsm::States<W>;
};
class Outer : public Fsm::Machine<Outer>
@@ -200,16 +216,20 @@ namespace
using Success = int;
struct Begin : State {
Task<Step> run() { co_return startMachine<WaitSub, Fin>(); }
struct States {
struct Begin : State {
Task<StateKey> run()
{
co_return startMachine<WaitSub, Fin>();
}
};
struct Fin : State {
Task<StateKey> ok(ChildSuccess s)
{
co_return succeed(s.as<int>());
}
};
};
struct Fin : State {
Task<Step> ok(ChildSuccess auto s)
{
co_return succeed(s.value);
}
};
using States = Fsm::States<Begin, Fin>;
};
} // namespace