Skip to content

Commit

Permalink
Check if watchdogs are closed before operating on them
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl committed Jan 14, 2025
1 parent e43428b commit 14ee61a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/watchdog.toit
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Watchdog extends ServiceResourceProxy:
reacted upon.
*/
start --s/int -> none:
if is-closed: throw "ALREADY_CLOSED"
is-stopped_ = false
client := (client_ as WatchdogServiceClient)
client.start_ handle_ s
Expand All @@ -133,6 +134,7 @@ class Watchdog extends ServiceResourceProxy:
Does nothing if the watchdog is not started.
*/
feed -> none:
if is-closed: throw "ALREADY_CLOSED"
client := (client_ as WatchdogServiceClient)
client.feed_ handle_

Expand All @@ -142,6 +144,7 @@ class Watchdog extends ServiceResourceProxy:
Does nothing if the watchdog is not started.
*/
stop -> none:
if is-closed: throw "ALREADY_CLOSED"
is-stopped_ = true
client := (client_ as WatchdogServiceClient)
client.stop_ handle_
Expand All @@ -152,4 +155,8 @@ class Watchdog extends ServiceResourceProxy:
close -> none:
super
if not is-stopped_:
throw "WATCHDOG_NOT_STOPPED"
// Produce a stack trace to draw attention to the
// fact that a closed, non-stopped watchdog will
// eventually lead to problems, because it cannot
// be fed anymore.
catch --trace: throw "WATCHDOG_NOT_STOPPED"

0 comments on commit 14ee61a

Please sign in to comment.