Skip to content

Instantly share code, notes, and snippets.

@akarnokd
Last active May 27, 2018 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akarnokd/6638bbfd89df9e5d4848d7d6489cbc22 to your computer and use it in GitHub Desktop.
Save akarnokd/6638bbfd89df9e5d4848d7d6489cbc22 to your computer and use it in GitHub Desktop.
namespace System.Reactive.Linq
{
/// <summary>
/// Provides a set of static methods for writing in-memory queries over observable sequences.
/// </summary>
public static class ObservableEx
{
private static IQueryLanguageEx _override;
/// <summary>
/// Override the default implementation of operators.
/// </summary>
public static IQueryLanguageEx Override
{
get { return Volatile.Read(ref _override); }
set { Interlocked.Exchange(ref _override, value); }
}
[Experimental]
public static IObservable<TResult> Create<TResult>(Func<IObserver<TResult>, IEnumerable<IObservable<object>>> iteratorMethod)
{
if (iteratorMethod == null)
throw new ArgumentNullException(nameof(iteratorMethod));
var ovr = Override;
if (ovr != null)
{
return ovr.Create(iteratorMethod);
}
return new AnonymousObservable<TResult>(observer =>
iteratorMethod(observer).Concat().Subscribe(_ => { }, observer.OnError, observer.OnCompleted));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment