Browse files

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

Signals created during an update phase don't get updated
  • Loading branch information...
2 parents 9f6a867 + a2333a7 commit 5e2c77ffebcf4b8dc4e007dc852787609f333cf6 @cobbpg committed Dec 22, 2011
Showing with 50 additions and 14 deletions.
  1. +16 −4 FRP/Elerea/Clocked.hs
  2. +17 −5 FRP/Elerea/Param.hs
  3. +17 −5 FRP/Elerea/Simple.hs
View
20 FRP/Elerea/Clocked.hs
@@ -208,12 +208,24 @@ start (SG gen) = do
S sample <- gen pool pool
return $ do
res <- sample
- (ptrs,acts) <- unzip.catMaybes <$> (mapM getUpdate =<< readIORef pool)
- writeIORef pool ptrs
- mapM_ fst acts
- mapM_ snd acts
+ cleanup pool
return res
+cleanup :: IORef UpdatePool -> IO ()
+cleanup pool =
+ let
+ loop allPtrs final = do
+ (ptrs,acts) <- unzip.catMaybes <$> (mapM getUpdate =<< readIORef pool)
+ if null acts
+ then do
+ final
+ writeIORef pool allPtrs
+ else do
+ writeIORef pool []
+ mapM_ fst acts
+ loop (ptrs++allPtrs) (final >> mapM_ snd acts)
+ in loop [] (return ())
+
-- | Auxiliary function used by all the primitives that create a
-- mutable variable.
addSignal :: (a -> IO a) -- ^ sampling function
View
22 FRP/Elerea/Param.hs
@@ -145,15 +145,27 @@ start (SG gen) = do
(inp,sink) <- external undefined
S sample <- gen pool inp
return $ \param -> do
- let deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
sink param
res <- sample
- (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
- writeIORef pool ptrs
- mapM_ fst acts
- mapM_ snd acts
+ cleanup pool
return res
+cleanup :: IORef UpdatePool -> IO ()
+cleanup pool =
+ let
+ deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
+ loop allPtrs final = do
+ (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
+ if null acts
+ then do
+ final
+ writeIORef pool allPtrs
+ else do
+ writeIORef pool []
+ mapM_ fst acts
+ loop (ptrs++allPtrs) (final >> mapM_ snd acts)
+ in loop [] (return ())
+
-- | Auxiliary function used by all the primitives that create a
-- mutable variable.
addSignal :: (a -> IO a) -- ^ sampling function
View
22 FRP/Elerea/Simple.hs
@@ -137,14 +137,26 @@ start (SG gen) = do
pool <- newIORef []
S sample <- gen pool
return $ do
- let deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
res <- sample
- (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
- writeIORef pool ptrs
- mapM_ fst acts
- mapM_ snd acts
+ cleanup pool
return res
+cleanup :: IORef UpdatePool -> IO ()
+cleanup pool =
+ let
+ deref ptr = (fmap.fmap) ((,) ptr) (deRefWeak ptr)
+ loop allPtrs final = do
+ (ptrs,acts) <- unzip.catMaybes <$> (mapM deref =<< readIORef pool)
+ if null acts
+ then do
+ final
+ writeIORef pool allPtrs
+ else do
+ writeIORef pool []
+ mapM_ fst acts
+ loop (ptrs++allPtrs) (final >> mapM_ snd acts)
+ in loop [] (return ())
+
-- | Auxiliary function used by all the primitives that create a
-- mutable variable.
addSignal :: (a -> IO a) -- ^ sampling function

0 comments on commit 5e2c77f

Please sign in to comment.