jamespconnor
jamespconnor

Reputation: 1412

Rx IObservable - return first IObservable stream to get a value

I am creating two (or more) IObservable<T>s of all the same T. They have been generated from Task<IEnumerable<T>> of which one can come back quicker than the others. All I care about is the IObservable which returns the first value - this is the one that I use from then on.

I remember attending a Jon Skeet presentation in Cambridge where he did exactly this using the TPL in a very neat way but I can't remember how! Ideally I'd get a method something like this:

IObservable<T> PickFastestObservable<T>(IEnumerable<IObservable<T>> slowObservables);

But if I had to do it on the tasks directly, I could probably work something out.

I'm struggling to get something up myself that I'm confident with.

Cheers,

Upvotes: 0

Views: 169

Answers (1)

Lee
Lee

Reputation: 144126

I think you want Observable.Amb e.g.

IObservable<T> fastest = slowObservables.Amb();

Upvotes: 5

Related Questions