Product Site

5.4.1.4. init

Sets up an Alarm for a future time atime. At this time, the Alarm sends message triggered to the specified notification target.

The target must be an object that implements the AlarmNotification interface. It must inherit from or be a subclass of the AlarmNotification class, or a Message object (as the Message class inherits from AlarmNotification). If target is a Message object, the triggered method of the Message class will respond by simply sending the specified message.

The atime can be a DateTime, a TimeSpan, or a String object. If it is
  • a DateTime object, it specifies the time when the alarm will be triggered. The specified time must be in the future.
  • a TimeSpan, the Alarm will be set to the current time plus the specified time span. The time span must not be a negative interval.
  • a String, you can specify this as a date and time (hh:mm:ss) or as a number of seconds starting at the present time. If you use the date and time format, you can specify a date in the default format (dd Mmm yyyy) after the time with a single blank separating the time and date. Leading and trailing whitespace characters are not allowed in the atime. If you do not specify a date, the Alarm uses the first future occurrence of the specified time.

If specified, attachment can be an arbitrary object that will be attached to the alarm instance, and can later be retrieved in the event handler. See method attachment.

You can use the cancel method to cancel a pending alarm. If cancelled, the alarm sends message cancel to the specified notification target.

The following code sets up an alarm at 5:10 p.m. on December 15, 2017. (Assume today's date/time is prior to December 15, 2017.)
Example 5.218. Alarm class
/* Alarm Examples */

PersonalMessage = .MyMessageClass~new("Call the Bank")
msg = .Message~new(PersonalMessage, "RemindMe")

time = .DateTime~fromIsoDate("2017-12-15T17:10:00.000000")

a = .Alarm~new(time, msg)
exit

::class MyMessageClass public
::method init
  expose inmsg
  use arg inmsg

::method RemindMe
  expose inmsg
  say "It is now" time("C")". Please" inmsg
  /* On the specified data and time, displays the following message: */
  /* "It is now 5:10pm. Please Call the Bank" */

For the following example, the user uses the same code as in the preceding example to define msg, a message object to run at the specified time. The following code sets up an alarm to run the msg message object in 30 seconds from the current time:
Example 5.219. Alarm class
a = .Alarm~new(30, msg)