[Haskell-beginners] Help me with designing my daemon, please.

David McBride dmcbride at neondsl.com
Wed Sep 7 22:37:01 CEST 2011

I'm imagining this:

data TestInfo = {
  testname :: String,
data TestResult = {
  success :: Bool,

data Test = Test (TestInfo -> IO ())
type Tests = [Test]

main = do
  let tests = [whatever] :: Tests
  testchan <- newTChanIO :: IO (TChan TestInfo)
  resultchan <- newTChanIO :: IO (TChan TestResult)
  exceptionwhatever $ queuetest testchan
  forkIO $ testThread (testchan,resultchan) tests
  printTestResults resultChan

queuetest chan = atomically $ writeTchan (TestInfo .....)

testThread (testchan, resultchan) tests = forever $ do
  newtest <- atomically $ readTChan testchan
  results <- mapM tests newTest
  atomically $ writeTChan resultchan results

printTestResults chan = forever $ do
  x <- atomically $ readTChan chan
  print x

Something like that perhaps?

On Wed, Sep 7, 2011 at 3:31 PM, Michael Litchard <michael at schmong.org> wrote:
> This is what I am trying to do.
> I have tests to run and manage. I'm only running one test at a time.
> When my daemon gets a signal, it will either prep a test and run it,
> or queue the request. After it runs the test, I want it to check the
> queue for other tests that may have been requested.
> This is my first expedition into this domain. I'm trying to collect
> MVars and putting tem in a TChan is the way that seemed right, but I'm
> not sure at all. This is my first guess.
> I thought I needed a forked thread for the eventuality that I get a
> signal while my transaction is being executed.
> Have I clarified or further obfuscated?
> On Wed, Sep 7, 2011 at 12:22 PM, David McBride <dmcbride at neondsl.com> wrote:
>> It sounds bizarre.  Why pass around an mvar in tchan, when you could
>> just pass a maybe around and pattern match to see if it is Nothing or
>> not?  Also, why have forkio and tchan at all if they are only going to
>> operate in sequence, one at a time?
>> What exactly are you trying to do?
>> On Wed, Sep 7, 2011 at 3:01 PM, Michael Litchard <michael at schmong.org> wrote:
>>> I have a daemon I need to build, and need to work out some design
>>> details I am having difficulty with. Here's what the design looks like
>>> right now
>>> When the daemon starts it creates an empty MVar and an empty TChan.
>>> Then it listens for a usrSIG1.
>>> when it gets one, it checks to see if the MVar is empty. If it is, it
>>> does some stuff to fill the MVar, which is then used to pass around
>>> state for a list of functions. These functions are always the same.
>>> After evaluating these functions, the TChan is checked. As long as the
>>> TChan has something in it,
>>> it populates an MVar and the same three functions are evaluated in the
>>> same order again.
>>> If the MVar is full, it creates another MVar of the same type and puts
>>> it in the TChan.
>>> Is this a sound design? Does it prompt any questions from you? Here's
>>> my question. If this is basically a sound design, I know I will need
>>> use forkIO. I'm not sure where.
>>> If this is not a sound design, please ask questions or give other
>>> feedback so I can make changes and restore sanity.
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

More information about the Beginners mailing list