-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different behavior with Rx 4 and buffer #1610
Comments
The default scheduler in RxJS 5 is the Buffer first subscribes to the closing notifier If you do this const a = Rx.Observable.of(1, 2, 3, 4)
.subscribeOn(Rx.Scheduler.async)
.share();
a
.buffer(a.filter(x => x % 2 === 0))
.subscribe(x => console.log(x)); You'll notice the output [1]
[2, 3] Which makes sense if you see that You can do it with scan though: Rx = Rx.KitchenSink;
const a = Rx.Observable.of(1, 2, 3, 4)
.scan(({ready, arr}, i) => {
if (i % 2 === 0) {
return {ready: true, arr: arr.concat(i)};
} else if (ready) {
return {ready: false, arr: [i]};
} else {
return {ready: false, arr: arr.concat(i)}
}
}, {ready: false, arr: []})
.filter(acc => acc.ready)
.map(acc => acc.arr)
.subscribe(x => console.log(x));
|
@staltz I would argue that this is a breaking change for no good reason and is in fact a bug |
Summary:This change upgrades us to the RxJS 5 beta. It includes: * Update Flow definitions to reflect new APIs * Add `DisposableSubscription` and `CompositeSubscription` for dealing with new Subscription API (See also ReactiveX/rxjs#1583) * Add `bufferUntil` to replace some `buffer()` usages (See ReactiveX/rxjs#1610) * Remove rx-dom * Update package.json * Update all code to use new APIs Reviewed By: peterhal Differential Revision: D3131543 fb-gh-sync-id: 437c7b90d6e1fd8e463a57eb341146bbc4e9bbd3 fbshipit-source-id: 437c7b90d6e1fd8e463a57eb341146bbc4e9bbd3
There there were several really good reasons for this breaking change.
Other things:
|
Also, the sample code is really an illustration of an anti-pattern in Rx: shared synchronous observables with |
@trxcllnt I disagree
|
Setting aside the sync issue for a sec, the results are different for async too: const a = Observable.interval(1000).take(5).share();
a
.buffer(a.filter(x => x % 2 === 0))
.subscribe(x => console.log(x)); 4:
5:
|
In v4 |
This is probably a source of the real issue here. |
@mattpodwysocki I whole-heartedly agree with you. Now that we've got the
|
@trxcllnt so you're saying that you agree with @mattpodwysocki's assertion that we should be trampoline scheduling by default? (if I'm understanding his assertions correctly). Because I'm against that. It would be counter to many of the stated goals of this project |
@Blesh oh no, just that this is a bug. the recursive vs. trampoline scheduling was settled a long time ago by RxJava. |
Yeah, I think we all agree this is a bug. |
Leaving this open, as we'll have this change in the next major version (as it's breaking for some users) |
…2195) In buffer operator subscribe to source observable first, so that when closingNotifier emits value, all source values emited before land in buffer Closes #1610 BREAKING CHANGE: When source and closingNotifier fire at the same time, it is expected that value emitted by source will first land in buffer and then closingNotifier will close it. Because of reversed subscription order, closingNotifier emitted first, so source was not able to put value in buffer before it was closed. Now source is subscribed before closingNotifier, so if they fire at the same time, source value is put into buffer and then closingNotifer closes it.
Just got tripped up by this. Three questions:
source$.publish(stream$ => stream$.buffer(stream$.throttle(100))); becomes source$.publish(stream$ => {
const sub$ = new Subject();
stream$.subscribe(sub$);
return sub$.buffer(stream$.throttle(100));
});
I wonder however what the expected behaviour is of the notifier in some of these other cases given that it may be intended to be inclusive or exclusive (consider Note that Also, things like |
Related #5654 |
We are migrating from v4 -> v5 and stumbled upon this behavior change. Is there a workaround for this (since judging by the comments it will most likely not be fixed in v5)? (I'm sorry if it has already been stated, but it's not very clear to me) |
@XeniaSiskaki :) This is just expected behavior and not a bug we'd be fixing. I guess it would really depend on your code and what your goal is. It might be best to post a question about what you're trying to do on Stackoverflow with some code examples. In RxJS 7.x you can use the import { share, buffer, filter, scheduled, asapScheduler } from 'rxjs';
const a = scheduled([1, 2, 3, 4], asapScheduler).pipe(share());
a.pipe(buffer(a.pipe(filter((x) => x % 2 === 0)))).subscribe((x) =>
console.log(x)
);
// [1, 2]
// [3, 4]
// [] See this Stackblitz to play around with it (I'm going to close this issue though, because it's super old and not a bug. haha) |
RxJS version: 5.0.0-beta5
Code to reproduce:
Expected behavior:
Actual behavior:
Additional information:
The "expected behavior" is what Rx 4 does, but maybe there's a more correct way to do this?
The text was updated successfully, but these errors were encountered: