Observable.Next bug?
-
Tuesday, January 24, 2012 10:30 PM
Observable.Next is a blocking but non buffering conversion from IObservable to IEnumerable.
However it seems to be naive in that is does not cache any notification. I think it should at least cache OnError and OnCompleted. As it doesn't, if the enumerator is busy when the sequence completes or error's, the enumerator will miss it and then be left hanging for ever. :(
Code to reproduce
Console.WriteLine("{0:o} Starting", DateTime.Now); var source = Observable.Interval(TimeSpan.FromSeconds(1)) .Take(4); var result = source.Next(); foreach (var element in result) { Console.WriteLine("{0:o} {1}", DateTime.Now, element); Thread.Sleep(2000); //Misses the OnCompleted } //Never gets called. Console.WriteLine("{0:o} done", DateTime.Now); /* Output: 2012-01-01T12:00:00.0000000 Starting 2012-01-01T12:00:01.1000000 1 2012-01-01T12:00:03.1000000 3 */
Lee
Lee Campbell http://LeeCampbell.blogspot.com- Edited by LeeCampbell Tuesday, January 24, 2012 10:32 PM Naively to Naive
All Replies
-
Wednesday, January 25, 2012 3:08 AM
Hi Lee,
Have you seen "Latest"
Console.WriteLine("{0:o} Starting", DateTime.Now); var source = Observable.Interval(TimeSpan.FromSeconds(1)) .Take(4); var result = source.Latest(); foreach (var element in result) { Console.WriteLine("{0:o} {1}", DateTime.Now, element); Thread.Sleep(2000); //Misses the OnCompleted } //Never gets called. Console.WriteLine("{0:o} done", DateTime.Now);
OUTPUT
2012-01-25T11:07:41.6905541+08:00 Starting
2012-01-25T11:07:42.7483202+08:00 0
2012-01-25T11:07:44.7486018+08:00 2
2012-01-25T11:07:46.7498601+08:00 done
James Miles http://enumeratethis.com -
Wednesday, January 25, 2012 7:59 AM
Yes! And MostRecent(T), but I still think Next has a bug. Also the symantic for Latest and Next are different. Latest will cache a value (ie give you the value 2 not 3) but Next will not cache that value and block until it gets the next value (ie 3).
Lee Campbell http://LeeCampbell.blogspot.com -
Wednesday, January 25, 2012 8:21 AM
Yes, there is a slight difference in behaviour. Note however that Latest will only give you a cached value if you have not previously observed that value.
Next's behaviour used to be consistent with Subject<T> however Subject<T> has been changed so that it caches OnError & OnComplete notifications. Perhaps they need to revaluate Next's behaviour as well!
PS. I'd recommend changing the Topic type to question... otherwise they will never look at it! ;)
James Miles http://enumeratethis.com- Edited by James Miles Wednesday, January 25, 2012 8:22 AM
-
Wednesday, January 25, 2012 8:27 AMOwnerInfinite blocking is not desirable in this case, so I'm considering it to be a bug. We'll look into it for a future release. Thanks for letting us know!
using (Microsoft.Sql.Cloud.DataProgrammability.Rx) { Signature.Emit("Bart De Smet"); }

