Note that there are some explanatory texts on larger screens.

plurals
  1. POReactive-banana: up-to-date values from fromPoll
    primarykey
    data
    text
    <p>I'm writing a music player in Haskell with reactive-banana. One problem I have is fetching up-to-date values with fromPoll. I want to enable the user to optionally select a part of the track <strong>while playing</strong>. My code looks something like this:</p> <pre><code>makePlayNetworkDescr :: Player a =&gt; AddHandler Command -&gt; a -&gt; NetworkDescription t () makePlayNetworkDescr addCmdEvent player = do bPosition &lt;- fromPoll (getPosition player) eCmds &lt;- fromAddHandler addCmdEvent let eSetStart = filterE (isJust) $ bPosition &lt;@ filterE (==SetStart) eCmds eSetEnd = filterE (isJust) $ bPosition &lt;@ filterE (==SetEnd) eCmds eClearRange = filterE (==ClearRange) eCmds bStart = accumB Nothing ((const &lt;$&gt; eSetStart) `union` (const Nothing &lt;$ eClearRange)) bEnd = accumB Nothing ((const &lt;$&gt; eSetEnd) `union` (const Nothing &lt;$ eClearRange)) </code></pre> <p>Above, <em>getPosition</em> is a partial function, returning <em>Nothing</em> before the playback actually starts. The problem is that once the <em>addCmdEvent</em> fires for the first time, <em>bPosition</em> will still hold a <em>Nothing</em> value. <em>eSetStart/End</em> calculate their values based on this. Only then does <em>bPosition</em> get updated, and this is the value which will be used next time that <em>addCmdEvent</em> fires. And so on, the value will always be "off by one", so to speak. </p> <p>There is a related <a href="https://stackoverflow.com/questions/8618069/reactive-banana-firing-event-that-contain-the-most-up-to-date-value-of-a-behavi">SO question</a>, but in that case there exists a "trigger" event which can be used to calculate the new value of the behavior. Is anything like that possible with fromPoll?</p>
    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.
 

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