This commit is contained in:
Quentin Jin 2019-04-03 18:07:25 +08:00
parent 655c716b62
commit 4cd608d123
5 changed files with 31 additions and 29 deletions

View File

@ -1,10 +1,9 @@
included: included:
- Sources - Sources
- Tests
disabled_rules: disabled_rules:
- cyclomatic_complexity - cyclomatic_complexity
- file_length - file_length
- function_body_length - function_body_length
- identifier_name - identifier_name
line_length: 200

View File

@ -64,7 +64,9 @@ extension Plan {
/// > "2001-01-01 00:00:03" /// > "2001-01-01 00:00:03"
/// > "2001-01-01 00:00:06" /// > "2001-01-01 00:00:06"
/// ... /// ...
public static func make<I>(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Interval { public static func make<I>(
_ makeUnderlyingIterator: @escaping () -> I
) -> Plan where I: IteratorProtocol, I.Element == Interval {
return Plan(AnySequence(makeUnderlyingIterator)) return Plan(AnySequence(makeUnderlyingIterator))
} }
@ -109,7 +111,9 @@ extension Plan {
/// You are not supposed to return `Date()` in making interator. /// You are not supposed to return `Date()` in making interator.
/// If you want to execute a task immediately, /// If you want to execute a task immediately,
/// use `Plan.now` then `concat` another plan instead. /// use `Plan.now` then `concat` another plan instead.
public static func make<I>(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Date { public static func make<I>(
_ makeUnderlyingIterator: @escaping () -> I
) -> Plan where I: IteratorProtocol, I.Element == Date {
return Plan.make { () -> AnyIterator<Interval> in return Plan.make { () -> AnyIterator<Interval> in
var iterator = makeUnderlyingIterator() var iterator = makeUnderlyingIterator()
var last: Date! var last: Date!
@ -445,7 +449,7 @@ extension Plan {
date = calendar.date(byAdding: .year, value: 1, to: d) date = calendar.date(byAdding: .year, value: 1, to: d)
} else if Date().is(monthday) { } else if Date().is(monthday) {
date = Date().startOfToday date = Date().startOfToday
} else { } else {
let components = monthday.toDateComponents() let components = monthday.toDateComponents()
date = calendar.nextDate(after: Date(), matching: components, matchingPolicy: .strict) date = calendar.nextDate(after: Date(), matching: components, matchingPolicy: .strict)
} }

View File

@ -51,7 +51,6 @@ open class Task {
/// The mutex used to guard task center operations. /// The mutex used to guard task center operations.
let taskCenterMutex = NSRecursiveLock() let taskCenterMutex = NSRecursiveLock()
/// Initializes a normal task with specified plan and dispatch queue. /// Initializes a normal task with specified plan and dispatch queue.
/// ///
/// - Parameters: /// - Parameters:

View File

@ -221,6 +221,6 @@ final class PlanTests: XCTestCase {
("testPassingEmptyArrays", testPassingEmptyArrays), ("testPassingEmptyArrays", testPassingEmptyArrays),
("testIntervalOffset", testIntervalOffset), ("testIntervalOffset", testIntervalOffset),
("testNegativeIntervalOffset", testNegativeIntervalOffset), ("testNegativeIntervalOffset", testNegativeIntervalOffset),
("testNilIntervalOffset", testNilIntervalOffset), ("testNilIntervalOffset", testNilIntervalOffset)
] ]
} }

View File

@ -107,7 +107,7 @@ final class TaskTests: XCTestCase {
let fn = { let fn = {
let obj = NSObject() let obj = NSObject()
let task = Plan.after(0.1.second).do(queue: .main, onElapse: { let task = Plan.after(0.1.second).do(queue: .main, onElapse: {
XCTFail() XCTFail("should never come here")
}) })
task.host(on: obj) task.host(on: obj)
} }