aboutsummaryrefslogtreecommitdiffstats
path: root/src/Control/Concurrent/Extended.hs
blob: 933e3a61a006b7068d59348069518dd8b936b0f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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