polysemy-process-0.11.1.0: Polysemy effects for system processes
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Process.Interpreter.Process

Description

 
Synopsis

Documentation

outputQueue :: forall p chunk err eff r. Members [eff !! err, ProcessOutput p chunk, Queue (Out chunk), Embed IO] r => Bool -> Sem r Bool -> Sem (eff ': r) ByteString -> Sem r () Source #

Call a chunk reading action repeatedly, pass the bytes to ProcessOutput and enqueue its results. As soon as an empty chunk is encountered, the queue is closed if the gating action returns False. The conditional closing is for the purpose of keeping the queue alive until the last producer has written all received chunks – this is important when both stdout and stderr are written to the same queue. When a process writes to stdout and terminates, the stderr reader will immediately receive an empty chunk and close the queue while the stdout reader calls ProcessOutput, after which write will fail and the consumer won't receive the output.

interpretProcess :: forall param proc i o r. Members (ProcessIO i o) r => Member (Scoped proc (SystemProcess !! SystemProcessError) !! SystemProcessScopeError) r => Members [Resource, Race, Async, Embed IO] r => ProcessOptions -> (param -> Sem (Stop ProcessError ': r) proc) -> InterpreterFor (Scoped param (Process i o) !! ProcessError) r Source #

Interpret Process with a system process resource whose file descriptors are connected to three TBMQueues, deferring decoding of stdout and stderr to the interpreters of two ProcessOutput effects. This variant: - Models a daemon process that is not expected to terminate, causing Stop to be sent to the scope callsite instead of individual Process actions. - Is for parameterized scopes, meaning that a value of arbitrary type may be passed to withProcessOneshotParam which is then passed to the supplied function to produce a SysProcConf for the native process.

interpretProcess_ :: forall i o r. Member (Scoped_ (SystemProcess !! SystemProcessError) !! SystemProcessScopeError) r => Members [ProcessOutput 'Stdout o, ProcessOutput 'Stderr o, ProcessInput i, Resource, Race, Async, Embed IO] r => ProcessOptions -> InterpreterFor (Scoped_ (Process i o) !! ProcessError) r Source #

Interpret Process with a system process resource whose file descriptors are connected to three TBMQueues, deferring decoding of stdout and stderr to the interpreters of two ProcessOutput effects. This variant: - Models a daemon process that is not expected to terminate, causing Stop to be sent to the scope callsite instead of individual Process actions. - Defers process config to SystemProcess.

interpretProcessNative :: forall param i o r. Members (ProcessIO i o) r => Members [Resource, Race, Async, Embed IO] r => ProcessOptions -> (param -> Sem r (Either Text SysProcConf)) -> InterpreterFor (Scoped param (Process i o) !! ProcessError) r Source #

Interpret Process as a native SystemProcess. This variant: - Models a daemon process that is not expected to terminate, causing Stop to be sent to the scope callsite instead of individual Process actions. - Is for parameterized scopes, meaning that a value of arbitrary type may be passed to withProcessOneshotParam which is then passed to the supplied function to produce a SysProcConf for the native process.

interpretProcessNative_ :: forall i o r. Members (ProcessIO i o) r => Members [Resource, Race, Async, Embed IO] r => ProcessOptions -> SysProcConf -> InterpreterFor (Scoped_ (Process i o) !! ProcessError) r Source #

Interpret Process as a native SystemProcess. This variant: - Models a daemon process that is not expected to terminate, causing Stop to be sent to the scope callsite instead of individual Process actions. - Defers process config to SystemProcess.

interpretInputOutputProcess :: forall i o r. Member (Process i o) r => InterpretersFor [Input o, Output i] r Source #

Reinterpret Input and Output as Process.

interpretInputHandleBuffered :: Member (Embed IO) r => Handle -> InterpreterFor (Input ByteString !! ProcessError) r Source #

Interpret 'Input ByteString' by polling a Handle and stopping with ProcessError when it fails.

interpretInputHandle :: Member (Embed IO) r => Handle -> InterpreterFor (Input ByteString !! ProcessError) r Source #

Interpret 'Input ByteString' by polling a Handle and stopping with ProcessError when it fails. This variant deactivates buffering for the Handle.

interpretOutputHandleBuffered :: Member (Embed IO) r => Handle -> InterpreterFor (Output ByteString !! ProcessError) r Source #

Interpret 'Output ByteString' by writing to a Handle and stopping with ProcessError when it fails.

interpretOutputHandle :: Member (Embed IO) r => Handle -> InterpreterFor (Output ByteString !! ProcessError) r Source #

Interpret 'Output ByteString' by writing to a Handle and stopping with ProcessError when it fails. This variant deactivates buffering for the Handle.

interpretProcessIO :: forall i o ie oe r. Members [Input ByteString !! ie, Output ByteString !! oe] r => Members [ProcessInput i, ProcessOutput 'Stdout o, Resource, Race, Async, Embed IO] r => ProcessOptions -> InterpreterFor (Process i o !! ProcessError) r Source #

Interpret Process in terms of Input and Output. Since the i and o parameters correspond to the abstraction of stdio fds of an external system process, i is written by Output and o is read from Input. This is useful to abstract the current process's stdio as an external process, with input and output swapped.

interpretProcessHandles :: forall i o r. Members [ProcessInput i, ProcessOutput 'Stdout o, Resource, Race, Async, Embed IO] r => ProcessOptions -> Handle -> Handle -> InterpreterFor (Process i o !! ProcessError) r Source #

Interpret Process in terms of two Handles. This is useful to abstract the current process's stdio as an external process, with input and output swapped. The first Handle argument corresponds to the o parameter, the second one to i, despite the first one usually being the current process's stdin. This is due to Process abstracting an external process to whose stdin would be written, while the current one's is read.

interpretProcessCurrent :: Members [ProcessInput i, ProcessOutput 'Stdout o, Resource, Race, Async, Embed IO] r => ProcessOptions -> InterpreterFor (Process i o !! ProcessError) r Source #

Interpret Process using the current process's stdin and stdout. This mirrors the usual abstraction of an external process, to whose stdin would be written, while the current one's is read.