diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 081c34acdb..fafd7aaae3 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -366,6 +366,13 @@ int EventLoop::exec() VERIFY_NOT_REACHED(); } +void EventLoop::spin_until(Function goal_condition) +{ + EventLoopPusher pusher(*this); + while (!goal_condition()) + pump(); +} + void EventLoop::pump(WaitMode mode) { wait_for_event(mode); diff --git a/Userland/Libraries/LibCore/EventLoop.h b/Userland/Libraries/LibCore/EventLoop.h index 047de38234..9b1a660e80 100644 --- a/Userland/Libraries/LibCore/EventLoop.h +++ b/Userland/Libraries/LibCore/EventLoop.h @@ -44,6 +44,8 @@ public: // this should really only be used for integrating with other event loops void pump(WaitMode = WaitMode::WaitForEvents); + void spin_until(Function); + void post_event(Object& receiver, NonnullOwnPtr&&); static EventLoop& main();