summaryrefslogtreecommitdiff
path: root/Control/Concurrent/Go.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Control/Concurrent/Go.hs')
-rw-r--r--Control/Concurrent/Go.hs27
1 files changed, 13 insertions, 14 deletions
diff --git a/Control/Concurrent/Go.hs b/Control/Concurrent/Go.hs
index 69d35b8..92444f4 100644
--- a/Control/Concurrent/Go.hs
+++ b/Control/Concurrent/Go.hs
@@ -30,17 +30,16 @@ import Data.Text (Text)
import qualified System.IO.Unsafe as Unsafe
-- | A standard channel.
-data Channel a
- = Channel
- { _in :: Chan.InChan a,
- _out :: Chan.OutChan a,
- _size :: Int
- }
+data Channel a = Channel
+ { _in :: Chan.InChan a,
+ _out :: Chan.OutChan a,
+ _size :: Int
+ }
instance Aeson.ToJSON (Channel a) where
toJSON c = Aeson.String ("#<channel " <> len c <> ">" :: Text)
where
- len = show . Unsafe.unsafePerformIO . Chan.estimatedLength . _in
+ len = show <. Unsafe.unsafePerformIO <. Chan.estimatedLength <. _in
-- | Starts a background process.
fork :: IO () -> IO Concurrent.ThreadId
@@ -58,26 +57,26 @@ type Mult a = Chan.OutChan a
-- | Duplicates a channel, but then anything written to the source will
-- be available to both. This is like Clojure's `core.async/mult`
mult :: Channel a -> IO (Mult a)
-mult = Chan.dupChan . _in
+mult = Chan.dupChan <. _in
-- | Read a value from a 'Mult'. This is like Clojure's `core.async/tap`.
--
-- You can use this to read from a channel in a background process, e.g.:
--
-- >>> c <- Go.chan
--- >>> Go.fork . forever <| Go.mult c >>= Go.tap >>= print
+-- >>> Go.fork <. forever <| Go.mult c >>= Go.tap >>= print
tap :: Mult a -> IO a
tap = Chan.readChan
-- | Take from a channel. Blocks until a value is received.
read :: Channel a -> IO a
-read = Chan.readChan . _out
+read = Chan.readChan <. _out
-- | Write to a channel. Blocks if the channel is full.
write :: Channel a -> a -> IO Bool
-write = Chan.tryWriteChan . _in
+write = Chan.tryWriteChan <. _in
--- $example
+-- <|example
--
-- A simple example from ghci:
--
@@ -94,9 +93,9 @@ write = Chan.tryWriteChan . _in
-- >>> Go.read c
-- "hi"
-- >>> Go.fork
--- >>> Go.fork $ forever $ Go.mult c >>= Go.tap >>= \t -> print ("one: " <> t)
+-- >>> Go.fork <| forever <| Go.mult c >>= Go.tap >>= \t -> print ("one: " <> t)
-- ThreadId 810
--- >>> Go.fork $ forever $ Go.mult c >>= Go.tap >>= \t -> print ("two: " <> t)
+-- >>> Go.fork <| forever <| Go.mult c >>= Go.tap >>= \t -> print ("two: " <> t)
-- ThreadId 825
-- >>> Go.write c "test"
-- "two: t"eosnte":