Skip to content

Commit

Permalink
factor some repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
sullyj3 committed Jul 28, 2024
1 parent 12e45fc commit 70fc3fd
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Sand/SandDaemon.lean
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,19 @@ def handleClientCmd (cmd : Command) : CmdHandlerT IO Unit := do
let timers ← state.timers.atomically get

_ ← client.send <| (CmdResponse.list <| Sand.timersForClient timers).serialize

-- TODO factor repetition
| .pause which => do
let result ← (SanddState.pauseTimer which).run {state, client, clientConnectedTime}
match result with
| .ok () => do
_ ← client.send CmdResponse.ok.serialize
| .error .notFound => do
_ ← client.send (CmdResponse.timerNotFound which).serialize
| .error .noop => do
_ ← client.send CmdResponse.noop.serialize
sendResult client which result
| .resume which => do
let result ← state.resumeTimer which clientConnectedTime
sendResult client which result
where
sendResult (client : Socket) (timerId : TimerId) result := do
_ ← client.send <|
match result with
| .ok () => do
_ ← client.send CmdResponse.ok.serialize
| .error .notFound => do
_ ← client.send (CmdResponse.timerNotFound which).serialize
| .error .noop => do
_ ← client.send CmdResponse.noop.serialize
| .ok () => CmdResponse.ok.serialize
| .error .notFound => (CmdResponse.timerNotFound timerId).serialize
| .error .noop => CmdResponse.noop.serialize

def handleClient (client : Socket) : CmdHandlerT IO Unit := do
-- receive and parse message
Expand Down

0 comments on commit 70fc3fd

Please sign in to comment.