A more elegant way to start a multithread alarm in Rebol VID ? (What's the equivalent of load event?
Posted
by Rebol Tutorial
on Stack Overflow
See other posts from Stack Overflow
or by Rebol Tutorial
Published on 2010-05-24T07:36:26Z
Indexed on
2010/05/24
7:41 UTC
Read the original article
Hit count: 349
rebol
I want to trigger an alarm when the GUI starts. I can't see what's the equivalent of load event of other language in Rebol VID, so I put it in the periodic handler which is quite circumvoluted. So how to do this more cleanly ?
alarm-data: none
set-alarm: func [
"Set alarm for future time."
seconds "Seconds from now to ring alarm."
message [string! unset!] "Message to print on alarm."
] [
alarm-data: reduce [now/time + seconds message]
]
ring: func [
"Action for when alarm comes due."
message [string! unset!]
] [
set-face monitor either message [message]["RIIIING!"]
; Your sound playing can also go here (my computer doesn't have speakers).
]
periodic: func [
"Called every second, checks alarms."
fact action event
] [
either alarm-data [
; Update alarm countdown.
set-face monitor rejoin [
"Alarm will ring in "
to integer! alarm-data/1 - now/time
" seconds."
]
; Check alarm.
if now/time > alarm-data/1 [
ring alarm-data/2
;alarm-data: none ; Reset once fired.
]
][
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
]
]
alarm: func[seconds message [string! unset!]][
system/words/seconds: seconds
if value? 'message [
system/words/message: message
]
view layout [
monitor: text 256 ""
rate 1 feel [engage: :periodic]
button 256 "re/start countdown" [
either value? 'message [
set-alarm seconds message
][
set-alarm seconds "Alarm triggered!"
]
set-face monitor "Alarm set."
]
]
]
© Stack Overflow or respective owner