javascript - Does startWith() operator turns Observable into ReplaySubject(1)? -


if want subscribers @ least x, can use startwith( x ) existing observable:

streamfromlibrary.startwith( x ).subscribe( myhandler ); //i want myhandler() not wait until streamfromlibrary produce value //but called instantly x 

or still needs carried through intermediate replaysubject( 1 ) this?

let carrier = new rx.replaysubject( 1 ); carrier.next( x ); streamfromlibrary.subscribe( value => carrier.next( value ) ); carrier.subscribe( myhandler ); 

or if not, there other more elegant way carry values existing streams subscription @ least 1 initial/last value?

you don't need use replaysubject, should know these 2 aren't same:

  • the startwith() operator emits preset value every observer when subscribe.

  • the replaysubject(1) class re-emits 1 last item went through it. first value emits every observer might not same depending on pushed subject.

note, there's behaviorsubject takes initial value parameter , overrides every emission works replaysubject(1).

however there's 1 important distinction. when behaviorsubject receives complete notification never ever emits anything. on other hand replaysubject replays buffer every observer though has received complete notification.

also when using subjects might find interesting: subject , internal state


Comments

Popular posts from this blog

python - Best design pattern for collection of objects -

android - IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling -

go - serving up pdfs using golang -