| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Unison.Util.Websockets
Synopsis
- withQueues :: forall i o m a. (MonadUnliftIO m, WebSocketsData i, WebSocketsData o) => Int -> Int -> Connection -> (Queues i o -> m a) -> m (Either ConnectionException (a, [o]))
- data Queues i o = Queues {}
- data MsgOrError err a
- = Msg !a
- | UserErr !err
- | DeserialiseFailure !Text
- withCodeserverWebsocket :: forall m i o r e. (MonadUnliftIO m, WebSocketsData i, WebSocketsData o) => Int -> CodeserverURI -> (CodeserverId -> IO (Either e Text)) -> String -> (Queues i o -> m r) -> m (Either ConnectionException (r, [o]))
Documentation
withQueues :: forall i o m a. (MonadUnliftIO m, WebSocketsData i, WebSocketsData o) => Int -> Int -> Connection -> (Queues i o -> m a) -> m (Either ConnectionException (a, [o])) Source #
Allows interfacing with a websocket as a pair of bounded queues.
Instances
| Profunctor Queues Source # | |
Defined in Unison.Util.Websockets Methods dimap :: (a -> b) -> (c -> d) -> Queues b c -> Queues a d # lmap :: (a -> b) -> Queues b c -> Queues a c # rmap :: (b -> c) -> Queues a b -> Queues a c # (#.) :: forall a b c q. Coercible c b => q b c -> Queues a b -> Queues a c # (.#) :: forall a b c q. Coercible b a => Queues b c -> q a b -> Queues a c # | |
data MsgOrError err a Source #
Type used for websocket messages that can either be a message or an error.
Constructors
| Msg !a | |
| UserErr !err | |
| DeserialiseFailure !Text |
Instances
| (Show a, Show err) => Show (MsgOrError err a) Source # | |
Defined in Unison.Util.Websockets Methods showsPrec :: Int -> MsgOrError err a -> ShowS # show :: MsgOrError err a -> String # showList :: [MsgOrError err a] -> ShowS # | |
| (Eq a, Eq err) => Eq (MsgOrError err a) Source # | |
Defined in Unison.Util.Websockets Methods (==) :: MsgOrError err a -> MsgOrError err a -> Bool # (/=) :: MsgOrError err a -> MsgOrError err a -> Bool # | |
| (Ord a, Ord err) => Ord (MsgOrError err a) Source # | |
Defined in Unison.Util.Websockets Methods compare :: MsgOrError err a -> MsgOrError err a -> Ordering # (<) :: MsgOrError err a -> MsgOrError err a -> Bool # (<=) :: MsgOrError err a -> MsgOrError err a -> Bool # (>) :: MsgOrError err a -> MsgOrError err a -> Bool # (>=) :: MsgOrError err a -> MsgOrError err a -> Bool # max :: MsgOrError err a -> MsgOrError err a -> MsgOrError err a # min :: MsgOrError err a -> MsgOrError err a -> MsgOrError err a # | |
| (Serialise a, Serialise err) => Serialise (MsgOrError err a) Source # | Roundtrip test: >>> import qualified Codec.Serialise as CBOR >>> CBOR.deserialise (CBOR.serialise (Msg "test" :: MsgOrError Text Text)) == Msg "test" True >>> CBOR.deserialise (CBOR.serialise (Err "error" :: MsgOrError Text Text)) == Err "error" True |
Defined in Unison.Util.Websockets Methods encode :: MsgOrError err a -> Encoding # decode :: Decoder s (MsgOrError err a) # encodeList :: [MsgOrError err a] -> Encoding # decodeList :: Decoder s [MsgOrError err a] # | |
| (Serialise msg, Serialise e) => WebSocketsData (MsgOrError e msg) Source # | Roundtrip test: >>> import qualified Network.WebSockets as WS >>> let msgVal = Msg "test" :: MsgOrError Text Text >>> WS.fromLazyByteString (WS.toLazyByteString msgVal) == msgVal True >>> let errVal = UserErr "whoops" :: MsgOrError Text Text >>> WS.fromLazyByteString (WS.toLazyByteString errVal) == errVal True
|
Defined in Unison.Util.Websockets Methods fromDataMessage :: DataMessage -> MsgOrError e msg # fromLazyByteString :: ByteString -> MsgOrError e msg # toLazyByteString :: MsgOrError e msg -> ByteString # | |
withCodeserverWebsocket :: forall m i o r e. (MonadUnliftIO m, WebSocketsData i, WebSocketsData o) => Int -> CodeserverURI -> (CodeserverId -> IO (Either e Text)) -> String -> (Queues i o -> m r) -> m (Either ConnectionException (r, [o])) Source #
Connect a websocket to the codeserver at the given URI.
The action will be called with a Queues to send and receive messages,
when the action completes, the websocket connection will be closed.