Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Last active January 4, 2016 07:49
Show Gist options
  • Save dtchepak/8591632 to your computer and use it in GitHub Desktop.
Save dtchepak/8591632 to your computer and use it in GitHub Desktop.
//Extensions.cs
public static IObservable<T> ObservableFunc<T>(this Func<T> f) {
return Observable.Create<T>(obs => {
try {
obs.OnNext(f());
obs.OnCompleted();
} catch (Exception e) {
obs.OnError(e);
}
return () => {};
});
}
//Other.cs
var info = Observable
.Interval(TimeSpan.FromMilliseconds(450))
.SelectMany(_ => getInfo.ObservableFunc()) // getInfo is a Func<T> that can throw
.TakeUntil(done);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment