For the following code
const foo = new Observable((subscriber) => {
console.log('Hello');
subscriber.next(42);
subscriber.next(100);
subscriber.next(200);
setTimeout(() => {
subscriber.next(300);
}, 1000);
});
console.log('before');
foo.subscribe((x) => {
console.log('a', x);
});
foo.subscribe((x) => {
console.log('b', x);
});
console.log('after');
When I used RxJS, I got the following output
before
Hello
a 42
a 100
a 200
Hello
b 42
b 100
b 200
after
a 300
b 300
When I used WICG Observable (tested in Chrome 150), I got the following output
before
Hello
a 42
a 100
a 200
after
a 300
b 300
The behavior of the two is different. It seems that RxJS is new every time it subscribes, while WICG Observable reuses the ongoing Observable.
I want to know if this is the expected behavior of WICG Observable or a bug in the browser implementation.
If this is an expected behavior, I would like to know the background or reason for this design?