packages feed

tdlib 0.1.3 → 0.1.4

raw patch · 3 files changed

+24/−9 lines, 3 files

Files

src/TDLib/Errors.hs view
@@ -7,8 +7,12 @@ import Data.ByteString (ByteString)  data TDLibError-  = ExtraFieldNotInt !Value-  | UnableToParseJSON !ByteString-  | UnableToParseValue !Value-  | UnknownError+  = -- | Recieved an answer but the field "@extra" is not present or is not a integer+    ExtraFieldNotInt !Value+  | -- | The json value cannot be parsed into the expected data type+    UnableToParseJSON !ByteString+  | -- | The bytestring failed to be parsed into a 'Value'+    UnableToParseValue !Value+  | -- | Unknown Error+    UnknownError   deriving (Show, Eq, Exception)
src/TDLib/EventLoop.hs view
@@ -1,8 +1,16 @@ {-# LANGUAGE ExistentialQuantification #-}  -- | A heavyweight TDLib effect intepreter written using event loop-module TDLib.EventLoop where+module TDLib.EventLoop+  ( -- * effect interpreter+    runTDLibEventLoop, +    -- * low level functions+    runCommand,+    loop,+  )+where+ import Control.Concurrent (forkIO, killThread) import Control.Concurrent.Chan.Unagi import Control.Concurrent.STM@@ -83,6 +91,7 @@         Nothing -> lock index lck         _ -> writeTVar ans (M.delete index m) +-- | runs the event loop that receives updates from the client and dispatches them loop :: Client -> Double -> Locks -> Ans -> InChan Update -> IO a loop client timeout lck ans chan = forever $ do   bs <- untilJust $ clientReceive client timeout@@ -98,6 +107,7 @@             Success u -> writeChan chan u         Just i -> atomically $ insertAns i lck ans v +-- | runs a command and waits for its answer runCommand :: (ToJSON a, FromJSON b, FromJSON err) => Client -> Int -> Locks -> Ans -> a -> IO (err ∪ b) runCommand client i lck ans cmd =   case toJSON cmd of@@ -110,6 +120,7 @@         Error _ -> throwIO $ UnableToParseValue v         Success r -> pure r +-- | runs the TDLib effect runTDLibEventLoop :: Members '[Embed IO] r => Double -> InChan Update -> Sem (TDLib ': r) a -> Sem r a runTDLibEventLoop timeout chan m = do   lck <- embed $ newTVarIO mempty
tdlib.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 50a170d1232470269e1a3fb32c1ee38e2e1b8b8be070e885ce94d096ea17abb6+-- hash: e0350137321b986ba9d30546b221776f1fc4d0f228d731766e5bfeb99f0842bb  name:               tdlib-version:            0.1.3+version:            0.1.4 license:            BSD3 license-file:       LICENSE copyright:          (c) 2020 Poscat@@ -15,9 +15,9 @@ author:             Poscat homepage:           https://github.com/poscat0x04/tdlib#readme bug-reports:        https://github.com/poscat0x04/tdlib/issues-synopsis:           Bidings to the tdlib json interface+synopsis:           complete binding to the Telegram Database Library description:        Please see the README on GitHub at <https://github.com/poscat0x04/tdlib#readme>-category:           FFI+category:           Web build-type:         Simple extra-source-files:     README.md