diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp index a0c39abad..b0d17bd52 100644 --- a/src/mbgl/util/thread.hpp +++ b/src/mbgl/util/thread.hpp @@ -112,9 +112,9 @@ template void Thread::run(ThreadContext context, P&& params, std::index_sequence) { uv::loop l; - { - ThreadContext::current.set(&context); + ThreadContext::current.set(&context); + { RunLoop loop_(l.get()); loop = &loop_; @@ -126,13 +126,13 @@ void Thread::run(ThreadContext context, P&& params, std::index_sequence< loop = nullptr; object = nullptr; - - ThreadContext::current.set(nullptr); } // Run the loop again to ensure that async close callbacks have been called. l.run(); + ThreadContext::current.set(nullptr); + joinable.get_future().get(); }