Introduce destruction callbacks
[folly.git] / folly / io / async / EventBase.h
index fdee81348b13ca27ef7877c723fc3f4c3475d43e..660b1abdf93d3852f79628341736faa514de78d9 100644 (file)
@@ -240,6 +240,18 @@ class EventBase : private boost::noncopyable, public TimeoutManager {
 
   void runInLoop(Cob&& c, bool thisIteration = false);
 
+  /**
+   * Adds the given callback to a queue of things run before destruction
+   * of current EventBase.
+   *
+   * This allows users of EventBase that run in it, but don't control it,
+   * to be notified before EventBase gets destructed.
+   *
+   * Note: will be called from the thread that invoked EventBase destructor,
+   *       before the final run of loop callbacks.
+   */
+  void runOnDestruction(LoopCallback* callback);
+
   /**
    * Run the specified function in the EventBase's thread.
    *
@@ -500,6 +512,7 @@ class EventBase : private boost::noncopyable, public TimeoutManager {
   CobTimeout::List pendingCobTimeouts_;
 
   LoopCallbackList loopCallbacks_;
+  LoopCallbackList onDestructionCallbacks_;
 
   // This will be null most of the time, but point to currentCallbacks
   // if we are in the middle of running loop callbacks, such that