public static ISingle <T> Amb <T>(this IEnumerable <ISingle <T> > sources) { return(Create <T>(s => { AmbSingleSubscriber <T> ambs = new AmbSingleSubscriber <T>(s); s.OnSubscribe(ambs); int c = 0; foreach (ISingle <T> a in sources) { if (ambs.IsDisposed()) { break; } a.Subscribe(ambs); c++; } if (c == 0 && !ambs.IsDisposed()) { s.OnError(NoSuchElementException()); } })); }
public static ISingle <T> Amb <T>(this ISingle <T>[] sources) { if (sources.Length == 0) { return(Throw <T>(() => NoSuchElementException())); } return(Create <T>(s => { AmbSingleSubscriber <T> ambs = new AmbSingleSubscriber <T>(s); s.OnSubscribe(ambs); foreach (ISingle <T> a in sources) { if (ambs.IsDisposed()) { break; } a.Subscribe(ambs); } })); }