Summary: Add loopOnce() method which provides functionality similar to event_base_loop(base, EVLOOP_ONCE);
Test Plan: fbmake
Reviewed By: simpkins@fb.com
FB internal diff:
D1249753
// enters the event_base loop -- will only exit when forced to
bool EventBase::loop() {
+ return loopBody();
+}
+
+bool EventBase::loopOnce() {
+ return loopBody(true);
+}
+
+bool EventBase::loopBody(bool once) {
VLOG(5) << "EventBase(): Starting loop.";
int res = 0;
bool ranLoopCallbacks;
VLOG(5) << "EventBase " << this << " loop time: " <<
getTimeDelta(&prev).count();
+
+ if (once) {
+ break;
+ }
}
// Reset stop_ so loop() can be called again
stop_ = false;
*/
bool loop();
+ /**
+ * Wait for some events to become active, run them, then return.
+ *
+ * This is useful for callers that want to run the loop manually.
+ *
+ * Returns the same result as loop().
+ */
+ bool loopOnce();
+
/**
* Runs the event loop.
*
typedef LoopCallback::List LoopCallbackList;
class FunctionRunner;
+ bool loopBody(bool once = false);
+
// executes any callbacks queued by runInLoop(); returns false if none found
bool runLoopCallbacks(bool setContext = true);