factor/basis/alarms/alarms-docs.factor

79 lines
4.3 KiB
Factor
Raw Normal View History

USING: help.markup help.syntax calendar quotations system ;
2009-11-15 00:28:18 -05:00
IN: alarms
2008-02-21 20:19:21 -05:00
HELP: alarm
2008-05-21 22:31:54 -04:00
{ $class-description "An alarm. Can be passed to " { $link cancel-alarm } "." } ;
2008-02-21 20:19:21 -05:00
HELP: add-alarm
2009-11-30 17:38:57 -05:00
{ $values { "quot" quotation } { "start" duration } { "interval" { $maybe "duration/f" } } { "alarm" alarm } }
2009-11-23 20:49:47 -05:00
{ $description "Creates and registers an alarm to start at " { $snippet "start" } " offset from the current time. If " { $snippet "interval" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency, with scheduling happening before the quotation is called in order to ensure that the next event will happen on time. The quotation will be called from a new thread spawned by the alarm thread. If a repeated alarm's quotation throws an exception, the alarm will not be rescheduled." } ;
2008-02-21 20:19:21 -05:00
HELP: later
2008-09-04 19:14:24 -04:00
{ $values { "quot" quotation } { "duration" duration } { "alarm" alarm } }
2009-11-30 17:38:57 -05:00
{ $description "Creates and registers an alarm which calls the quotation once at " { $snippet "duration" } " offset from now." }
2009-11-15 00:28:18 -05:00
{ $examples
{ $unchecked-example
"USING: alarms io calendar ;"
"""[ "Break's over!" print flush ] 15 minutes later drop"""
""
}
} ;
HELP: later*
{ $values { "quot" quotation } { "duration" duration } { "alarm" alarm } }
{ $description "Creates and registers an alarm which calls the quotation once at " { $snippet "duration" } " offset from now. The alarm is passed to the quotation as an input." }
{ $examples
{ $unchecked-example
"USING: alarms io calendar ;"
"""[ cancel-alarm "Break's over!" print flush ] 15 minutes later* drop"""
2009-11-15 00:28:18 -05:00
""
}
} ;
2008-02-21 20:19:21 -05:00
HELP: cancel-alarm
{ $values { "alarm" alarm } }
2008-02-23 23:29:46 -05:00
{ $description "Cancels an alarm. Does nothing if the alarm is not active." } ;
2008-02-21 20:19:21 -05:00
2008-09-04 19:14:24 -04:00
HELP: every
{ $values
{ "quot" quotation } { "duration" duration }
{ "alarm" alarm } }
2009-11-23 20:49:47 -05:00
{ $description "Creates and registers an alarm which calls the quotation repeatedly, using " { $snippet "dt" } " as the frequency. If the quotation throws an exception that is not caught inside it, the alarm scheduler will cancel the alarm and will not reschedule it again." }
2009-11-15 00:28:18 -05:00
{ $examples
{ $unchecked-example
"USING: alarms io calendar ;"
"""[ "Hi Buddy." print flush ] 10 seconds every drop"""
""
}
} ;
2008-09-04 19:14:24 -04:00
HELP: every*
{ $values
{ "quot" quotation } { "duration" duration }
{ "alarm" alarm } }
{ $description "Creates and registers an alarm which calls the quotation repeatedly, using " { $snippet "dt" } " as the frequency. The alarm is passed as an input to the quotation. If the quotation throws an exception that is not caught inside it, the alarm scheduler will cancel the alarm and will not reschedule it again." }
{ $examples
"Cancelling an alarm from within the alarm:"
{ $unchecked-example
"USING: alarms io calendar inspector ;"
"""[ cancel-alarm "Hi Buddy." print flush ] 10 seconds every* drop"""
""
}
} ;
2008-02-21 20:19:21 -05:00
ARTICLE: "alarms" "Alarms"
"The " { $vocab-link "alarms" } " vocabulary provides a lightweight way to schedule one-time and recurring tasks. Alarms use " { $link nano-count } " as the timing primitive, so they will continue to work across system clock changes. Alarms run in a single green thread per alarm. If a recurring alarm's quotation would be scheduled to run again before the previous quotation has finished processing, the alarm will be run again immediately afterwards. This may result in the alarm falling behind indefinitely, in which case the it will run as often as possible while still allowing other green threads to run. Finally, recurring alarms that execute 'on time' or 'catch up' will always be scheduled for an exact multiple of the interval from the original starting time, which prevents the alarm from drifting over time." $nl
2009-11-15 00:28:18 -05:00
"The alarm class:"
2009-11-30 17:38:57 -05:00
{ $subsections alarm }
2009-11-15 00:28:18 -05:00
"Register a recurring alarm:"
{ $subsections every every* }
2009-11-15 00:28:18 -05:00
"Register a one-time alarm:"
{ $subsections later later* }
2009-11-15 00:28:18 -05:00
"Low-level interface to add alarms:"
{ $subsections add-alarm }
"Cancelling an alarm:"
{ $subsections cancel-alarm }
2008-02-22 17:18:45 -05:00
"Alarms do not persist across image saves. Saving and restoring an image has the effect of calling " { $link cancel-alarm } " on all " { $link alarm } " instances." ;
2008-02-21 20:19:21 -05:00
ABOUT: "alarms"