ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
timeout.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/schedulers/constraints.hpp>
14#include <rpp/sources/fwd.hpp>
15#include <rpp/observables/constraints.hpp>
16#include <rpp/observables/details/member_overload.hpp>
17
18namespace rpp::details
19{
20struct timeout_tag;
21}
22
23namespace rpp::details
24{
25template<constraint::decayed_type Type, constraint::observable_of_type<Type> FallbackObs, schedulers::constraint::scheduler TScheduler>
26struct timeout_impl;
27
28template<constraint::decayed_type Type, typename SpecificObservable>
29struct member_overload<Type, SpecificObservable, timeout_tag>
30{
52 template<constraint::observable_of_type<Type> FallbackObs, schedulers::constraint::scheduler TScheduler>
53 auto timeout(schedulers::duration period, FallbackObs&& fallback_obs, const TScheduler& scheduler = TScheduler{}) const & requires is_header_included<timeout_tag, FallbackObs, TScheduler>
54 {
55 return static_cast<const SpecificObservable*>(this)->template lift<Type>(timeout_impl<Type, std::decay_t<FallbackObs>, TScheduler>{period, std::forward<FallbackObs>(fallback_obs), scheduler});
56 }
57
58 template<constraint::observable_of_type<Type> FallbackObs,schedulers::constraint::scheduler TScheduler>
59 auto timeout(schedulers::duration period, FallbackObs&& fallback_obs, const TScheduler& scheduler = TScheduler{}) && requires is_header_included<timeout_tag, FallbackObs, TScheduler>
60 {
61 return std::move(*static_cast<SpecificObservable*>(this)).template lift<Type>(timeout_impl<Type, std::decay_t<FallbackObs>, TScheduler>{period, std::forward<FallbackObs>(fallback_obs), scheduler});
62 }
63
83 template<schedulers::constraint::scheduler TScheduler>
84 auto timeout(schedulers::duration period, const TScheduler& scheduler = TScheduler{}) const & requires is_header_included<timeout_tag, TScheduler>
85 {
86 return timeout(period, rpp::source::error<Type>(std::make_exception_ptr(utils::timeout{"Timeout reached"})), scheduler);
87 }
88
89 template<schedulers::constraint::scheduler TScheduler>
90 auto timeout(schedulers::duration period, const TScheduler& scheduler = TScheduler{}) && requires is_header_included<timeout_tag, TScheduler>
91 {
92 return std::move(*static_cast<SpecificObservable*>(this)).timeout(period, rpp::source::error<Type>(std::make_exception_ptr(utils::timeout{"Timeout reached"})), scheduler);
93 }
94
95
96};
97} // namespace rpp::details
Definition: member_overload.hpp:19
Definition: timeout.hpp:68