automatonic automatonic - 1 year ago 102
C# Question

How to create an observable that produces a single value and never completes

I am aware of

as a way to create a sequence that never completes, but is there an extension/clean process for creating an observable that produces a single value and then never completes? Do i go with
Observable.Concat(Observable.Return(onlyValue), Observable.Never<T>())
? Or is there something built in or more "RXy" than this?

Answer Source

For your specific question, a simple choice is to use ‛Never‛ and ‛StartWith‛:


But for the more general case of "I have an observable sequence that will produce some results and eventually complete and I want to change it so it does not complete" (of which your question is a special case), your Concat idea is the way to do it



Observable.Concat(source, Observable.Never<int>());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download