Accept binary_guard in crl::guard().

This commit is contained in:
John Preston 2019-02-17 15:52:57 +04:00
parent 4d987f7278
commit d208236994
8 changed files with 30 additions and 36 deletions

View File

@ -81,3 +81,21 @@ inline std::pair<binary_guard, binary_guard> make_binary_guard() {
}
} // namespace base
namespace crl {
template <typename T, typename Enable>
struct guard_traits;
template <>
struct guard_traits<base::binary_guard, void> {
static base::binary_guard create(base::binary_guard value) {
return value;
}
static bool check(const base::binary_guard &guard) {
return guard.alive();
}
};
} // namespace crl

View File

@ -722,16 +722,12 @@ void BackgroundPreviewBox::checkLoadedDocument() {
: PrepareScaledNonPattern(
Data::PrepareBlurredBackground(image),
Images::Option(0));
crl::on_main([
crl::on_main(std::move(guard), [
this,
image = std::move(image),
scaled = std::move(scaled),
blurred = std::move(blurred),
guard = std::move(guard)
blurred = std::move(blurred)
]() mutable {
if (!guard) {
return;
}
_full = std::move(image);
setScaledFromImage(std::move(scaled), std::move(blurred));
update();

View File

@ -1624,14 +1624,10 @@ base::binary_guard ReadImageAsync(
if (postprocess) {
image = postprocess(std::move(image));
}
crl::on_main([
guard = std::move(guard),
crl::on_main(std::move(guard), [
image = std::move(image),
callback = std::move(callback)
]() mutable {
if (!guard) {
return;
}
callback(std::move(image));
});
});

View File

@ -107,15 +107,11 @@ void GoodThumbSource::ready(
QImage &&image,
int bytesSize,
QByteArray &&bytesForCache) {
crl::on_main([
crl::on_main(std::move(guard), [
=,
guard = std::move(guard),
image = std::move(image),
bytes = std::move(bytesForCache)
]() mutable {
if (!guard) {
return;
}
if (image.isNull()) {
_empty = true;
return;

View File

@ -426,16 +426,12 @@ void FileLoader::loadLocal(const Storage::Cache::Key &key) {
QByteArray &&value,
QImage &&image,
QByteArray &&format) mutable {
crl::on_main([
crl::on_main(std::move(guard), [
=,
value = std::move(value),
image = std::move(image),
format = std::move(format),
guard = std::move(guard)
format = std::move(format)
]() mutable {
if (!guard) {
return;
}
localLoaded(
StorageImageSaved(std::move(value)),
format,

View File

@ -92,10 +92,7 @@ void Databases::destroy(Cache::Database *database) {
kept.destroying = std::move(first);
database->close();
database->waitForCleaner([=, guard = std::move(second)]() mutable {
crl::on_main([=, guard = std::move(guard)]{
if (!guard) {
return;
}
crl::on_main(std::move(guard), [=] {
_map.erase(path);
});
});

View File

@ -486,14 +486,10 @@ void Templates::load() {
crl::async([=, guard = std::move(right)]() mutable {
auto result = ReadFiles(cWorkingDir() + "TEMPLATES");
result.index = ComputeIndex(result.result);
crl::on_main([
crl::on_main(std::move(guard), [
=,
result = std::move(result),
guard = std::move(guard)
result = std::move(result)
]() mutable {
if (!guard) {
return;
}
setData(std::move(result.result));
_index = std::move(result.index);
_errors.fire(std::move(result.errors));

View File

@ -947,12 +947,11 @@ void Instance::generateCache() {
universal = Universal,
guard = std::move(right)
]() mutable {
crl::on_main([
crl::on_main(std::move(guard), [
=,
image = universal->generate(size, index),
guard = std::move(guard)
image = universal->generate(size, index)
]() mutable {
if (!guard || universal != Universal) {
if (universal != Universal) {
return;
}
pushSprite(std::move(image));