Causes the event loop to exit soon.

Synopsis

Declared in <folly/io/async/EventBase.h>

void
terminateLoopSoon();

Description

This will cause an existing call to loop() or loopForever() to stop event processing and return, even if there are still events remaining to be processed.

It is safe to call terminateLoopSoon() from another thread to cause loop() to wake up and return in the EventBase loop thread. terminateLoopSoon() may also be called from the loop thread itself (for example, a EventHandler or AsyncTimeout callback may call terminateLoopSoon() to cause the loop to exit after the callback returns.) If the loop is not running, this will cause the next call to loop to terminate soon after starting. If a loop runs out of work (and so terminates on its own) concurrently with a call to terminateLoopSoon(), this may cause a race condition.

Note that the caller is responsible for ensuring that cleanup of all event callbacks occurs properly. Since terminateLoopSoon() causes the loop to exit even when there are pending events present, there may be remaining callbacks present waiting to be invoked. If the loop is later restarted pending events will continue to be processed normally, however if the EventBase is destroyed after calling terminateLoopSoon() it is the caller's responsibility to ensure that cleanup happens properly even if some outstanding events are never processed.

Created with MrDocs