Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Switcher wrong time semantics. #34

Open
voland62 opened this issue Feb 20, 2018 · 1 comment
Open

Switcher wrong time semantics. #34

voland62 opened this issue Feb 20, 2018 · 1 comment

Comments

@voland62
Copy link

voland62 commented Feb 20, 2018

module Test.Issue where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import FRP (FRP)
import FRP.Behavior (Behavior, sample_, switcher)
import FRP.Event (Event, subscribe)
import FRP.Event.Mouse (down)
import FRP.Event.Time (interval)

main   e. Eff (console  CONSOLE, frp  FRP | e) Unit
main = do
  _ ← subscribe badStream $ log <<< show
  pure unit


testStream  Event (Behavior Int) -- stream of behaviors
testStream = pure <$> down

behavior  Behavior Int
behavior = switcher (pure 0) testStream

badStream  Event Int
badStream = sample_ behavior (interval 1000)

Problem: badStream here fires only a second after last mouse down event. So if for ex. testStream would fire more often than once per second, badStream will never fire.

Expected behavior: badStream should tick exactly once per second, regardless of testStream.

@paf31
Copy link
Owner

paf31 commented Feb 20, 2018

The problem seems to be with interval, which sets up a new timer for each subscription. It sounds like you want an "always on" event whose subscription exists outside of the event network. You could try creating such an event using the FFI, to see if that solves the problem. If it does, I will think about if/how this can fit into the semantics.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants