From fb5636483871fbafe9b286b377c339c8ddf8b4f8 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 7 Feb 2019 18:42:36 +0100 Subject: initial commit --- src/Control/Concurrent/Extended.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Control/Concurrent/Extended.hs (limited to 'src/Control/Concurrent/Extended.hs') diff --git a/src/Control/Concurrent/Extended.hs b/src/Control/Concurrent/Extended.hs new file mode 100644 index 0000000..933e3a6 --- /dev/null +++ b/src/Control/Concurrent/Extended.hs @@ -0,0 +1,24 @@ +module Control.Concurrent.Extended + ( module Exports + , newChan + , newRef + , newRelay + , newSemaphore + ) where + +import Control.Arrow +import Control.Concurrent as Exports hiding (newChan,readChan,writeChan) +import qualified Control.Concurrent.Chan.Unagi as U +import Data.IORef + +newChan :: IO (a -> IO (), IO a) +newChan = (U.writeChan *** U.readChan) <$> U.newChan + +newRef :: a -> IO (a -> IO (), IO a) +newRef v0 = (atomicWriteIORef &&& readIORef) <$> newIORef v0 + +newRelay :: IO (a -> IO (), IO a) +newRelay = (putMVar &&& takeMVar) <$> newEmptyMVar + +newSemaphore :: IO (IO (), IO ()) +newSemaphore = first ($()) <$> newRelay -- cgit v1.2.3