2

Could you please let me know if there's a way of keeping track of the completion of the current repetition in a repeating sequence? My end goal is to keep track of the current count and rate of completed repetitions which I can do once I have the base. Thank you for your help.

sequence.Repeat().Publish().RefCount()

I would like to capture the completions of "sequence" in the structure above.

Dimitri
  • 23
  • 4

2 Answers2

3

Use Materialize to convert your observable of T into an observable of Notification<T>. This allows you to handle values, completion and error just like ordinary sequence values. You may then just filter out the completions. However, I did not quite understand what you intend to do with them...

var completions = sequence
    .Materialize()
    .Where(notification => notification.Kind == NotificationKind.OnCompleted)
    .Repeat();
Daniel C. Weber
  • 1,011
  • 5
  • 12
  • Thank you. "Sequence" is a resilient quotes stream and I want to keep track of how often it gets disconnected, so I can disable live trading if the rate of disconnects exceeds my threshold. – Dimitri Dec 22 '15 at 17:30
1

Daniel's answer is valid, although it'll hide the stream errors, and I'd not sure it's what you wanted. Alternatively you can simply concat your stream with a single-element-stream before repeat, and that special element will be your completion marker:

var completions = sequence
    .Concat(Observable.Return(42))
    .Repeat().Publish().RefCount();

If you need this element to have some context (your question doesn't say), combien it with Observable.Defer:

var completions = sequence
    .Concat(Observable.Defer(() => Observable.Return(someExpression))
    .Repeat().Publish().RefCount();
Gluck
  • 2,933
  • 16
  • 28
  • Thank you. I was trying to come up with a solution using Concat and the Obervable.Empty but did not think monitoring for a special completion marker. – Dimitri Dec 22 '15 at 17:30