summaryrefslogtreecommitdiff
path: root/Com
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-04-11 00:56:43 -0700
committerBen Sima <ben@bsima.me>2020-04-11 00:56:43 -0700
commita482720e19b5d98c7c2ad637d9158e75fa0c2bd9 (patch)
tree67df5a4eef5f256c90cb31a7c04334c2928f4a54 /Com
parent20213be7232fd858130f8b4b468be6ac2b532741 (diff)
Add channel size to json serialization
Diffstat (limited to 'Com')
-rw-r--r--Com/Simatime/Go.hs4
1 files changed, 3 insertions, 1 deletions
diff --git a/Com/Simatime/Go.hs b/Com/Simatime/Go.hs
index e622539..f19511f 100644
--- a/Com/Simatime/Go.hs
+++ b/Com/Simatime/Go.hs
@@ -27,6 +27,7 @@ import qualified Control.Concurrent as Concurrent
import qualified Control.Concurrent.Chan.Unagi.Bounded
as Chan
import qualified Data.Aeson as Aeson
+import qualified System.IO.Unsafe as Unsafe
-- | A standard channel.
data Channel a = Channel
@@ -36,7 +37,8 @@ data Channel a = Channel
}
instance Aeson.ToJSON (Channel a) where
- toJSON _ = Aeson.String ("#<channel>" :: Text)
+ toJSON c = Aeson.String ("#<channel " <> len c <> ">" :: Text)
+ where len = show . Unsafe.unsafePerformIO . Chan.estimatedLength . _in
-- | Starts a background process.
fork :: IO () -> IO Concurrent.ThreadId