diff options
Diffstat (limited to 'src/Network/BitTorrent/Internal/Cache.hs')
-rw-r--r-- | src/Network/BitTorrent/Internal/Cache.hs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Internal/Cache.hs b/src/Network/BitTorrent/Internal/Cache.hs index 1eb2f192..8c74467a 100644 --- a/src/Network/BitTorrent/Internal/Cache.hs +++ b/src/Network/BitTorrent/Internal/Cache.hs | |||
@@ -27,6 +27,7 @@ module Network.BitTorrent.Internal.Cache | |||
27 | 27 | ||
28 | -- * Cached data | 28 | -- * Cached data |
29 | , tryTakeData | 29 | , tryTakeData |
30 | , unsafeTryTakeData | ||
30 | , takeData | 31 | , takeData |
31 | ) where | 32 | ) where |
32 | 33 | ||
@@ -35,6 +36,7 @@ import Data.Monoid | |||
35 | import Data.Default | 36 | import Data.Default |
36 | import Data.Time | 37 | import Data.Time |
37 | import Data.Time.Clock.POSIX | 38 | import Data.Time.Clock.POSIX |
39 | import System.IO.Unsafe | ||
38 | 40 | ||
39 | 41 | ||
40 | data Cached a = Cached | 42 | data Cached a = Cached |
@@ -143,6 +145,9 @@ tryTakeData c = do | |||
143 | alive <- isAlive c | 145 | alive <- isAlive c |
144 | return $ if alive then Just (cachedData c) else Nothing | 146 | return $ if alive then Just (cachedData c) else Nothing |
145 | 147 | ||
148 | unsafeTryTakeData :: Cached a -> Maybe a | ||
149 | unsafeTryTakeData = unsafePerformIO . tryTakeData | ||
150 | |||
146 | invalidateData :: Cached a -> IO a -> IO (Cached a) | 151 | invalidateData :: Cached a -> IO a -> IO (Cached a) |
147 | invalidateData Cached {..} action = do | 152 | invalidateData Cached {..} action = do |
148 | t <- getPOSIXTime | 153 | t <- getPOSIXTime |