mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Ensure that Callback is called only once
Also, make Callback movable but uncopyable.
This commit is contained in:
parent
8c4ea7a451
commit
7348653ff4
5 changed files with 36 additions and 17 deletions
|
@ -137,17 +137,19 @@ protected:
|
|||
|
||||
auto request(makeRequest(path));
|
||||
|
||||
auto callbackPtr = std::make_shared<decltype(callback)>(std::move(callback));
|
||||
|
||||
getDownloader()->enqueueDownload(request,
|
||||
{[callback, this](std::future<DownloadResult> result) {
|
||||
{[callbackPtr, this](std::future<DownloadResult> result) {
|
||||
try {
|
||||
callback(result.get().data);
|
||||
(*callbackPtr)(result.get().data);
|
||||
} catch (DownloadError & e) {
|
||||
if (e.error == Downloader::NotFound || e.error == Downloader::Forbidden)
|
||||
return callback(std::shared_ptr<std::string>());
|
||||
return (*callbackPtr)(std::shared_ptr<std::string>());
|
||||
maybeDisable();
|
||||
callback.rethrow();
|
||||
callbackPtr->rethrow();
|
||||
} catch (...) {
|
||||
callback.rethrow();
|
||||
callbackPtr->rethrow();
|
||||
}
|
||||
}});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue