monadIO-0.10.1.4: Overloading of concurrency variables

Portabilityconcurrency
Stabilityexperimental
MaintainerJohn Launchbury, john@galois.com
Safe HaskellNone

Control.Concurrent.StdInOut

Description

A low-tech concurrent interface to the console. When multiple threads want input, they send messages to the console with the format

  <thread-id>:request

The user supplies input to any requesting thread in a similar way:

  <thread-id>:response

At any time, the user can enter !! to obtain a listing of all the active prompts. Any input not of either of these forms is discarded.

 example :: IO ()
 example = setupStdinout processes
 
 processes :: IO ()
 processes = do
     forkIO $ (prompt "Enter something" >> return ())
     forkIO $ (prompt "Something else" >> return ())
     prompt "quit"      -- When the main thread dies,
     return ()          -- the whole interaction ends

Synopsis

Documentation

setupStdInOut :: IO a -> IO aSource

setupStdInOut establishes the context for prompt, by running a daemon while its argument is executing. The daemon is terminated once the argument to setupStdInOut finishes.

prompt :: HasFork io => String -> io StringSource

prompt is the main user level function of the module. The function prints its argument on stdout, prefixed by its process number. The user similarly selects the recipient by prefixing the process number, e.g. 23:. Active prompts will reprompt when !! is entered.

putStrLine :: MonadIO io => String -> io ()Source

putStrLine sends output to stdout, ensuring that lines are whole and uninterrupted (including the final newline).