packages feed

stm-queue-extras (empty) → 0.1.0.0

raw patch · 4 files changed

+191/−0 lines, 4 filesdep +basedep +stmsetup-changed

Dependencies added: base, stm

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Jon Sterling++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Control/Concurrent/STM/ETQueue.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE UnicodeSyntax #-}++-- |+-- Module: Control.Concurrent.STM.ETQueue+-- Copyright: Copyright © 2014 AlephCloud Systems, Inc.+-- License: MIT+-- Maintainer: Jon Sterling <jsterling@alephcloud.com>+-- Stability: experimental+--+module Control.Concurrent.STM.ETQueue+( ETQueue+, newETQueue+, newETQueueIO+, readETQueue+, tryReadETQueue+, peekETQueue+, tryPeekETQueue+, writeETQueue+, unGetETQueue+, isEmptyETQueue+, awaitEmpty+) where++import Control.Applicative+import Control.Concurrent.STM+import Control.Monad++-- | A variant of 'TQueue' such that you can await its emptiness.+data ETQueue α+  = ETQueue+  { etqQueue ∷ TQueue α+  , etqVar ∷ TMVar ()+  }++newETQueue ∷ STM (ETQueue α)+newETQueue = do+  etqQueue ← newTQueue+  etqVar ← newTMVar ()+  return ETQueue {..}++newETQueueIO ∷ IO (ETQueue α)+newETQueueIO = do+  etqQueue ← newTQueueIO+  etqVar ← newTMVarIO ()+  return ETQueue {..}++readETQueue+  ∷ ETQueue α+  → STM α+readETQueue ETQueue{..} = do+  a ← readTQueue etqQueue+  isEmpty ← isEmptyTQueue etqQueue+  when isEmpty $+    () <$ tryPutTMVar etqVar ()+  return a++tryReadETQueue+  ∷ ETQueue α+  → STM (Maybe α)+tryReadETQueue q =+  (Just <$> readETQueue q)+    `orElse` return Nothing++peekETQueue+  ∷ ETQueue α+  → STM α+peekETQueue ETQueue{..} =+  peekTQueue etqQueue++tryPeekETQueue+  ∷ ETQueue α+  → STM (Maybe α)+tryPeekETQueue ETQueue{..} =+  tryPeekTQueue etqQueue++writeETQueue+  ∷ ETQueue α+  → α+  → STM ()+writeETQueue ETQueue{..} a = do+  writeTQueue etqQueue a+  () <$ tryTakeTMVar etqVar++unGetETQueue+  ∷ ETQueue α+  → α+  → STM ()+unGetETQueue ETQueue{..} a = do+  unGetTQueue etqQueue a+  () <$ tryTakeTMVar etqVar++isEmptyETQueue+  ∷ ETQueue α+  → STM Bool+isEmptyETQueue ETQueue{..} =+  isEmptyTQueue etqQueue++awaitEmpty+  ∷ ETQueue α+  → STM ()+awaitEmpty ETQueue{..} =+  readTMVar etqVar
+ stm-queue-extras.cabal view
@@ -0,0 +1,66 @@+-- The name of the package.+name:                stm-queue-extras++-- The package version.  See the Haskell package versioning policy (PVP)+-- for standards guiding when and how versions should be incremented.+-- http://www.haskell.org/haskellwiki/Package_versioning_policy+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:             0.1.0.0++-- A short (one-line) description of the package.+synopsis:            Extra queue utilities for STM++-- A longer description of the package.+-- description:++-- The license under which the package is released.+license:             MIT++-- The file containing the license text.+license-file:        LICENSE++-- The package author(s).+author:              Jon Sterling++-- An email address to which users can send suggestions, bug reports, and+-- patches.+maintainer:          jon@jonmsterling.com++-- A copyright notice.+-- copyright:++category:            Concurrency++build-type:          Simple++-- Extra files to be distributed with the package, such as examples or a+-- README.+-- extra-source-files:++-- Constraint on the version of Cabal needed to build this package.+cabal-version:       >=1.10+++library+  -- Modules exported by the library.+  exposed-modules:     Control.Concurrent.STM.ETQueue+++  -- Modules included in this library but not exported.+  -- other-modules:++  -- LANGUAGE extensions used by modules in this package.+  -- other-extensions:++  -- Other library packages from which modules are imported.+  build-depends:       base >=4.7 && <4.8,+                       stm >= 2.4.3++  -- Directories containing source files.+  hs-source-dirs:      src++  -- Base language which the package is written in.+  default-language:    Haskell2010+