> You can abstract this pattern: > > -- runs its argument in an infinite loop, and returns an action that stops > the loop > daemon :: IO () -> IO (IO ()) > daemon action = do > stopvar <- atomically $ newTVar False > let run = do > stop <- atomically $ readTVar stopvar > if stop then return () else (action >> run) > forkIO run > return (atomically $ writeTVar stopvar True) > > TVars are overkill here, actually, an IORef would be just fine, I think. > > Luke
Thanks, Luke! Why do you write "return (atomically $ writeTVar stopvar True)" in the end? Actually, I'm more interested in technical details how to communicate from shell with background process - how to send commands to it. Currently looking into POSIX libraries hope to find answers there... Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a command in it, while one of daemon's thread is locked-while-awaits for anything to come out from the other side of the pipe... Belka -- View this message in context: http://www.nabble.com/how-to-implement-daemon-start-and-stop-directives--tp21598690p21599567.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe