fail.h 585 B

1234567891011121314151617181920212223
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include <rpl/producer.h>
  9. namespace rpl {
  10. template <typename Value, typename Error>
  11. inline auto fail(Error &&error) {
  12. return make_producer<Value, std::decay_t<Error>>([
  13. error = std::forward<Error>(error)
  14. ](const auto &consumer) mutable {
  15. consumer.put_error(std::move(error));
  16. return lifetime();
  17. });
  18. }
  19. } // namespace rpl