1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 09:57:35 +00:00

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.
This commit is contained in:
Andreas Kling 2022-01-25 08:54:54 +01:00
parent 3bab93c5e7
commit d1cea57246

View file

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