This repository was archived by the owner on Apr 20, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555
5656 ConnectableObservable . prototype . connect = function ( ) {
5757 if ( ! this . _connection ) {
58+ if ( this . _subject . isStopped ) {
59+ return disposableEmpty ;
60+ }
5861 var subscription = this . _source . subscribe ( this . _subject ) ;
5962 this . _connection = new ConnectDisposable ( this , subscription ) ;
6063 }
Original file line number Diff line number Diff line change 11( function ( ) {
22 'use strict' ;
33 /* jshint undef: true, unused: true */
4- /* globals QUnit, test, Rx */
4+ /* globals QUnit, test, Rx, equal */
55
66 QUnit . module ( 'multicast' ) ;
77
478478 subscribe ( 200 , 390 ) ) ;
479479 } ) ;
480480
481+ // adapted from issue Reactive-Extensions/RxJS#1112
482+ test ( "multicast should not reconnect when stopped" , function ( ) {
483+ var scheduler = new TestScheduler ( ) ;
484+
485+ var results = scheduler . createObserver ( ) ;
486+
487+ var calls = 0 ;
488+
489+ function request ( v ) {
490+ calls ++ ;
491+ return v * 2 ;
492+ }
493+
494+ var xs = scheduler . createColdObservable (
495+ onNext ( 1 , 1 ) ,
496+ onNext ( 2 , 2 ) ,
497+ onNext ( 3 , 3 ) ,
498+ onCompleted ( 4 ) ) ;
499+
500+ var c , s ;
501+
502+ scheduler . scheduleAbsolute ( null , 300 , function ( ) {
503+ c = new Rx . AnonymousObservable ( function ( o ) {
504+ return xs . subscribe (
505+ function ( x ) { o . onNext ( request ( x ) ) ; } ,
506+ function ( e ) { o . onError ( e ) ; } ,
507+ function ( ) { o . onCompleted ( ) ; } ) ;
508+ } ) . multicast ( new Subject ( ) ) ;
509+ c . subscribe ( results ) ;
510+ s = c . connect ( ) ;
511+ } ) ;
512+
513+ scheduler . scheduleAbsolute ( null , 400 , function ( ) {
514+ s . dispose ( ) ;
515+ c . connect ( ) ;
516+ } ) ;
517+
518+ scheduler . start ( ) ;
519+
520+ equal ( calls , 3 ) ;
521+
522+ results . messages . assertEqual (
523+ onNext ( 301 , 2 ) ,
524+ onNext ( 302 , 4 ) ,
525+ onNext ( 303 , 6 ) ,
526+ onCompleted ( 304 ) ) ;
527+ } ) ;
528+
481529} ( ) ) ;
You can’t perform that action at this time.
0 commit comments