diff options
author | eldritch horrors <pennae@lix.systems> | 2024-04-28 02:21:46 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-05-10 02:21:11 +0200 |
commit | ceccac835c55e3b5c805851bad871360641ff1d9 (patch) | |
tree | 55cc9d81430e6e8173e3cc4c308d173c6ce69034 /src/libutil | |
parent | b66451ae7fe12500f135137155c2aae6c406b2da (diff) |
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
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/callback.hh | 49 | ||||
-rw-r--r-- | src/libutil/meson.build | 1 | ||||
-rw-r--r-- | src/libutil/util.hh | 4 |
3 files changed, 0 insertions, 54 deletions
diff --git a/src/libutil/callback.hh b/src/libutil/callback.hh deleted file mode 100644 index 3710d1239..000000000 --- a/src/libutil/callback.hh +++ /dev/null @@ -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()); - } -}; - -} diff --git a/src/libutil/meson.build b/src/libutil/meson.build index 8caa0532a..13266f6bd 100644 --- a/src/libutil/meson.build +++ b/src/libutil/meson.build @@ -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', diff --git a/src/libutil/util.hh b/src/libutil/util.hh index ac4aa1d3a..5adabae28 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -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. |