Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #3 from takano-akio/new-signal-during-update

Signals created during an update phase don't get updated
  • Loading branch information...
commit 5e2c77ffebcf4b8dc4e007dc852787609f333cf6 2 parents 9f6a867 + a2333a7
Patai Gergely authored
20 FRP/Elerea/Clocked.hs
@@ -208,12 +208,24 @@ start (SG gen) = do
208 208 S sample <- gen pool pool
209 209 return $ do
210 210 res <- sample
211   - (ptrs,acts) <- unzip.catMaybes <$> (mapM getUpdate =<< readIORef pool)
212   - writeIORef pool ptrs
213   - mapM_ fst acts
214   - mapM_ snd acts
  211 + cleanup pool
215 212 return res
216 213
  214 +cleanup :: IORef UpdatePool -> IO ()
  215 +cleanup pool =
  216 + let
  217 + loop allPtrs final = do
  218 + (ptrs,acts) <- unzip.catMaybes <$> (mapM getUpdate =<< readIORef pool)
  219 + if null acts
  220 + then do
  221 + final
  222 + writeIORef pool allPtrs
  223 + else do
  224 + writeIORef pool []
  225 + mapM_ fst acts
  226 + loop (ptrs++allPtrs) (final >> mapM_ snd acts)
  227 + in loop [] (return ())
  228 +
217 229 -- | Auxiliary function used by all the primitives that create a
218 230 -- mutable variable.
219 231 addSignal :: (a -> IO a) -- ^ sampling function
22 FRP/Elerea/Param.hs
@@ -145,15 +145,27 @@ start (SG gen) = do
145 145 (inp,sink) <- external undefined
146 146 S sample <- gen pool inp
147 147 return $ \param -> do
148   - let deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
149 148 sink param
150 149 res <- sample
151   - (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
152   - writeIORef pool ptrs
153   - mapM_ fst acts
154   - mapM_ snd acts
  150 + cleanup pool
155 151 return res
156 152
  153 +cleanup :: IORef UpdatePool -> IO ()
  154 +cleanup pool =
  155 + let
  156 + deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
  157 + loop allPtrs final = do
  158 + (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
  159 + if null acts
  160 + then do
  161 + final
  162 + writeIORef pool allPtrs
  163 + else do
  164 + writeIORef pool []
  165 + mapM_ fst acts
  166 + loop (ptrs++allPtrs) (final >> mapM_ snd acts)
  167 + in loop [] (return ())
  168 +
157 169 -- | Auxiliary function used by all the primitives that create a
158 170 -- mutable variable.
159 171 addSignal :: (a -> IO a) -- ^ sampling function
22 FRP/Elerea/Simple.hs
@@ -137,14 +137,26 @@ start (SG gen) = do
137 137 pool <- newIORef []
138 138 S sample <- gen pool
139 139 return $ do
140   - let deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
141 140 res <- sample
142   - (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
143   - writeIORef pool ptrs
144   - mapM_ fst acts
145   - mapM_ snd acts
  141 + cleanup pool
146 142 return res
147 143
  144 +cleanup :: IORef UpdatePool -> IO ()
  145 +cleanup pool =
  146 + let
  147 + deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
  148 + loop allPtrs final = do
  149 + (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
  150 + if null acts
  151 + then do
  152 + final
  153 + writeIORef pool allPtrs
  154 + else do
  155 + writeIORef pool []
  156 + mapM_ fst acts
  157 + loop (ptrs++allPtrs) (final >> mapM_ snd acts)
  158 + in loop [] (return ())
  159 +
148 160 -- | Auxiliary function used by all the primitives that create a
149 161 -- mutable variable.
150 162 addSignal :: (a -> IO a) -- ^ sampling function

0 comments on commit 5e2c77f

Please sign in to comment.
Something went wrong with that request. Please try again.