Files
MapLibreParticleLab/platform/qt/src/async_task.cpp
Thiago Marcos P. Santos e93d51c922 [Qt] Implement the AsyncTask, Timer and RunLoop using Qt
Now Mapbox GL will handle events using Qt as backend
instead of libuv.
2016-04-20 20:55:51 +03:00

40 lines
692 B
C++

#include <mbgl/util/async_task.hpp>
#include "async_task_impl.hpp"
#include <mbgl/util/run_loop.hpp>
namespace mbgl {
namespace util {
AsyncTask::Impl::Impl(std::function<void()>&& fn)
: runLoop(RunLoop::Get()),
task(std::move(fn)) {
connect(this, SIGNAL(send(void)), this, SLOT(runTask(void)), Qt::QueuedConnection);
}
void AsyncTask::Impl::maySend() {
if (!queued.test_and_set()) {
emit send();
}
}
void AsyncTask::Impl::runTask() {
queued.clear();
task();
}
AsyncTask::AsyncTask(std::function<void()>&& fn)
: impl(std::make_unique<Impl>(std::move(fn))) {
}
AsyncTask::~AsyncTask() {
}
void AsyncTask::send() {
impl->maySend();
}
}
}