@@ -23,17 +23,12 @@ module Control.AutoUpdate (
2323 , mkAutoUpdate
2424 ) where
2525
26−import Control.Applicative ((<$>), (<*>))
27−import Control.AutoUpdate.Util (atomicModifyIORef')
28−import Control.Concurrent (ThreadId, forkIO, myThreadId, threadDelay)
29−import Control.Exception (Exception, SomeException
30− ,assert, fromException, handle,throwIO, throwTo, throw, try, catch)
31−import Control.Monad (forever, join, void)
32−import Data.IORef (IORef, newIORef, readIORef, writeIORef)
33−import Data.Typeable (Typeable)
34−import System.IO.Unsafe (unsafePerformIO)
35−import Prelude hiding (catch)
36−import Control.Concurrent.MVar
26+import Control.Concurrent (forkIO, threadDelay)
27+import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar,
28+ takeMVar, tryPutMVar, tryTakeMVar)
29+import Control.Exception (SomeException, catch, throw)
30+import Control.Monad (forever, void)
31+import Data.IORef (newIORef, readIORef, writeIORef)
3732
3833-- | Default value for creating an @UpdateSettings@.
3934--
@@ -64,8 +59,11 @@ data UpdateSettings a = UpdateSettings
6459 --
6560 -- Since 0.1.0
6661 , updateSpawnThreshold :: Int
67− -- ^ How many times the data must be requested before we decide to
68− -- spawn a dedicated thread.
62+ -- ^ NOTE: This value no longer has any effect, since worker threads are
63+ -- dedicated instead of spawned on demand.
64+ --
65+ -- Previously, this determined: How many times the data must be requested
66+ -- before we decide to spawn a dedicated thread.
6967 --
7068 -- Default: 3
7169 --
@@ -78,17 +76,6 @@ data UpdateSettings a = UpdateSettings
7876 -- Since 0.1.0
7977 }
8078
81−data Status a = AutoUpdated
82− !a
83− {-# UNPACK #-} !Int
84− -- Number of times used since last updated.
85− {-# UNPACK #-} !ThreadId
86− -- Worker thread.
87− | ManualUpdates
88− {-# UNPACK #-} !Int
89− -- Number of times used since we started/switched
90− -- off manual updates.
91−
9279-- | Generate an action which will either read from an automatically
9380-- updated value, or run the update action in the current thread.
9481--
@@ -138,5 +125,8 @@ mkAutoUpdate us = do
138125 -- and block for the result from the worker
139126 readMVar lastValue
140127
128+-- | Turn a runtime exception into an impure exception, so that all @IO@
129+-- actions will complete successfully. This simply defers the exception until
130+-- the value is forced.
141131catchSome :: IO a -> IO a
142−catchSome act = catch act $ \e -> return $ throw (e :: SomeException)
132+catchSome act = Control.Exception.catch act $ \e -> return $ throw (e :: SomeException)