Passing arguments with callback

I'm having a bit of trouble with callbacks. i want to pass param1 as a parameter for mycallback. any idea?
note that planner.start() spawns a thread. so it's a bit trickier than it looks

let mut planner = periodic::Planner::new();
let param1 = 5;
planner.add(
    mycallback,
    periodic::After::new(Duration::from_secs(5)),
);
planner.start();
drop(planner)

You can do it with a closure:

planner.add(
    move || mycallback(param1),
    periodic::After::new(Duration::from_secs(5)),
);
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.