unison-share-api-0.0.0
Safe HaskellNone
LanguageHaskell2010

Unison.Util.Websockets

Synopsis

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 #

data Queues i o Source #

Allows interfacing with a websocket as a pair of bounded queues.

Constructors

Queues 

Fields

Instances

Instances details
Profunctor Queues Source # 
Instance details

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

Instances details
(Show a, Show err) => Show (MsgOrError err a) Source # 
Instance details

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 # 
Instance details

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 # 
Instance details

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

Instance details

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

>>> let errVal = DeserialiseFailure "whoops" :: MsgOrError Text Text
>>> WS.fromLazyByteString (WS.toLazyByteString errVal) == errVal
True
>>> let dataMsg = WS.Binary (WS.toLazyByteString msgVal)
>>> WS.fromDataMessage dataMsg == msgVal
True
Instance details

Defined in Unison.Util.Websockets

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.