New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for interval offsets #28
Conversation
Adds the ability to offset a Task by a specific interval from its Plan, such so that the Task calculates its next run based on adding said interval to the Plan's next interval.
Codecov Report
@@ Coverage Diff @@
## master #28 +/- ##
==========================================
+ Coverage 90.86% 90.96% +0.09%
==========================================
Files 16 16
Lines 832 841 +9
==========================================
+ Hits 756 765 +9
Misses 76 76 |
Although negative interval offsets are allowed, they shouldn't make the Plan have a negative interval.
This was preventing functions from being passed to the offsetBy: parameter without issue, so it was removed.
Hi @Wilsonator5000 , Sorry for my late reply! I like the extension Plan {
// just a draft
func offset(_ body: @autoclosure @escaping () -> Interval?) -> Plan {
return Plan.make { () -> AnyIterator<Interval> in
let it = self.makeIterator()
return AnyIterator {
if let next = it.next() {
return next + (body() ?? 0.second)
}
return nil
}
}
}
} And since it's actually a transformation, a |
Hi @jianstm, your method makes sense too! A map wouldn't work because it would convert the iterator to an array, and we want the the |
The @autoclosure was creating issues when passing closures as value types, so it was removed an an overload was added instead.
Adds the ability to offset a Task by a specific interval from its Plan, such so that the Task calculates its next run based on adding said interval to the Plan's next interval. This can be useful if one has a preexisting Plan and needs to uniformly adjust the times at which its Task runs (eg. timezone differences, etc.).
Usage examples: