Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ema-examples/ema-examples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ library
, generic-optics
, generics-sop
, http-types
, lvar
, lvar >=0.2
, monad-logger
, monad-logger-extras
, mtl
Expand Down
1 change: 1 addition & 0 deletions ema/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ema/ema.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ library
, filepath
, filepattern
, http-types
, lvar
, lvar >=0.2
, monad-logger
, monad-logger-extras
, mtl
Expand Down
7 changes: 2 additions & 5 deletions ema/src/Ema/Server/WebSocket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
lvar.flake = false;
};
outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
Expand All @@ -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 {
Expand Down