I want to use Rx Buffer functionality:
var source = new Subject<Price>();
var buffer = source
.Buffer(TimeSpan.FromSeconds(30), 5)
.Where(p => p.Any());
that means emit (publishing to subscribers) happens when buffer reaches size of 5 or 30 seconds have gone since the last emit.
But I need to be able to emit on demand - for example when I receive high priority sequence item. Then I want to add it to observable (source.OnNext()
) and somehow force it to emit (that means returning all elements in the buffer and clearing it).
I know that I can add following code:
var flusher = new Subject<Price>();
var closing = flusher.Select(x => new List<Price> {x});
var query = buffer.Merge(closing).Subscribe(something);
and invoke flusher.OnNext(highPriorityItem) and I will have it emitted.
But in this case, I have two independent sequences with two different emits. I need one emit when buffer is full or specific item appears in sequence.
Force flush count-type Observable.Buffer c# and Force flush to Observable.Buffer c# don't seem to be suitable for me