瀏覽代碼

LibThreading: Invoke BackgroundAction completions on origin event loop

We now capture the origin thread's current event loop when setting up
a BackgroundAction and then invoke the on_complete callback on that same
event loop.
Andreas Kling 3 年之前
父節點
當前提交
d1cea57246
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      Userland/Libraries/LibThreading/BackgroundAction.h

+ 2 - 2
Userland/Libraries/LibThreading/BackgroundAction.h

@@ -56,10 +56,10 @@ private:
         , m_action(move(action))
         , m_on_complete(move(on_complete))
     {
-        enqueue_work([this] {
+        enqueue_work([this, origin_event_loop = &Core::EventLoop::current()] {
             m_result = m_action(*this);
             if (m_on_complete) {
-                deferred_invoke([this] {
+                origin_event_loop->deferred_invoke([this] {
                     m_on_complete(m_result.release_value());
                     remove_from_parent();
                 });