The callbacks and posting is handled by declared event objects. The declaration typically looks as follows:
event future { parameter timebase = "seconds"; method event(void *data) { log "info", 1, 1 : "The future is here"; } }
The timebase parameter selects which queue to post on:
The method event() is called when the event is picked from the queue. It takes an optional data argument that is set when the event is posted.
To post an event, you can use the post() method, or the post_on_queue() method on the event object.
method post(when, data) method post_on_queue(queue, when, data) # post an event 100s in the future with the optional argument some_data inline $future.post(100, some_data); # post an event 10s in the future on cpu2 inline $future.post(SIM_get_object("cpu2), 10, NULL);
If you changed your mind and a posted, but not yet handled, event is no longer valid, it can be canceled by calling the remove() method on the event object.
method remove(data) inline $future.remove(some_data);
To find out if there is an event posted but not yet handled, the method posted() can be called, and to get the time remaining until the event will be handled, the method next() will return the time as specified by timebase.
method posted(data) -> (truth) method next(data) -> (when) local bool is_this_event_posted; local double when_is_this_event_posted; inline $future.posted(some_data) -> (is_this_event_posted) inline $future.next(some_data) -> (when_is_this_event_posted)
DML also provides a convenient shortcut with the after statement. An after statement is used to call a DML method some time (always in simulated seconds) in the future. It is not possible to cancel pending calls from after statements.
# call my_method() after 10.5s after (10.5) call my_method();
Refer to the DML Reference Manual for more information.