yesod-websockets 0.2.1.1 → 0.2.2
raw patch · 3 files changed
+68/−4 lines, 3 filesdep +enclosed-exceptionsPVP ok
version bump matches the API change (PVP)
Dependencies added: enclosed-exceptions
API changes (from Hackage documentation)
+ Yesod.WebSockets: receiveDataE :: (MonadIO m, WebSocketsData a) => WebSocketsT m (Either SomeException a)
+ Yesod.WebSockets: sendBinaryDataE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendClose :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendCloseE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendPing :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m ()
+ Yesod.WebSockets: sendPingE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
+ Yesod.WebSockets: sendTextDataE :: (MonadIO m, WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())
Files
- ChangeLog.md +3/−1
- Yesod/WebSockets.hs +63/−2
- yesod-websockets.cabal +2/−1
ChangeLog.md view
@@ -1,1 +1,3 @@-No changes logged yet+## 0.2.2++* Add exceptional websocket commands [#772](https://github.com/yesodweb/yesod/pull/772)
Yesod/WebSockets.hs view
@@ -6,8 +6,15 @@ WebSocketsT , webSockets , receiveData+ , receiveDataE+ , sendPing+ , sendPingE+ , sendClose+ , sendCloseE , sendTextData+ , sendTextDataE , sendBinaryData+ , sendBinaryDataE -- * Conduit API , sourceWS , sinkWSText@@ -25,11 +32,14 @@ import Control.Monad.Trans.Control (control) import Control.Monad.Trans.Control (MonadBaseControl (liftBaseWith, restoreM)) import Control.Monad.Trans.Reader (ReaderT (ReaderT, runReaderT))+import Data.Either import qualified Data.Conduit as C import qualified Data.Conduit.List as CL import qualified Network.Wai.Handler.WebSockets as WaiWS import qualified Network.WebSockets as WS import qualified Yesod.Core as Y+import Control.Exception (SomeException)+import Control.Exception.Enclosed (tryAny) -- | A transformer for a WebSockets handler. --@@ -58,23 +68,74 @@ src sink +-- | Wrapper for capturing exceptions+wrapWSE :: (MonadIO m, WS.WebSocketsData a) => (WS.Connection -> a -> IO ())-> a -> WebSocketsT m (Either SomeException ())+wrapWSE ws x = ReaderT $ liftIO . tryAny . flip ws x++wrapWS :: (MonadIO m, WS.WebSocketsData a) => (WS.Connection -> a -> IO ()) -> a -> WebSocketsT m ()+wrapWS ws x = ReaderT $ liftIO . flip ws x+ -- | Receive a piece of data from the client. -- -- Since 0.1.0 receiveData :: (MonadIO m, WS.WebSocketsData a) => WebSocketsT m a receiveData = ReaderT $ liftIO . WS.receiveData +-- | Receive a piece of data from the client.+-- Capture SomeException as the result or operation+-- Since 0.2.2+receiveDataE :: (MonadIO m, WS.WebSocketsData a) => WebSocketsT m (Either SomeException a)+receiveDataE = ReaderT $ liftIO . tryAny . WS.receiveData+ -- | Send a textual message to the client. -- -- Since 0.1.0 sendTextData :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()-sendTextData x = ReaderT $ liftIO . flip WS.sendTextData x+sendTextData = wrapWS WS.sendTextData +-- | Send a textual message to the client.+-- Capture SomeException as the result or operation+-- and can be used like +-- `either handle_exception return =<< sendTextDataE ("Welcome" :: Text)`+-- Since 0.2.2+sendTextDataE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendTextDataE = wrapWSE WS.sendTextData+ -- | Send a binary message to the client. -- -- Since 0.1.0 sendBinaryData :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()-sendBinaryData x = ReaderT $ liftIO . flip WS.sendBinaryData x+sendBinaryData = wrapWS WS.sendBinaryData++-- | Send a binary message to the client.+-- Capture SomeException as the result of operation+-- Since 0.2.2+sendBinaryDataE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendBinaryDataE = wrapWSE WS.sendBinaryData++-- | Send a ping message to the client.+--+-- Since 0.2.2+sendPing :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendPing = wrapWS WS.sendPing++-- | Send a ping message to the client. +-- Capture SomeException as the result of operation+-- Since 0.2.2+sendPingE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendPingE = wrapWSE WS.sendPing++-- | Send a close request to the client. +-- +-- Since 0.2.2+sendClose :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m ()+sendClose = wrapWS WS.sendClose++-- | Send a close request to the client. +-- Capture SomeException as the result of operation+-- Since 0.2.2+sendCloseE :: (MonadIO m, WS.WebSocketsData a) => a -> WebSocketsT m (Either SomeException ())+sendCloseE = wrapWSE WS.sendClose -- | A @Source@ of WebSockets data from the user. --
yesod-websockets.cabal view
@@ -1,5 +1,5 @@ name: yesod-websockets-version: 0.2.1.1+version: 0.2.2 synopsis: WebSockets support for Yesod description: WebSockets support for Yesod homepage: https://github.com/yesodweb/yesod@@ -27,6 +27,7 @@ , monad-control >= 0.3 , conduit >= 1.0.15.1 , async >= 2.0.1.5+ , enclosed-exceptions >= 1.0 source-repository head type: git