summaryrefslogtreecommitdiff
path: root/Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp')
-rw-r--r--Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp b/Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp
new file mode 100644
index 0000000..35e000f
--- /dev/null
+++ b/Rx/v2/src/rxcpp/operators/rx-connect_forever.hpp
@@ -0,0 +1,58 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
+
+#pragma once
+
+#if !defined(RXCPP_OPERATORS_RX_CONNECT_FOREVER_HPP)
+#define RXCPP_OPERATORS_RX_CONNECT_FOREVER_HPP
+
+#include "../rx-includes.hpp"
+
+namespace rxcpp {
+
+namespace operators {
+
+namespace detail {
+
+template<class T, class ConnectableObservable>
+struct connect_forever : public operator_base<T>
+{
+ typedef typename std::decay<ConnectableObservable>::type source_type;
+
+ source_type source;
+
+ explicit connect_forever(source_type o)
+ : source(std::move(o))
+ {
+ source.connect();
+ }
+
+ template<class Subscriber>
+ void on_subscribe(Subscriber&& o) {
+ source.subscribe(std::forward<Subscriber>(o));
+ }
+};
+
+class connect_forever_factory
+{
+public:
+ connect_forever_factory() {}
+ template<class Observable>
+ auto operator()(Observable&& source)
+ -> observable<typename std::decay<Observable>::type::value_type, connect_forever<typename std::decay<Observable>::type::value_type, Observable>> {
+ return observable<typename std::decay<Observable>::type::value_type, connect_forever<typename std::decay<Observable>::type::value_type, Observable>>(
+ connect_forever<typename std::decay<Observable>::type::value_type, Observable>(std::forward<Observable>(source)));
+ }
+};
+
+}
+
+inline auto connect_forever()
+ -> detail::connect_forever_factory {
+ return detail::connect_forever_factory();
+}
+
+}
+
+}
+
+#endif