From 4ef954f7b3e9b5d99d1030843c2633dbd76f37c0 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 1 Apr 2020 22:51:47 -0700 Subject: Bound ques to about 10 items I also block before taking, instead of doing a mult and tap. This is a simple way to fix the memory issue, and makes them conceptually simpler to work with I think. The channels are still mutli-consumer and multi-producer, which is fine. I'm not sure now I will implement the regular pubsub, but I'm not sure there is a great usecase for that anyway. --- Com/Simatime/Go.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Com') diff --git a/Com/Simatime/Go.hs b/Com/Simatime/Go.hs index e552a90..bd9296a 100644 --- a/Com/Simatime/Go.hs +++ b/Com/Simatime/Go.hs @@ -23,12 +23,14 @@ where import Com.Simatime.Alpha hiding ( read ) import qualified Control.Concurrent as Concurrent -import qualified Control.Concurrent.Chan.Unagi as Chan +import qualified Control.Concurrent.Chan.Unagi.Bounded + as Chan -- | A standard channel. data Channel a = Channel { _in :: Chan.InChan a , _out :: Chan.OutChan a + , _size :: Int } -- | Starts a background process. @@ -36,10 +38,10 @@ fork :: IO () -> IO Concurrent.ThreadId fork = Concurrent.forkIO -- | Make a new channel. -chan :: IO (Channel a) -chan = do - (i, o) <- Chan.newChan - return <| Channel i o +chan :: Int -> IO (Channel a) +chan n = do + (i, o) <- Chan.newChan n + return <| Channel i o n -- | A channel for broadcasting to multiple consumers. See 'mult'. type Mult a = Chan.OutChan a -- cgit v1.2.3