I'm trying to make an IObservable<bool>
that returns true
if a UDP Message has been received in the last 5 seconds and if a timeout occurs, a false is returned.
So far I have this:
public IObservable<Boolean> GettingUDPMessages(IPEndPoint localEP)
{
var udp = BaseComms.UDPBaseStringListener(localEP)
.Where(msg => msg.Data.Contains("running"))
.Select(s => true);
return Observable
.Timeout(udp, TimeSpan.FromSeconds(5))
.Catch(Observable.Return(false));
}
The issues with this are:-
- Once a false is returned, the sequence stops
- I only really need
true
orfalse
on state changes.
I could use a Subject<T>
but I need to be careful to dispose of the UDPBaseStringListener
observable when there are no more subscribers.
Update
Every time I get a UDP message I would like it to return a true
. If I haven't received a UDP message in the last 5 seconds, I would like it to return a false
.