5 #if !defined(RXCPP_SOURCES_RX_ERROR_HPP) 6 #define RXCPP_SOURCES_RX_ERROR_HPP 8 #include "../rx-includes.hpp" 38 template<
class T,
class Coordination>
39 struct error :
public source_base<T>
41 typedef error<T, Coordination> this_type;
43 typedef rxu::decay_t<Coordination> coordination_type;
45 typedef typename coordination_type::coordinator_type coordinator_type;
47 struct error_initial_type
49 error_initial_type(std::exception_ptr e, coordination_type cn)
51 , coordination(std::move(cn))
54 std::exception_ptr exception;
55 coordination_type coordination;
57 error_initial_type initial;
59 error(std::exception_ptr e, coordination_type cn)
60 : initial(e, std::move(cn))
64 template<
class Subscriber>
65 void on_subscribe(Subscriber o)
const {
68 auto coordinator = initial.coordination.create_coordinator(o.get_subscription());
69 auto controller = coordinator.get_worker();
70 auto exception = initial.exception;
72 auto producer = [=](
const rxsc::schedulable&){
74 if (!dest.is_subscribed()) {
79 dest.on_error(exception);
83 [&](){
return coordinator.act(producer);},
85 if (selectedProducer.empty()) {
88 controller.schedule(selectedProducer.get());
92 struct throw_ptr_tag{};
93 struct throw_instance_tag{};
95 template <
class T,
class Coordination>
96 auto make_error(throw_ptr_tag&&, std::exception_ptr exception, Coordination cn)
97 -> observable<T, error<T, Coordination>> {
98 return observable<T, error<T, Coordination>>(error<T, Coordination>(std::move(exception), std::move(cn)));
101 template <
class T,
class E,
class Coordination>
102 auto make_error(throw_instance_tag&&, E e, Coordination cn)
103 -> observable<T, error<T, Coordination>> {
104 std::exception_ptr exception;
105 try {
throw e;}
catch(...) {exception = std::current_exception();}
106 return observable<T, error<T, Coordination>>(error<T, Coordination>(std::move(exception), std::move(cn)));
113 template<
class T,
class E>
115 -> decltype(detail::make_error<T>(
typename std::conditional<std::is_same<std::exception_ptr,
rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e),
identity_immediate())) {
116 return detail::make_error<T>(
typename std::conditional<std::is_same<std::exception_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e),
identity_immediate());
120 template<
class T,
class E,
class Coordination>
122 -> decltype(detail::make_error<T>(
typename std::conditional<std::is_same<std::exception_ptr,
rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), std::move(cn))) {
123 return detail::make_error<T>(
typename std::conditional<std::is_same<std::exception_ptr, rxu::decay_t<E>>::value, detail::throw_ptr_tag, detail::throw_instance_tag>::type(), std::move(e), std::move(cn));
Definition: rx-all.hpp:26
auto error(E e) -> decltype(detail::make_error< T >(typename std::conditional< std::is_same< std::exception_ptr, rxu::decay_t< E >>::value, detail::throw_ptr_tag, detail::throw_instance_tag >::type(), std::move(e), identity_immediate()))
Returns an observable that sends no items to observer and immediately generates an error...
Definition: rx-error.hpp:114
typename std::decay< T >::type decay_t
Definition: rx-util.hpp:36
identity_one_worker identity_immediate()
Definition: rx-coordination.hpp:170
auto on_exception(const F &f, const OnError &c) -> typename std::enable_if< detail::is_on_error< OnError >::value, typename detail::maybe_from_result< F >::type >::type
Definition: rx-observer.hpp:639