From c1358342e2ad63df87620126ecebc5b9bdf5adf3 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 20 Apr 2025 13:44:39 +1000 Subject: [PATCH 1/5] Use simplified lvar --- flake.lock | 18 ++++++++++++++++++ flake.nix | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/flake.lock b/flake.lock index 91e3d612..0aaf5001 100644 --- a/flake.lock +++ b/flake.lock @@ -225,6 +225,23 @@ "type": "github" } }, + "lvar": { + "flake": false, + "locked": { + "lastModified": 1745106020, + "narHash": "sha256-z0XLcs4uOolSOe3Flsxz81onlVqp5Ax25Y4+Gw0jcJE=", + "owner": "srid", + "repo": "lvar", + "rev": "317b1ff723ac4ebe8e5565d8001716e396011606", + "type": "github" + }, + "original": { + "owner": "srid", + "ref": "simplify", + "repo": "lvar", + "type": "github" + } + }, "nixos-unified": { "locked": { "lastModified": 1729697921, @@ -291,6 +308,7 @@ "fourmolu-nix": "fourmolu-nix", "git-hooks": "git-hooks", "haskell-flake": "haskell-flake_2", + "lvar": "lvar", "nixpkgs": "nixpkgs_2" } }, diff --git a/flake.nix b/flake.nix index 836d00d4..288b5b5e 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,9 @@ git-hooks.url = "github:cachix/git-hooks.nix"; git-hooks.flake = false; emanote.url = "github:srid/emanote"; + + lvar.url = "github:srid/lvar/simplify"; + lvar.flake = false; }; outputs = inputs@{ self, nixpkgs, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { @@ -22,6 +25,7 @@ # This attr is provided by https://github.com/srid/haskell-flake haskellProjects.default = { autoWire = [ "packages" "checks" ]; + packages.lvar.source = inputs.lvar; }; devShells.default = pkgs.mkShell { From 007df5fa5f4e04011809716f6823b4d23d2bf18a Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 20 Apr 2025 13:54:00 +1000 Subject: [PATCH 2/5] ema: Adapt for new lvar This impacts logging by no longer printing listener ID. --- ema/src/Ema/Server/WebSocket.hs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ema/src/Ema/Server/WebSocket.hs b/ema/src/Ema/Server/WebSocket.hs index 9f5dc306..2368a9eb 100644 --- a/ema/src/Ema/Server/WebSocket.hs +++ b/ema/src/Ema/Server/WebSocket.hs @@ -17,7 +17,6 @@ import Ema.Site (EmaStaticSite) import Network.WebSockets (ConnectionException) import Network.WebSockets qualified as WS import Optics.Core (review) -import Text.Printf (printf) import UnliftIO.Async (race) import UnliftIO.Exception (try) @@ -32,9 +31,8 @@ wsApp :: wsApp logger model emaWsHandler pendingConn = do conn :: WS.Connection <- WS.acceptRequest pendingConn WS.withPingThread conn 30 pass . flip runLoggingT logger $ do - subId <- LVar.addListener model let log lvl (s :: Text) = - logWithoutLoc (toText @String $ printf "ema.ws.%.2d" subId) lvl s + logWithoutLoc "ema.ws" lvl s log LevelInfo "Connected" let wsHandler = unEmaWsHandler emaWsHandler conn sendRouteHtmlToClient path s = do @@ -60,7 +58,7 @@ wsApp logger model emaWsHandler pendingConn = do -- Listen *until* either we get a new value, or the client requests -- to switch to a new route. currentModel <- LVar.get model - race (LVar.listenNext model subId) (wsHandler currentModel) >>= \case + race (LVar.listenNext model) (wsHandler currentModel) >>= \case Left newModel -> do -- The page the user is currently viewing has changed. Send -- the new HTML to them. @@ -83,4 +81,3 @@ wsApp logger model emaWsHandler pendingConn = do log LevelInfo $ "Closing websocket connection (reason: " <> reason <> ")" _ -> log LevelError $ "Websocket error: " <> show connExc - LVar.removeListener model subId From a4ba35dd390cef3e2c4063e608c5be5cca3df28d Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 20 Apr 2025 14:19:31 +1000 Subject: [PATCH 3/5] back to master --- flake.lock | 7 +++---- flake.nix | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index 0aaf5001..4aeb4ed8 100644 --- a/flake.lock +++ b/flake.lock @@ -228,16 +228,15 @@ "lvar": { "flake": false, "locked": { - "lastModified": 1745106020, - "narHash": "sha256-z0XLcs4uOolSOe3Flsxz81onlVqp5Ax25Y4+Gw0jcJE=", + "lastModified": 1745042607, + "narHash": "sha256-ERjOrxCGb9g8fcl1luAu9oxnvdKr8No3sd7D5ACo4As=", "owner": "srid", "repo": "lvar", - "rev": "317b1ff723ac4ebe8e5565d8001716e396011606", + "rev": "1758059f06be2fd0f231e32d9206b8d94dfa3741", "type": "github" }, "original": { "owner": "srid", - "ref": "simplify", "repo": "lvar", "type": "github" } diff --git a/flake.nix b/flake.nix index 288b5b5e..bca66f9c 100644 --- a/flake.nix +++ b/flake.nix @@ -9,7 +9,7 @@ git-hooks.flake = false; emanote.url = "github:srid/emanote"; - lvar.url = "github:srid/lvar/simplify"; + lvar.url = "github:srid/lvar"; lvar.flake = false; }; outputs = inputs@{ self, nixpkgs, flake-parts, ... }: From a70cf9823956fb59a89cc44ecacad22a28b1e7ac Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 20 Apr 2025 14:23:00 +1000 Subject: [PATCH 4/5] require lvar >= 0.2 --- ema-examples/ema-examples.cabal | 2 +- ema/CHANGELOG.md | 1 + ema/ema.cabal | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ema-examples/ema-examples.cabal b/ema-examples/ema-examples.cabal index 88d0c779..b7095331 100644 --- a/ema-examples/ema-examples.cabal +++ b/ema-examples/ema-examples.cabal @@ -87,7 +87,7 @@ library , generic-optics , generics-sop , http-types - , lvar + , lvar >=0.2 , monad-logger , monad-logger-extras , mtl diff --git a/ema/CHANGELOG.md b/ema/CHANGELOG.md index 2a165ed4..76dc5823 100644 --- a/ema/CHANGELOG.md +++ b/ema/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased (0.10.4.0) - Relax `base` constraint forever +- Require `lvar` 0.2 or later ([simplified API](https://github.com/srid/lvar/pull/8)) - API changes - `Ema.CLI`: The `Action` type is no longer a GADT. - `Ema.Server`: This module has be split into several smaller modules diff --git a/ema/ema.cabal b/ema/ema.cabal index 7d1bbb47..8edaeeee 100644 --- a/ema/ema.cabal +++ b/ema/ema.cabal @@ -86,7 +86,7 @@ library , filepath , filepattern , http-types - , lvar + , lvar >=0.2 , monad-logger , monad-logger-extras , mtl From 05e75da1fc1951db7cf9915123694b119a120ffd Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 20 Apr 2025 14:23:32 +1000 Subject: [PATCH 5/5] up --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 4aeb4ed8..f6275a3b 100644 --- a/flake.lock +++ b/flake.lock @@ -228,11 +228,11 @@ "lvar": { "flake": false, "locked": { - "lastModified": 1745042607, - "narHash": "sha256-ERjOrxCGb9g8fcl1luAu9oxnvdKr8No3sd7D5ACo4As=", + "lastModified": 1745122737, + "narHash": "sha256-ZnYXkkPmnNvt4tA45JgSC7dpttmqhUo4AHfEjB1r1gE=", "owner": "srid", "repo": "lvar", - "rev": "1758059f06be2fd0f231e32d9206b8d94dfa3741", + "rev": "047a24c4dcd7f85f9c18058f6be991cea531870e", "type": "github" }, "original": {