wait.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include "fwd.h"
  3. #include <library/cpp/threading/future/core/future.h>
  4. #include <library/cpp/threading/future/wait/wait_group.h>
  5. #include <util/generic/array_ref.h>
  6. namespace NThreading {
  7. namespace NImpl {
  8. template <class TContainer>
  9. using EnableGenericWait = std::enable_if_t<
  10. !std::is_convertible_v<TContainer, TArrayRef<const TFuture<void>>>,
  11. TFuture<void>>;
  12. }
  13. // waits for all futures
  14. [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1);
  15. [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1, const TFuture<void>& f2);
  16. [[nodiscard]] TFuture<void> WaitAll(TArrayRef<const TFuture<void>> futures);
  17. template <typename TContainer>
  18. [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAll(const TContainer& futures);
  19. // waits for the first exception or for all futures
  20. [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1);
  21. [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1, const TFuture<void>& f2);
  22. [[nodiscard]] TFuture<void> WaitExceptionOrAll(TArrayRef<const TFuture<void>> futures);
  23. template <typename TContainer>
  24. [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitExceptionOrAll(const TContainer& futures);
  25. // waits for any future
  26. [[nodiscard]] TFuture<void> WaitAny(const TFuture<void>& f1);
  27. [[nodiscard]] TFuture<void> WaitAny(const TFuture<void>& f1, const TFuture<void>& f2);
  28. [[nodiscard]] TFuture<void> WaitAny(TArrayRef<const TFuture<void>> futures);
  29. template <typename TContainer>
  30. [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAny(const TContainer& futures);
  31. }
  32. #define INCLUDE_FUTURE_INL_H
  33. #include "wait-inl.h"
  34. #undef INCLUDE_FUTURE_INL_H