notifications on request cancellation

This commit is contained in:
Konstantin Käfer
2014-09-17 12:10:08 +02:00
parent fd2b2e2082
commit 89cd310cf6
6 changed files with 68 additions and 21 deletions

View File

@@ -149,7 +149,8 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl
// The prepare call jumps back to the main thread.
fileSource->prepare([&, url, fileSource] {
fileSource->request(ResourceType::Glyphs, url)->onload([&, url](const Response &res) {
auto request = fileSource->request(ResourceType::Glyphs, url);
request->onload([&, url](const Response &res) {
if (res.code != 200) {
// Something went wrong with loading the glyph pbf. Pass on the error to the future listeners.
const std::string msg = util::sprintf<255>("[ERROR] failed to load glyphs (%d): %s\n", res.code, res.message.c_str());
@@ -163,6 +164,9 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl
promise.set_value(*this);
}
});
request->oncancel([&]() {
promise.set_exception(std::make_exception_ptr(std::runtime_error("Loading glyphs was canceled")));
});
});
}