From cb42db9eaa8dc288e42584d1ae892b8b811a28f9 Mon Sep 17 00:00:00 2001 From: Kirk Shoop Date: Wed, 19 Mar 2014 18:11:40 -0700 Subject: switch subscribe from observer to subscriber --- Rx/v2/src/rxcpp/rx-test.hpp | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'Rx/v2/src/rxcpp/rx-test.hpp') diff --git a/Rx/v2/src/rxcpp/rx-test.hpp b/Rx/v2/src/rxcpp/rx-test.hpp index 946ec03..e519cf8 100644 --- a/Rx/v2/src/rxcpp/rx-test.hpp +++ b/Rx/v2/src/rxcpp/rx-test.hpp @@ -18,7 +18,7 @@ struct test_subject_base typedef rxn::recorded::type> recorded_type; typedef std::shared_ptr> type; - virtual void on_subscribe(observer) const =0; + virtual void on_subscribe(subscriber) const =0; virtual std::vector messages() const =0; virtual std::vector subscriptions() const =0; }; @@ -30,29 +30,35 @@ struct test_source explicit test_source(typename test_subject_base::type ts) : ts(std::move(ts)) { + if (!this->ts) abort(); } typename test_subject_base::type ts; - void on_subscribe(observer o) const { + void on_subscribe(subscriber o) const { ts->on_subscribe(std::move(o)); } - template - typename std::enable_if::type, observer>::value, void>::type - on_subscribe(Observer o) const { - auto so = std::make_shared(o); - ts->on_subscribe(make_observer_dynamic( - so->get_subscription(), - // on_next - [so](T t){ - so->on_next(t); - }, - // on_error - [so](std::exception_ptr e){ - so->on_error(e); - }, - // on_completed - [so](){ - so->on_completed(); - })); + template + typename std::enable_if::type, subscriber>::value, void>::type + on_subscribe(Subscriber&& o) const { + + static_assert(is_subscriber::value, "on_subscribe must be passed a subscriber."); + + auto so = std::make_shared::type>(std::forward(o)); + ts->on_subscribe( + make_subscriber( + *so, + make_observer_dynamic( + // on_next + [so](T t){ + so->on_next(t); + }, + // on_error + [so](std::exception_ptr e){ + so->on_error(e); + }, + // on_completed + [so](){ + so->on_completed(); + }))); } }; -- cgit v1.2.3