// RunLoop is a helper class for tests that need to process tasks posted // to a task queue, but still want to run everything on a single thread. // This is useful for tests that need to simulate asynchronous operations // without the complexity of managing real threads. class RunLoop {
public:
RunLoop(); explicit RunLoop(SocketServer* absl_nullable custom_ss);
~RunLoop();
// Returns a pointer to the task queue implementation managed by this RunLoop.
TaskQueueBase* task_queue();
// Runs tasks posted to the task queue via PostTask, until Quit() is called. void Run();
// Stops a call to Run() or RunFor() once all tasks scheduled to run before or // at the current time are completed. void Quit();
// Returns a closure that will call Quit() if it is still valid when called.
absl::AnyInvocable<void()> QuitClosure();
// Runs tasks posted to the task queue via PostTask, until Quit() is called or // `max_wait_duration` has passed. May only be called once at a time. void RunFor(TimeDelta max_wait_duration);
// Processes all pending tasks and returns. This can be useful to // synchronously wait for a posted task to execute. void Flush();
// Post a task for execution on the task queue. void PostTask(absl::AnyInvocable<void() &&> task) {
task_queue()->PostTask(std::move(task));
}
private: class FakeSocketServer : public SocketServer {
public:
FakeSocketServer(); explicit FakeSocketServer(SocketServer* absl_nullable custom_ss);
~FakeSocketServer() override;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.