Reputation: 2063
EDIT:
Closing this one because I was an Idiot and didn't realize that my GetLogEntries()
method was buggy: I did some time computations in there, and instead of using TimeSpan.TotalMilliSeconds
, I was using TimeSpan.Milliseconds
.
Yeah.
Original Question:
Given the following 4 methods, where the 3 first work just fine, but the last doesn't, I can't figure out why the last one doesn't.
I just can't figure out why TestCase4() doesn't work. Am I missing something?
public void Case1()
{
var a = Observable.Interval(TimeSpan.FromSeconds(1));
var b = a.Buffer(TimeSpan.FromSeconds(1));
b.Subscribe(x =>
{
// yep, this is called every second
});
}
public void Case2()
{
var a = Observable.Interval(TimeSpan.FromSeconds(1));
var b = a.Buffer(() => Observable.Interval(TimeSpan.FromSeconds(1)));
b.Subscribe(x =>
{
// yep, this is also called every second
});
}
public void Case3()
{
IObservable<LogEntry> source = this.LogsProvider.GetLogEntries();
var buffered = source.Buffer(TimeSpan.FromSeconds(1));
buffered.Subscribe(logentriesList =>
{
// yep, I get an IList<LogEntry> each second.
});
}
public void Case4()
{
IObservable<LogEntry> source = this.LogsProvider.GetLogEntries();
var buffered = source.Buffer(() => Observable.Interval(TimeSpan.FromSeconds(1)));
buffered.Subscribe(logentriesList =>
{
// nope, I never get here.. Why ? Case3() works as expected...
// Isn't this just the same as Case2() vs Case1(), where Case2() actually works?
});
}
Upvotes: 0
Views: 504
Reputation: 29776
The implementations of the two overloads of Buffer()
you are experimenting with are (unsurprisingly) quite different - but I think this is a red herring. The outcome should be the same given the way you are using them.
As Dave Sexton hinted in his comment, the code you have shown omits two vital parts:
GetLogEntries()
Case<n>
methodsI would be extremely surprised if the Buffer
implementation is broken. Also, the code you have shown correctly calls the Buffer
overloads.
Therefore the most likely explanation is that the problem is in the omitted code.
I note that you are calling GetLogEntries()
on an instance (this.LogsProvider
) that is possibly shared between Case3
and Case4
. I strongly suspect this is the case and that your invocation of GetLogEntries()
is not idempotent and has side effects causing the second invocation to return no entries. Does it perhaps return the latest unreported log entries each time?
Upvotes: 3