Skip to content

Commit c80ae00

Browse files
authored
Deadline now cancel the job properly (#98)
1 parent 63040cd commit c80ae00

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Change signature of Limit(Int) to Limit(Double)
1313

1414
#### Fix
15+
- Deadline now cancel the job properly (#98)
1516
- Fix calling `done` after termination will remove the lastError (#97)
1617
- Breaking support for Swift 3.2 (#75)
1718

Sources/SwiftQueue/Constrains+Deadline.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ internal final class DeadlineConstraint: JobConstraint {
1515
}
1616

1717
func run(operation: SqOperation) -> Bool {
18-
if let delay = operation.info.deadline {
19-
runInBackgroundAfter(delay.timeIntervalSince(Date()), callback: { [weak operation] in
20-
operation?.run()
21-
})
18+
guard let delay = operation.info.deadline else {
19+
return true
2220
}
21+
22+
runInBackgroundAfter(delay.timeIntervalSince(Date()), callback: { [weak operation] in
23+
guard let ope = operation else { return }
24+
guard !ope.isFinished else { return }
25+
26+
ope.cancel(with: .deadline)
27+
})
2328
return true
2429
}
2530

Sources/SwiftQueue/SqOperation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ internal final class SqOperation: Operation {
6666
super.cancel()
6767
}
6868

69+
func cancel(with: SwiftQueueError) {
70+
lastError = with
71+
onTerminate()
72+
super.cancel()
73+
}
74+
6975
func onTerminate() {
7076
if isExecuting {
7177
isFinished = true

0 commit comments

Comments
 (0)