diff options
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. |