I have a stream with several notification types. One notification type contains information about the current file and is sent continuously. Another type is emitted when the user clicks a button. Both notifications are inside a single stream.
When the user clicks the button I want to do something with current file. I split the source stream in two streams and try combine the "button click" with the latest "current file" notification.
static IObservable<DoSomething> DoSomethingWithFile(IObservable<object> stream)
{
var buttonClick = stream.OfType<ButtonClick>();
var file = stream.OfType<CurrentFile>();
var match = buttonClick
.And(file)
.Then((command, f) => new DoSomething());
return Observable.When(match);
}
This is the desired marble diagram:
File 1-1-1-1-2-2-2-3-3-3-3
Button ----x-----------x----
Desired ----1-----------3----
x x
The code generally works, but only a few times if the current file information changes. Instead of the marble diagram above, I get this one:
File 1-1-1-1-2-2-2-3-3-3-3
Button ----x-----------x----
Actual ----1-----------2----
x x
CombineLatest
will not work in this scenario because on every new file it'll emit a notification to the destination sequence, although the user did not click the button.
I know the question is very general, but of course we're talking about a real project :-)