diff --git a/src/Loop.h b/src/Loop.h index 5db8ee2..2c80a65 100644 --- a/src/Loop.h +++ b/src/Loop.h @@ -50,7 +50,11 @@ private: } static void preCb(us_loop *loop) { + LoopData *loopData = (LoopData *) us_loop_ext(loop); + if (loopData->preHandler) { + loopData->preHandler((Loop *) loop); + } } static void postCb(us_loop *loop) { @@ -118,6 +122,12 @@ public: loopData->postHandler = handler; } + void setPreHandler(std::function handler) { + LoopData *loopData = (LoopData *) us_loop_ext((us_loop *) this); + + loopData->preHandler = handler; + } + /* Defer this callback on Loop's thread of execution */ void defer(std::function cb) { LoopData *loopData = (LoopData *) us_loop_ext((us_loop *) this); diff --git a/src/LoopData.h b/src/LoopData.h index c90e886..7a47078 100644 --- a/src/LoopData.h +++ b/src/LoopData.h @@ -36,7 +36,7 @@ private: int currentDeferQueue = 0; std::vector> deferQueues[2]; - std::function postHandler; + std::function postHandler, preHandler; public: ~LoopData() {