ixa/macros/schedule_relative.rs
1/// Schedules an action after a delay relative to the context's current time.
2///
3/// The scheduled action is called with the executing `context: &mut Context` as
4/// its first argument, followed by each remaining macro argument in the same
5/// order.
6///
7/// For example:
8///
9/// ```ignore
10/// schedule_relative!(context, my_delay, my_handler, arg1, arg2, arg3);
11/// ```
12///
13/// expands to code like:
14///
15/// ```ignore
16/// {
17/// let time = context.get_current_time() + my_delay;
18/// context.add_plan(time, move |context| {
19/// my_handler(context, arg1, arg2, arg3)
20/// })
21/// }
22/// ```
23#[macro_export]
24macro_rules! schedule_relative {
25 ($context:expr, $delay:expr, $action:expr $(, $arg:expr)* $(,)?) => {{
26 let context = ($context);
27 let time = context.get_current_time() + $delay;
28 context.add_plan(time, move |context| {
29 ($action)(context $(, $arg)*)
30 })
31 }};
32}