Skip to content

Commit

Permalink
replace namespace SanddState... end with def SanddState.<...>
Browse files Browse the repository at this point in the history
  • Loading branch information
sullyj3 committed Jul 28, 2024
1 parent 92f30b6 commit 8c96ed1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Sand/SandDaemon.lean
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ structure SanddState where
nextTimerId : IO.Mutex Nat
timers : IO.Mutex (HashMap Nat Timer)

namespace SanddState

def initial : IO SanddState := do
def SanddState.initial : IO SanddState := do
return {
nextTimerId := (← IO.Mutex.new 1),
timers := (← IO.Mutex.new ∅)
}

def addTimer (state : SanddState) (due : Nat) : BaseIO TimerId := do
def SanddState.addTimer (state : SanddState) (due : Nat) : BaseIO TimerId := do
let id : TimerId ← state.nextTimerId.atomically (getModify Nat.succ)
let timer : Timer := ⟨id, due⟩
state.timers.atomically <| modify (·.insert id timer)
Expand All @@ -35,13 +33,13 @@ inductive TimerOpError

def TimerOpResult α := Except TimerOpError α

def pauseTimer (state : SanddState) (timerId : TimerId)
def SanddState.pauseTimer (state : SanddState) (timerId : TimerId)
: BaseIO (TimerOpResult Unit) := sorry

def resumeTimer (state : SanddState) (timerId : TimerId)
def SanddState.resumeTimer (state : SanddState) (timerId : TimerId)
: BaseIO (TimerOpResult Unit) := sorry

def removeTimer (state : SanddState) (id : TimerId) : BaseIO (TimerOpResult Unit) := do
def SanddState.removeTimer (state : SanddState) (id : TimerId) : BaseIO (TimerOpResult Unit) := do
let timers ← state.timers.atomically get
-- match timers.findIdx? (λ timer ↦ timer.id == id) with
match timers.find? id with
Expand All @@ -51,12 +49,10 @@ def removeTimer (state : SanddState) (id : TimerId) : BaseIO (TimerOpResult Unit
| none => do
pure <| .error .notFound

def timerExists (state : SanddState) (id : TimerId) : BaseIO Bool := do
def SanddState.timerExists (state : SanddState) (id : TimerId) : BaseIO Bool := do
let timers ← state.timers.atomically get
return timers.find? id |>.isSome

end SanddState

private def xdgDataHome : OptionT BaseIO FilePath :=
xdgDataHomeEnv <|> dataHomeDefault
where
Expand Down

0 comments on commit 8c96ed1

Please sign in to comment.