Commit 2d08baf6 authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Sara Golemon

Add loopOnce() method to folly::EventBase

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
parent 36194671
......@@ -223,6 +223,14 @@ void EventBase::waitUntilRunning() {
// 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;
......@@ -302,6 +310,10 @@ bool EventBase::loop() {
VLOG(5) << "EventBase " << this << " loop time: " <<
getTimeDelta(&prev).count();
if (once) {
break;
}
}
// Reset stop_ so loop() can be called again
stop_ = false;
......
......@@ -143,6 +143,15 @@ class EventBase : private boost::noncopyable, public TimeoutManager {
*/
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.
*
......@@ -479,6 +488,8 @@ class EventBase : private boost::noncopyable, public TimeoutManager {
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment