PriorityChansConverger-0.1: Read single output from an array of inputs - channels with priorities




A bottleneck for UI from multiple threads. Prevents mixing of output messages. Also makes possible a primitive form of input. By mastering cuisUIInput_E and cuisUIOutput_E it's possible to construct ConcurrentUISupport with different than UI I/O.


ConcurrentUISupport administration

data ConcurrentUISupport Source




cuisInputTChan :: TChan [CUISCommand]

Supported threads are welcome to write their commands here. It is recommended not to use this channel directly - use cuisWrite, cuisReadLn and other mediators instead.

cuisOutputChans :: TVar (Map AskerID (TChan ReadFromConsoleStr))

Map of feedback chans leading to threads, that issue the ReadStr_CUISC commands.

cuisFinish :: ThreadFinisher

Call this, when you want to finish supporter thread.

cuisSupporterStopCheck :: STM Bool

Was cuisFinish called?

cuisFinalizer :: IO ()

What to do, when supporter thread finishes?

cuisUIInput_E :: Either (STM String) (IO String)

How to input, when ReadStr_CUISC command comes?

cuisUIOutput_E :: Either (String -> STM ()) (String -> IO ())

How to output, when PutStrLn_CUISC command comes?

cuisPressAnyKey_uiCmd :: Maybe (IO ())

If set, then call it on each NewPage_CUISC command.

cuisPressAnyKey_linesCountCond :: Maybe Int

For (Just i), if count of printed lines is > i, then automatically issue NewPage_CUISC command and set lines counter to 0.

cuisUIInput :: ConcurrentUISupport -> IO StringSource

Whatever cuisUIInput_E is - Left or Right - flattern it into IO.

cuisUIOutput :: ConcurrentUISupport -> String -> IO ()Source

Whatever cuisUIOutput_E is - Left or Right - flattern it into IO.

cuisInput :: ConcurrentUISupport -> [CUISCommand] -> IO ()Source

Not to be confised with cuisUIInput, which interfaces with user. This input interfaces with threads, that makes use of it.

A wrapper around cuisInputTChan.

Use these functions to deal with ConcurrentUISupport

Few helpers for dealing with exceptions