diff --git a/eventuals/closure.h b/eventuals/closure.h index e397019ed..1e69c3e8f 100644 --- a/eventuals/closure.h +++ b/eventuals/closure.h @@ -5,6 +5,7 @@ #include "eventuals/compose.h" #include "eventuals/interrupt.h" #include "eventuals/type-erased-stream.h" +#include "stout/bytes.h" //////////////////////////////////////////////////////////////////////// @@ -63,6 +64,10 @@ struct _Closure final { return *continuation_; } + Bytes HeapSize() { + return Bytes{0} + k_.HeapSize(); + } + F_ f_; Interrupt* interrupt_ = nullptr; diff --git a/eventuals/eventual.h b/eventuals/eventual.h index dd55911db..4a5ec1036 100644 --- a/eventuals/eventual.h +++ b/eventuals/eventual.h @@ -6,6 +6,7 @@ #include "eventuals/interrupt.h" #include "eventuals/scheduler.h" #include "eventuals/undefined.h" +#include "stout/bytes.h" // TODO(benh): catch exceptions from 'start', 'fail', 'stop', etc. @@ -170,6 +171,10 @@ struct _Eventual { return adaptor_; } + Bytes HeapSize() { + return Bytes{0} + k_.HeapSize(); + } + Context_ context_; Start_ start_; Fail_ fail_; diff --git a/eventuals/scheduler.h b/eventuals/scheduler.h index 0706e08bc..2839f1e89 100644 --- a/eventuals/scheduler.h +++ b/eventuals/scheduler.h @@ -15,6 +15,7 @@ #include "eventuals/terminal.h" #include "eventuals/undefined.h" #include "stout/borrowable.h" +#include "stout/bytes.h" #include "stout/stringify.h" //////////////////////////////////////////////////////////////////////// @@ -392,6 +393,10 @@ struct Reschedulable final { interrupt_ = &interrupt; } + Bytes HeapSize() { + return Bytes{0} + k_.HeapSize(); + } + Interrupt* interrupt_ = nullptr; using Continuation_ = @@ -471,6 +476,10 @@ struct _Preempt final { } } + Bytes HeapSize() { + return Bytes{0} + k_.HeapSize(); + } + Scheduler::Context context_; E_ e_; diff --git a/eventuals/terminal.h b/eventuals/terminal.h index 266c87539..c3e131ae8 100644 --- a/eventuals/terminal.h +++ b/eventuals/terminal.h @@ -3,6 +3,7 @@ #include "eventuals/compose.h" #include "eventuals/interrupt.h" #include "eventuals/undefined.h" +#include "stout/bytes.h" //////////////////////////////////////////////////////////////////////// @@ -57,6 +58,10 @@ struct _Terminal final { void Register(Interrupt&) {} + Bytes HeapSize() { + return Bytes{0}; + } + Context_ context_; Start_ start_; Fail_ fail_; diff --git a/test/eventual.cc b/test/eventual.cc index fe217ca82..2012a2b38 100644 --- a/test/eventual.cc +++ b/test/eventual.cc @@ -332,5 +332,21 @@ TEST(EventualTest, Ref) { EXPECT_EQ(110, x); } +TEST(EventualTest, HeapSize) { + auto e = []() { + return Eventual([](auto& k) { + k.Start(1); + }); + }; + + auto [future, k] = PromisifyForTest(e()); + + k.Start(); + + EXPECT_EQ(0, k.HeapSize().bytes()); + + EXPECT_EQ(1, future.get()); +} + } // namespace } // namespace eventuals::test