Readme for daemons-0.2.1

daemons

Daemons in Haskell made fun and easy

Example

Here's AddOne, a simple daemon that waits for a number and responds with the incremented number.

import Data.Default ( def )
import System.Environment ( getArgs )
import System.Daemon

addOne :: Int -> IO Int
addOne n = return (n + 1)

main :: IO ()
main = do
    ensureDaemonRunning "addOne" def addOne
    [n] <- getArgs
    res <- runClient "localhost" 5000 ((read n) :: Int)
    print (res :: Maybe Int)

Running it, we see:

% addone 22
Daemon started on port 5000
Just 23
% addone 41
Just 42

The two important functions above are ensureDaemonRunning, which checks if a daemon named addOne is already running, and starts it if not, and runClient which connects to the daemon running on localhost:5000, passes it a number, and waits for the response.

What would I use this for?

Tutorials and examples

Installation

This package is on Hackage. To install it, run:

cabal update
cabal install daemons

Modules

See also