diff --git a/Telegram/SourceFiles/base/binary_guard.h b/Telegram/SourceFiles/base/binary_guard.h index 1c6455e1a4..5ff3fc37db 100644 --- a/Telegram/SourceFiles/base/binary_guard.h +++ b/Telegram/SourceFiles/base/binary_guard.h @@ -81,3 +81,21 @@ inline std::pair make_binary_guard() { } } // namespace base + +namespace crl { + +template +struct guard_traits; + +template <> +struct guard_traits { + static base::binary_guard create(base::binary_guard value) { + return value; + } + static bool check(const base::binary_guard &guard) { + return guard.alive(); + } + +}; + +} // namespace crl diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 32eadbb06c..5268c18e4b 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -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(); diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 8607885617..9d44f6b819 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -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)); }); }); diff --git a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp index efab7f27b8..6735ea6786 100644 --- a/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp +++ b/Telegram/SourceFiles/data/data_document_good_thumbnail.cpp @@ -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; diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index e3cddbfaef..8ec3612d82 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -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, diff --git a/Telegram/SourceFiles/storage/storage_databases.cpp b/Telegram/SourceFiles/storage/storage_databases.cpp index 580ed0c1bc..f0fc1a5656 100644 --- a/Telegram/SourceFiles/storage/storage_databases.cpp +++ b/Telegram/SourceFiles/storage/storage_databases.cpp @@ -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); }); }); diff --git a/Telegram/SourceFiles/support/support_templates.cpp b/Telegram/SourceFiles/support/support_templates.cpp index bc52d949d8..b20bd565d1 100644 --- a/Telegram/SourceFiles/support/support_templates.cpp +++ b/Telegram/SourceFiles/support/support_templates.cpp @@ -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)); diff --git a/Telegram/SourceFiles/ui/emoji_config.cpp b/Telegram/SourceFiles/ui/emoji_config.cpp index 079ed986a0..0f57c568cf 100644 --- a/Telegram/SourceFiles/ui/emoji_config.cpp +++ b/Telegram/SourceFiles/ui/emoji_config.cpp @@ -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));