Clean up alarms
parent
b44b334a02
commit
46ab3bdd18
|
@ -14,8 +14,7 @@ HELP: later
|
|||
|
||||
HELP: cancel-alarm
|
||||
{ $values { "alarm" alarm } }
|
||||
{ $description "Cancels an alarm." }
|
||||
{ $errors "Throws an error if the alarm is not active." } ;
|
||||
{ $description "Cancels an alarm. Does nothing if the alarm is not active." } ;
|
||||
|
||||
ARTICLE: "alarms" "Alarms"
|
||||
"Alarms provide a lightweight way to schedule one-time and recurring tasks without spawning a new thread."
|
||||
|
|
|
@ -56,15 +56,13 @@ SYMBOL: alarm-thread
|
|||
: trigger-alarms ( alarms -- )
|
||||
now (trigger-alarms) ;
|
||||
|
||||
: next-alarm ( alarms -- ms )
|
||||
: next-alarm ( alarms -- timestamp/f )
|
||||
dup heap-empty?
|
||||
[ drop f ]
|
||||
[ heap-peek drop alarm-time now timestamp- 1000 * 0 max ]
|
||||
if ;
|
||||
[ drop f ] [ heap-peek drop alarm-time ] if ;
|
||||
|
||||
: alarm-thread-loop ( -- )
|
||||
alarms get-global
|
||||
dup next-alarm nap drop
|
||||
dup next-alarm nap-until drop
|
||||
dup trigger-alarms
|
||||
alarm-thread-loop ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue