From a482720e19b5d98c7c2ad637d9158e75fa0c2bd9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 11 Apr 2020 00:56:43 -0700 Subject: Add channel size to json serialization --- Com/Simatime/Go.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Com/Simatime/Go.hs') 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 ("#" :: Text) + toJSON c = Aeson.String ("# len c <> ">" :: Text) + where len = show . Unsafe.unsafePerformIO . Chan.estimatedLength . _in -- | Starts a background process. fork :: IO () -> IO Concurrent.ThreadId -- cgit v1.2.3