diff options
author | Valery Kopylov <v-valkop@microsoft.com> | 2015-06-09 15:19:53 +0300 |
---|---|---|
committer | Valery Kopylov <v-valkop@microsoft.com> | 2015-06-09 15:19:53 +0300 |
commit | 2482b20a4a2d631b61002497af8ce72aacc842a2 (patch) | |
tree | ecf7741c811f396a47106982d91becb283802378 | |
parent | cffd1189771d80e7dd244701bf76819cadf17758 (diff) | |
download | RxCpp-2482b20a4a2d631b61002497af8ce72aacc842a2.tar.gz |
Use subscribe_with_rethrow for blocking first and last.
-rw-r--r-- | Rx/v2/examples/doxygen/blocking_observable.cpp | 3 | ||||
-rw-r--r-- | Rx/v2/src/rxcpp/rx-observable.hpp | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/Rx/v2/examples/doxygen/blocking_observable.cpp b/Rx/v2/examples/doxygen/blocking_observable.cpp index ee94013..1e7dd56 100644 --- a/Rx/v2/examples/doxygen/blocking_observable.cpp +++ b/Rx/v2/examples/doxygen/blocking_observable.cpp @@ -25,8 +25,7 @@ SCENARIO("blocking first empty sample"){ SCENARIO("blocking first error sample"){ printf("//! [blocking first error sample]\n"); - auto values = rxcpp::observable<>::range(1, 3). - concat(rxcpp::observable<>::error<int>(std::runtime_error("Error from source"))). + auto values = rxcpp::observable<>::error<int>(std::runtime_error("Error from source")). as_blocking(); try { auto first = values.first(); diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp index 8675820..cf2a381 100644 --- a/Rx/v2/src/rxcpp/rx-observable.hpp +++ b/Rx/v2/src/rxcpp/rx-observable.hpp @@ -305,8 +305,12 @@ public: */ T first() { rxu::maybe<T> result; + rxu::maybe<std::exception_ptr> error; composite_subscription cs; - subscribe_with_rethrow(cs, [&](T v){result.reset(v); cs.unsubscribe();}); + subscribe_with_rethrow( + cs, + [&](T v){result.reset(v); cs.unsubscribe();}, + [&](std::exception_ptr){}); if (result.empty()) throw rxcpp::empty_error("first() requires a stream with at least one value"); return result.get(); @@ -332,9 +336,7 @@ public: rxu::maybe<std::exception_ptr> error; subscribe_with_rethrow( [&](T v){result.reset(v);}, - [&](std::exception_ptr ep){error.reset(ep);}); - if (!error.empty()) - std::rethrow_exception(error.get()); + [&](std::exception_ptr){}); if (result.empty()) throw rxcpp::empty_error("last() requires a stream with at least one value"); return result.get(); |