-
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
Observable.bufferWhen emits data before trigger if source observable completes #2361
Comments
Thought I should put the workaround in this issue too where it's more relevant. Zip with the trigger after the buffer gives the expected behaviour. import * as Rx from 'rxjs/Rx';
import {ISuiteCallbackContext} from 'mocha';
describe('Experiment with Observable buffer', function (this: ISuiteCallbackContext) {
this.timeout(10000);
it('Demonstrates a bug with bufferWhen', () => {
const src = Rx.Observable.interval(5).take(10);
const interval = Rx.Observable.interval(1000);
const trigger = new Rx.Subject<number>();
interval
.do(n => console.log('Trigger'))
.subscribe(trigger);
return src
.bufferWhen(() => trigger)
.zip(trigger, src => src)
.do(v => console.log(v))
.toArray()
.toPromise()
.then(values => {
console.log(values);
console.log('done.');
});
// Actual output:
// Trigger
// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
// [ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ]
// done.
// Expected output:
// Trigger
// [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
// [ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ]
// done.
});
}); |
Nice workaround. Cool idea with the zip. |
Closing as stale |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
RxJS version:
5.1.0
Code to reproduce:
Expected behavior:
I would expect that bufferWhen should only emit when the closingSelect (trigger) emits a value.
Actual behavior:
bufferWhen emits as soon as src is complete. That is unexpected and undesired.
Additional information:
This is an attempt at working around #2154. The issue there is that it doesn't emit at all.
The text was updated successfully, but these errors were encountered: