Use a promise rather than async dance
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
#include <mbgl/platform/default/headless_display.hpp>
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
#include <future>
|
||||
|
||||
void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) {
|
||||
ASSERT_TRUE(value.IsString());
|
||||
auto string = std::string { value.GetString(),value.GetStringLength() };
|
||||
@@ -154,32 +154,15 @@ TEST_P(HeadlessTest, render) {
|
||||
map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
|
||||
map.setBearing(bearing);
|
||||
|
||||
struct Data {
|
||||
std::string path;
|
||||
std::unique_ptr<const StillImage> image;
|
||||
};
|
||||
std::promise<void> promise;
|
||||
|
||||
uv_async_t *async = new uv_async_t;
|
||||
async->data = new Data { "test/suite/tests/" + base + "/" + name + "/actual.png", nullptr };
|
||||
uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) {
|
||||
auto data = std::unique_ptr<Data>(reinterpret_cast<Data *>(as->data));
|
||||
as->data = nullptr;
|
||||
uv_close(reinterpret_cast<uv_handle_t *>(as), [](uv_handle_t *handle) {
|
||||
delete reinterpret_cast<uv_async_t *>(handle);
|
||||
});
|
||||
|
||||
assert(data);
|
||||
const std::string png = util::compress_png(data->image->width, data->image->height, data->image->pixels.get());
|
||||
util::write_file(data->path, png);
|
||||
map.renderStill([&](std::unique_ptr<const StillImage> image) {
|
||||
const std::string png = util::compress_png(image->width, image->height, image->pixels.get());
|
||||
util::write_file("test/suite/tests/" + base + "/" + name + "/actual.png", png);
|
||||
promise.set_value();
|
||||
});
|
||||
|
||||
map.renderStill([async](std::unique_ptr<const StillImage> image) {
|
||||
reinterpret_cast<Data *>(async->data)->image = std::move(image);
|
||||
uv_async_send(async);
|
||||
});
|
||||
|
||||
// This loop will terminate once the async was fired.
|
||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
promise.get_future().get();
|
||||
|
||||
map.stop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user