-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bundles shared calls to IO functions to perform them only once -- -- Bundles shared calls to IO functions to perform them only once @package sharedio @version 0.1.0 -- | Allows bundling or throttling of concurrent IO to -- perform computation only once. -- -- Useful in situations where concurrency can be expensive, such as file -- system scans (where concurrent execution usually returns the same -- result but introduces much disk seeking overhead). module Control.Concurrent.SharedIO -- | A sharing lock on a shared IO computation. -- -- When it is free, a computation can be started on it. -- -- When it is locked, started computation will not execute, but -- instead block until the running computation finished, and receive the -- same result. data SharedIO a -- | Creates a new sharing lock. newSharedIO :: IO (SharedIO a) -- | Request to start a computation on the given sharing lock. -- -- If a computation is already running on that lock, the requested -- computation will not start, but instead block for the running -- computation to finish and return the same result for all threads -- waiting for it. -- -- Ensures that (a)synchronous exceptions in the computation will be -- forwarded to all threads waiting for its result. -- -- Example: -- -- -- -- main = do fileScanSharedIO <- newSharedIO runWebserver -- (handleRequest fileScanSharedIO) -- -- handleRequest :: SharedIO -> IO [FilePath] handleRequest -- fileScanSharedIO = do withSharedIO fileScanSharedIO -- (getDirectoryContents largefolder) withSharedIO :: SharedIO a -> IO a -> IO a