miniplex-0.3.4: simple 1-to-N interprocess communication

System.Miniplex.Sink

Contents

Description

Asynchronous message broadcasting.

Synopsis

Caveat

This module performs writes on sockets that may be closed at any time, triggering SIGPIPE signals. It is therefore recommended that you call System.Posix.Signals.installHandler System.Posix.Signals.openEndedPipe System.Posix.Signals.Ignore Nothing at the beginning of your program.

data Sink Source

Instances

create :: String -> IO SinkSource

create tag creates a message sink. tag is used to uniquely identify this sink. The set of allowed characters for tag includes letters, digits, _, - and +.

(Implementation detail: This function actually creates a named socket in your ~/.miniplex/.)

write :: Sink -> String -> IO ()Source

write si msg asynchronously writes msg to si, where it will be received by all currently connected readers.

destroy :: Sink -> IO ()Source

Deallocates a sink. The destroyed sink must not be used again.

(Implementation detail: This function closes and removes the socket from the file system. If you forget to call it, you'll leave a stale entry in ~/.miniplex/, which will cause calls to create with the same tag to fail.)

withSink :: String -> (Sink -> IO a) -> IO aSource

Helper function to simplify resource handling. withSink tag body creates a sink, calls body, then destroys the sink, even if body throws an exception.