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:
1 parent
43b5a81504
commit
80293ee56f
93 files changed
+8500
-3312
No files matched your search
@@ -7,7 +7,8 @@
|
||||
|
||||
using Void::Coro::Task;
|
||||
using Void::Fsm::MachineOptions;
|
||||
using Void::Fsm::Step;
|
||||
using Void::Fsm::State;
|
||||
using Void::Fsm::StateKey;
|
||||
namespace Fsm = Void::Fsm;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
@@ -28,17 +29,18 @@ namespace
|
||||
|
||||
int total = 0;
|
||||
|
||||
struct Take : State {
|
||||
Task<Step> run()
|
||||
{
|
||||
auto a = co_await await_event<Add>();
|
||||
self().total += a.n;
|
||||
auto b = co_await await_event<Add>();
|
||||
self().total += b.n;
|
||||
co_return succeed(self().total);
|
||||
}
|
||||
struct States {
|
||||
struct Take : State {
|
||||
Task<StateKey> run()
|
||||
{
|
||||
auto a = co_await await_event<Add>();
|
||||
self().total += a.n;
|
||||
auto b = co_await await_event<Add>();
|
||||
self().total += b.n;
|
||||
co_return succeed(self().total);
|
||||
}
|
||||
};
|
||||
};
|
||||
using States = Fsm::States<Take>;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -63,16 +65,17 @@ namespace
|
||||
|
||||
using Success = int;
|
||||
|
||||
struct A : State {
|
||||
Task<Step> run() { co_return goto_state<C>(); }
|
||||
struct States {
|
||||
struct A : State {
|
||||
Task<StateKey> run() { co_return goto_state<C>(); }
|
||||
};
|
||||
struct B : State {
|
||||
Task<StateKey> run() { co_return succeed(1); }
|
||||
};
|
||||
struct C : State {
|
||||
Task<StateKey> run() { co_return succeed(3); }
|
||||
};
|
||||
};
|
||||
struct B : State {
|
||||
Task<Step> run() { co_return succeed(1); }
|
||||
};
|
||||
struct C : State {
|
||||
Task<Step> run() { co_return succeed(3); }
|
||||
};
|
||||
using States = Fsm::States<A, B, C>;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -98,17 +101,18 @@ namespace
|
||||
|
||||
using Success = int;
|
||||
|
||||
struct Loop : State {
|
||||
Task<Step> run()
|
||||
{
|
||||
co_await await_event<Tick>();
|
||||
co_return next<Loop>();
|
||||
}
|
||||
struct States {
|
||||
struct Loop : State {
|
||||
Task<StateKey> run()
|
||||
{
|
||||
co_await await_event<Tick>();
|
||||
co_return next<Loop>();
|
||||
}
|
||||
};
|
||||
struct Done : State {
|
||||
Task<StateKey> run() { co_return succeed(99); }
|
||||
};
|
||||
};
|
||||
struct Done : State {
|
||||
Task<Step> run() { co_return succeed(99); }
|
||||
};
|
||||
using States = Fsm::States<Loop, Done>;
|
||||
|
||||
explicit Jumper(MachineOptions o = {}) : Fsm::Machine<Jumper>(o) {}
|
||||
};
|
||||
@@ -124,7 +128,7 @@ Void::Testing::Test jump_redirects_at_next_boundary()
|
||||
while (fsm.pump() > 0) {
|
||||
} // Loop -> next<Loop> -> park again
|
||||
|
||||
fsm.jump<Jumper::Done>(); // request a jump
|
||||
fsm.jump<Jumper::States::Done>(); // request a jump
|
||||
fsm.send(Tick{});
|
||||
while (fsm.pump() > 0) {
|
||||
} // Loop finishes -> boundary applies the jump -> Done
|
||||
@@ -147,10 +151,14 @@ namespace
|
||||
|
||||
int runs = 0;
|
||||
|
||||
struct Once : State {
|
||||
Task<Step> run() { co_return succeed(++self().runs); }
|
||||
struct States {
|
||||
struct Once : State {
|
||||
Task<StateKey> run()
|
||||
{
|
||||
co_return succeed(++self().runs);
|
||||
}
|
||||
};
|
||||
};
|
||||
using States = Fsm::States<Once>;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -173,13 +181,14 @@ namespace
|
||||
|
||||
using Success = int;
|
||||
|
||||
struct A : State {
|
||||
Task<Step> run() { co_return succeed(1); }
|
||||
};
|
||||
struct B : State {
|
||||
Task<Step> run() { co_return succeed(2); }
|
||||
};
|
||||
using States = Fsm::States<A, B>; // initial = A
|
||||
struct States {
|
||||
struct A : State {
|
||||
Task<StateKey> run() { co_return succeed(1); }
|
||||
};
|
||||
struct B : State {
|
||||
Task<StateKey> run() { co_return succeed(2); }
|
||||
};
|
||||
}; // initial = A
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -189,7 +198,7 @@ Void::Testing::Test restart_at_changes_initial_state()
|
||||
Pick fsm;
|
||||
const auto first = fsm.run_blocking();
|
||||
Void::Testing::expect_eq(*first, 1); // A
|
||||
fsm.restart_at<Pick::B>();
|
||||
fsm.restart_at<Pick::States::B>();
|
||||
const auto second = fsm.wait();
|
||||
Void::Testing::expect_eq(*second, 2); // B
|
||||
}
|
||||
@@ -204,32 +213,33 @@ namespace
|
||||
|
||||
using Success = int;
|
||||
|
||||
struct A : State {
|
||||
Task<Step> run() { co_return succeed(1); }
|
||||
struct States {
|
||||
struct A : State {
|
||||
Task<StateKey> run() { co_return succeed(1); }
|
||||
};
|
||||
struct B : State {
|
||||
Task<StateKey> run() { co_return succeed(2); }
|
||||
};
|
||||
struct C : State {
|
||||
Task<StateKey> run() { co_return succeed(3); }
|
||||
};
|
||||
};
|
||||
struct B : State {
|
||||
Task<Step> run() { co_return succeed(2); }
|
||||
};
|
||||
struct C : State {
|
||||
Task<Step> run() { co_return succeed(3); }
|
||||
};
|
||||
// Not in States<> — added via replace<>.
|
||||
// Not in States — added via replace<>.
|
||||
struct Extra : State {
|
||||
Task<Step> run() { co_return succeed(7); }
|
||||
Task<StateKey> run() { co_return succeed(7); }
|
||||
};
|
||||
using States = Fsm::States<A, B, C>;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
Void::Testing::Test remove_and_set_initial_before_start()
|
||||
{
|
||||
Mut fsm;
|
||||
Void::Testing::expect(fsm.has_state<Mut::C>());
|
||||
fsm.remove<Mut::C>();
|
||||
Void::Testing::expect(!fsm.has_state<Mut::C>());
|
||||
Void::Testing::expect(fsm.has_state<Mut::States::C>());
|
||||
fsm.remove<Mut::States::C>();
|
||||
Void::Testing::expect(!fsm.has_state<Mut::States::C>());
|
||||
Void::Testing::expect_eq(fsm.describe().size(), std::size_t{2});
|
||||
|
||||
fsm.set_initial<Mut::B>();
|
||||
fsm.set_initial<Mut::States::B>();
|
||||
const auto outcome = fsm.run_blocking();
|
||||
Void::Testing::expect_eq(*outcome, 2);
|
||||
}
|
||||
@@ -237,8 +247,9 @@ Void::Testing::Test remove_and_set_initial_before_start()
|
||||
Void::Testing::Test replace_swaps_a_state_and_keeps_initial()
|
||||
{
|
||||
Mut fsm;
|
||||
fsm.replace<Mut::A, Mut::Extra>(); // A was initial -> Extra becomes initial
|
||||
Void::Testing::expect(!fsm.has_state<Mut::A>());
|
||||
// A was initial -> Extra becomes initial.
|
||||
fsm.replace<Mut::States::A, Mut::Extra>();
|
||||
Void::Testing::expect(!fsm.has_state<Mut::States::A>());
|
||||
Void::Testing::expect(fsm.has_state<Mut::Extra>());
|
||||
const auto outcome = fsm.run_blocking();
|
||||
Void::Testing::expect_eq(*outcome, 7);
|
||||
@@ -257,14 +268,15 @@ namespace
|
||||
|
||||
using Success = int;
|
||||
|
||||
struct W : State {
|
||||
Task<Step> run()
|
||||
{
|
||||
co_await await_event<Go>();
|
||||
co_return succeed(5);
|
||||
}
|
||||
struct States {
|
||||
struct W : State {
|
||||
Task<StateKey> run()
|
||||
{
|
||||
co_await await_event<Go>();
|
||||
co_return succeed(5);
|
||||
}
|
||||
};
|
||||
};
|
||||
using States = Fsm::States<W>;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in new issue
Block a user