libutil: remove callback.hh

it's no longer used. it really shouldn't have existed this long since it
was just a mashup of both std::promise and std::packaged_task in a shape
that makes composition unnecessarily difficult. all but a single case of
Callback pattern calls were fully synchronous anyway, and even this sole
outlier was by far not important enough to justify the extra complexity.

Change-Id: I208aec4572bf2501cdbd0f331f27d505fca3a62f
This commit is contained in:
eldritch horrors 2024-04-28 02:21:46 +02:00
parent b66451ae7f
commit ceccac835c
15 changed files with 0 additions and 66 deletions

View file

@ -11,7 +11,6 @@
#include "nar-accessor.hh"
#include "thread-pool.hh"
#include "signals.hh"
#include "callback.hh"
#include <chrono>
#include <future>

View file

@ -11,7 +11,6 @@
#include "common-protocol.hh"
#include "common-protocol-impl.hh"
#include "topo-sort.hh"
#include "callback.hh"
#include "local-store.hh" // TODO remove, along with remaining downcasts
#include "logging-json.hh"

View file

@ -2,7 +2,6 @@
#include "finally.hh"
#include "worker.hh"
#include "substitution-goal.hh"
#include "callback.hh"
#include "signals.hh"
namespace nix {

View file

@ -11,7 +11,6 @@
#include "compression.hh"
#include "daemon.hh"
#include "topo-sort.hh"
#include "callback.hh"
#include "json-utils.hh"
#include "cgroup.hh"
#include "personality.hh"

View file

@ -1,5 +1,4 @@
#include "store-api.hh"
#include "callback.hh"
namespace nix {

View file

@ -6,7 +6,6 @@
#include "signals.hh"
#include "compression.hh"
#include "finally.hh"
#include "callback.hh"
#if ENABLE_S3
#include <aws/core/client/ClientConfiguration.h>

View file

@ -2,7 +2,6 @@
#include "filetransfer.hh"
#include "globals.hh"
#include "nar-info-disk-cache.hh"
#include "callback.hh"
namespace nix {

View file

@ -9,7 +9,6 @@
#include "path-with-outputs.hh"
#include "ssh.hh"
#include "derivations.hh"
#include "callback.hh"
namespace nix {

View file

@ -6,7 +6,6 @@
#include "derivations.hh"
#include "nar-info.hh"
#include "references.hh"
#include "callback.hh"
#include "topo-sort.hh"
#include "signals.hh"
#include "finally.hh"

View file

@ -5,7 +5,6 @@
#include "store-api.hh"
#include "thread-pool.hh"
#include "topo-sort.hh"
#include "callback.hh"
#include "closure.hh"
#include "filetransfer.hh"

View file

@ -15,7 +15,6 @@
#include "pool.hh"
#include "finally.hh"
#include "logging.hh"
#include "callback.hh"
#include "filetransfer.hh"
#include <nlohmann/json.hpp>

View file

@ -9,7 +9,6 @@
#include "url.hh"
#include "references.hh"
#include "archive.hh"
#include "callback.hh"
#include "remote-store.hh"
#include "signals.hh"
// FIXME this should not be here, see TODO below on

View file

@ -1,49 +0,0 @@
#pragma once
///@file
#include <future>
#include <functional>
namespace nix {
/**
* A callback is a wrapper around a lambda that accepts a valid of
* type T or an exception. (We abuse std::future<T> to pass the value or
* exception.)
*/
template<typename T>
class Callback
{
std::function<void(std::future<T>)> fun;
std::atomic_flag done = ATOMIC_FLAG_INIT;
public:
Callback(std::function<void(std::future<T>)> fun) : fun(fun) { }
Callback(Callback && callback) : fun(std::move(callback.fun))
{
auto prev = callback.done.test_and_set();
if (prev) done.test_and_set();
}
void operator()(T && t) noexcept
{
auto prev = done.test_and_set();
assert(!prev);
std::promise<T> promise;
promise.set_value(std::move(t));
fun(promise.get_future());
}
void rethrow(const std::exception_ptr & exc = std::current_exception()) noexcept
{
auto prev = done.test_and_set();
assert(!prev);
std::promise<T> promise;
promise.set_exception(exc);
fun(promise.get_future());
}
};
}

View file

@ -43,7 +43,6 @@ libutil_headers = files(
'args/root.hh',
'args.hh',
'box_ptr.hh',
'callback.hh',
'canon-path.hh',
'cgroup.hh',
'chunked-vector.hh',

View file

@ -836,10 +836,6 @@ std::optional<typename T::value_type> pop(T & c)
}
template<typename T>
class Callback;
/**
* A RAII helper that increments a counter on construction and
* decrements it on destruction.