I'd like to create an IObservable-stream based on Sets/Resets of a ManualResetEvent, e.g. in principle something like
IObservable<bool> ToObservable(ManualResetEvent ev)
{
var s = new Subject<bool>();
ev.OnSet += s.OnNext(true);
ev.OnReset += s.OnNext(false);
return s;
}
Only that ManualResetEvent doesn't expose such events of course. So is there any way to observe when this gets stopped/reset?
For the record, if the differentiation between set/unset into true/false isn't possible, a more simple IObservable<Unit> pushing a value whenever the state of ManualResetEvent changes would be okay as well.
Is there any way of doing this?
I've found a post explaining how to convert a ManualResetEvent (or rather, a WaitHandle in general) into a task ( Wrapping ManualResetEvent as awaitable task ), which seems to complete whenever the next time is that the ManualResetEvent changes (from set to unset, or other way around). But I haven't really found any way how I could chain this up into a sequence (e.g. after the task completes, I'd need to create another one for the next event, etc., and somehow create an observable out of this "recursive" sequence)
Thanks!