HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleconcurrent-output-1.10.21Haskell2010

System.Console.Concurrent

Concurrent output handling.

 import Control.Concurrent.Async
 import System.Console.Concurrent

 main = withConcurrentOutput $ do
 	outputConcurrent "washed the car\n"
 		`concurrently`
	outputConcurrent "walked the dog\n"
		`concurrently`
 	createProcessConcurrent (proc "ls" [])
  • 3 types
  • 1 class
  • 13 values

Concurrent output

10 declarations
classclass Outputable v where
#

Values that can be output.

Methods

Instances3Outputable
  • Outputable StringDefined in concurrent-output-1.10.21 · System.Console.Concurrent.Internal
  • Outputable TextDefined in concurrent-output-1.10.21 · System.Console.Concurrent.Internal
  • Outputable TextDefined in concurrent-output-1.10.21 · System.Console.Concurrent.Internal

    Note that using a lazy Text as an Outputable value will buffer it all in memory.

valueoutputConcurrent :: Outputable v => v -> IO ()
#

Displays a value to stdout.

Uses locking to ensure that the whole output occurs atomically even when other threads are concurrently generating output.

No newline is appended to the value, so if you want a newline, be sure to include it yourself.

When something else is writing to the console at the same time, this does not block. It buffers the value, so it will be displayed once the other writer is done.

When outputConcurrent is used within a call to displayConsoleRegions, the output is displayed above the currently open console regions. Only lines ending in a newline are displayed in this case (it uses waitCompleteLines).

Wrapper around createProcess that prevents multiple processes that are running concurrently from writing to stdout/stderr at the same time.

If the process does not output to stdout or stderr, it's run by createProcess entirely as usual. Only processes that can generate output are handled specially:

A process is allowed to write to stdout and stderr in the usual way, assuming it can successfully take the output lock.

When the output lock is held (ie, by another concurrent process, or because outputConcurrent is being called at the same time), the process is instead run with its stdout and stderr redirected to a buffer. The buffered output will be displayed as soon as the output lock becomes free.

Note that the the process is waited for by a background thread, so unlike createProcess, neglecting to call waitForProcess will not result in zombie processess.

valuelockOutput :: (MonadIO m, MonadMask m) => m a -> m a
#

Holds a lock while performing an action. This allows the action to perform its own output to the console, without using functions from this module.

While this is running, other threads that try to lockOutput will block. Any calls to outputConcurrent and createProcessConcurrent will not block, but the output will be buffered and displayed only once the action is done.

Low level access to the output buffer

7 declarations
datadata OutputBuffer
#

Buffered output.

Instances1Eq
  • Eq OutputBufferDefined in concurrent-output-1.10.21 · System.Console.Concurrent.Internal
valuebufferOutputSTM :: Outputable v => StdHandle -> v -> STM ()
#

Adds a value to the output buffer for later display.

Note that buffering large quantities of data this way will keep it resident in memory until it can be displayed. While outputConcurrent uses temp files if the buffer gets too big, this STM function cannot do so.