var sourceInit = Rx.Observable.timer(0, 1000)
.do(x => console.log('timer', x))
let source = sourceInit.map(x => x*10)
source.subscribe(x => {
console.log('x', x)
})
source.subscribe(x => {
console.log('x2', x)
})
The outpu I've got:
timer 0
x 0
timer 0
x2 0
timer 1
x 10
timer 1
x2 10
timer 2
x2 20
timer 2
I need have only single subscription to timer and output like this:
timer 0
x 0
x2 0
timer 1
x 10
x2 10
timer 2
x 20
x2 20
What is the correct approach to this problem should be?
I got with this approach using subject:
var sourceInit = Rx.Observable.timer(0, 1000)
.do(x => console.log('timer', x))
var source = new Rx.Subject();
sourceInit.subscribe(source)
source.subscribe(x => {
console.log('x', x)
})
source.subscribe(x => {
console.log('x2', x)
})
Is it correct and only one?