yarpl/test/Flowable_lifecycle.cpp
/**
 * Test how things behave when the Flowable goes out of scope.
 * The Handler class is *just* the onSubscribe func. The real lifetime
 * is in the Subscription which the Handler kicks off via a 'new' to
 * put on the heap.
 *
 * @param scheduler
 * @param subscriber
 */
Test how things behave when the Flowable goes out of scope.
The Handler class is *just* the onSubscribe func. The real lifetime
is in the Subscription which the Handler kicks off via a 'new' to
put on the heap.

@param scheduler
@param subscriber
Test how things behave when the Flowable goes out of scope . The Handler class is * just * the onSubscribe func . The real lifetime is in the Subscription which the Handler kicks off via a ' new ' to put on the heap . @param scheduler @param subscriber
static auto runHandlerFlowable(Scheduler& scheduler) {
  class Handler {
   public:
    Handler() = default;
    ~Handler() {
      std::cout << "DESTROY Handler" << std::endl;
    }
    Handler(Handler&&) = default; 
    Handler(const Handler&) = delete;
    Handler& operator=(Handler&&) = default; 
    Handler& operator=(const Handler&) = delete;
    void operator()(std::unique_ptr<Subscriber<long>> s) {
      std::this_thread::sleep_for(std::chrono::milliseconds(500));
      auto s_ =
          new yarpl::flowable::sources::RangeSubscription(1, 100, std::move(s));
      s_->start();
    }
  };
  return Flowable<long>::create(Handler())->subscribeOn(scheduler)->take(50);
}
static auto runHandlerFlowable ( Scheduler & scheduler ) { class Handler { public : Handler ( ) = default ; ~ Handler ( ) { std :: cout << " " << std :: endl ; } Handler ( Handler && ) = default ; Handler ( const Handler & ) = delete ; Handler & operator = ( Handler && ) = default ; Handler & operator = ( const Handler & ) = delete ; void operator () ( std :: unique_ptr < Subscriber < long > > s ) { std :: this_thread :: sleep_for ( std :: chrono :: milliseconds ( 500 ) ) ; auto s_ = new yarpl :: flowable :: sources :: RangeSubscription ( 1 , 100 , std :: move ( s ) ) ; s_ -> start ( ) ; } } ; return Flowable < long > :: create ( Handler ( ) ) -> subscribeOn ( scheduler ) -> take ( 50 ) ; }
Test how things behave when the Flowable goes out of scope.
Test how things behave when the Flowable goes out of scope .
// only allow std::move // only allow std::move // want to test that lifecycle works when thread scheduling occurs /* sleep override */