Closed Deedasmi closed 6 years ago
There is an issue where when_ready
could go negative which would cause problems. Need to re-think this.
An easy fix like expr > 0 ? expr : 0
would fix the above (but induce problem if one periodicity is set to 0
).
I will get onto this project again myself later tonight and look at this.
I added a default trait impl as a convenience function, but left it overrideable in case gather() was a long-running function or required more than just time, such as a file lock or some other condition that ready() could fail. However, I realized that if when_ready passes and ready() fails, when_ready will go negative and overflow into a massively long sleep time.
I still like the idea of supporting a non-time based ready check, but not sure how to do it at the moment. The only easy solution is making ready a &mut self call so it can reset its last_call. I'll think on it some more. If you think of something feel free to commit to my fork!
I think the solution here is:
a) Modify when_read to use:
let periodicty_fixed = if self.periodicity > 0 periodicity else 1
And used periodicty_fixed
instead of self.periodicity
in the fix
b) When checking the "when_ready" results add a map of:
map(x -> if x > 0 x else 0)
Atm I'm on my phone so i can't really make a commit
That seems like a big gotcha for plugin developers though. Biggest problem I'm seeing now is that plugins don't have to be time based. Ready could be a ping, file check, or anything else.
Still, there are options
Leaning towards 2 and scraping this branch.
It's after 3 am and I have class tomorrow, so I should force myself to stop thinking about this lol
Agent now sleeps the required amount of time rather than one second every loop.
In theory, we could get rid of the existing ready function and if when_ready is negative then we run. I don't think it's worth it though.
Last two commits aren't related to this trait change directly, apologies if it causes conflicts with any of your work.