Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Given the problem as described - which is a little vague as I don't see what the actual id (<code>Guid</code>) is used for, nor the <code>DateTime</code> values - I've got the following query which appears to solve your problem:</p> <pre><code>IObservable&lt;bool&gt; execute = idUpdate .Publish(_idUpdate =&gt; from qsu in queryStateUpdate select qsu.Item1 ? _idUpdate.Select(x =&gt; true) : Observable.Empty&lt;bool&gt;()) .Switch(); </code></pre> <p>I've tested this with the following <code>idUpdate</code> &amp; <code>queryStateUpdate</code> observables.</p> <pre><code>var rnd = new Random(); IObservable&lt;Tuple&lt;Guid, DateTime&gt;&gt; idUpdate = Observable .Generate( 0, n =&gt; n &lt; 10000, n =&gt; n + 1, n =&gt; Tuple.Create(Guid.NewGuid(), DateTime.Now), n =&gt; TimeSpan.FromSeconds(rnd.NextDouble() * 0.1)); IObservable&lt;Tuple&lt;bool, DateTime&gt;&gt; queryStateUpdate = Observable .Generate( 0, n =&gt; n &lt; 100, n =&gt; n + 1, n =&gt; n % 2 == 0, n =&gt; TimeSpan.FromSeconds(rnd.NextDouble() * 2.0)) .StartWith(true) .DistinctUntilChanged() .Select(b =&gt; Tuple.Create(b, DateTime.Now)); </code></pre> <p>If you can provide some clarification around your problem I will probably be able to provide a better answer to suit your needs.</p> <hr> <p>EDIT: Added the "replay(1)" behaviour required when the Id changes when inactive.</p> <p>Please note that I have gotten rid of the need to have tuples with <code>DateTime</code>.</p> <pre><code>IObservable&lt;Guid&gt; idUpdate = ... IObservable&lt;bool&gt; queryStateUpdate = ... var replay = new ReplaySubject&lt;Guid&gt;(1); var disposer = new SerialDisposable(); Func&lt;bool, IObservable&lt;bool&gt;, IObservable&lt;Guid&gt;, IObservable&lt;Guid&gt;&gt; getSwitch = (qsu, qsus, iu) =&gt; { if (qsu) { return replay.Merge(iu); } else { replay.Dispose(); replay = new ReplaySubject&lt;Guid&gt;(1); disposer.Disposable = iu.TakeUntil(qsus).Subscribe(replay); return Observable.Empty&lt;Guid&gt;(); } }; var query = queryStateUpdate .DistinctUntilChanged() .Publish(qsus =&gt; idUpdate .Publish(ius =&gt; qsus .Select(qsu =&gt; getSwitch(qsu, qsus, ius)))) .Switch(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload