using System;
using System.Collections.Generic;

namespace System.Reactive.Linq.ObservableImpl
{
	internal sealed class While<TSource> : Producer<TSource, While<TSource>._>, IConcatenatable<TSource>
	{
		public While(Func<bool> condition, IObservable<TSource> source)
		{
			this._condition = condition;
			this._source = source;
		}

		protected override While<TSource>._ CreateSink(IObserver<TSource> observer)
		{
			return new While<TSource>._(observer);
		}

		protected override void Run(While<TSource>._ sink)
		{
			sink.Run(this.GetSources());
		}

		public IEnumerable<IObservable<TSource>> GetSources()
		{
			While<TSource>.<GetSources>d__5 <GetSources>d__ = new While<TSource>.<GetSources>d__5(-2);
			<GetSources>d__.<>4__this = this;
			return <GetSources>d__;
		}

		private readonly Func<bool> _condition;

		private readonly IObservable<TSource> _source;

		internal sealed class _ : ConcatSink<TSource>
		{
			public _(IObserver<TSource> observer)
				: base(observer)
			{
			}
		}
	}
}
