Skip to content

Commit

Permalink
Add example to haddocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbp committed Nov 2, 2015
1 parent d481651 commit 1777c5b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 0 additions & 1 deletion example/hworker-example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ license-file: LICENSE
author: Daniel Patterson
maintainer: [email protected]
build-type: Simple
extra-source-files: README.md CHANGELOG.md
cabal-version: >=1.10


Expand Down
26 changes: 25 additions & 1 deletion src/System/Hworker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

{-|
Expand All @@ -17,6 +16,31 @@ commands like EVAL (ie, that if you do several things within an EVAL,
they will all happen or none will happen). Nothing has been tested
with Redis clusters (and it likely will not work).
An example use is the following (see the repository for a
slightly expanded version; also, the test cases in the repository are
also good examples):
> data PrintJob = Print deriving (Generic, Show)
> data State = State (MVar Int)
> instance ToJSON PrintJob
> instance FromJSON PrintJob
>
> instance Job State PrintJob where
> job (State mvar) Print =
> do v <- takeMVar mvar
> putMVar mvar (v + 1)
> putStrLn $ "A(" ++ show v ++ ")"
> return Success
>
> main = do mvar <- newMVar 0
> hworker <- create "printer" (State mvar)
> forkIO (worker hworker)
> forkIO (monitor hworker)
> forkIO (forever $ queue hworker Print >> threadDelay 1000000)
> forever (threadDelay 1000000)
-}

module System.Hworker
Expand Down

0 comments on commit 1777c5b

Please sign in to comment.