An open API service indexing awesome lists of open source software.

https://github.com/nh2/haskell-sharedio

Bundles shared calls to IO functions to perform them only once
https://github.com/nh2/haskell-sharedio

Last synced: 3 months ago
JSON representation

Bundles shared calls to IO functions to perform them only once

Awesome Lists containing this project

README

        

haskell-sharedio
================

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).

Example
-------

```haskell
import Control.Concurrent.SharedIO (SharedIO, newSharedIO, withSharedIO)

-- A webserver that lists directory contents, using
-- SharedIO to bundle clients fanatically hitting refresh.

-- Without this, the file seeking would slow the server to a crawl.

main = do
fileScanSharedIO <- newSharedIO
runWebserver (handleRequest fileScanSharedIO)

handleRequest :: SharedIO -> IO [FilePath]
handleRequest fileScanSharedIO = do
withSharedIO fileScanSharedIO (getDirectoryContents "largefolder")
```