Skip to content

Commit 8ce8dd6

Browse files
committed
Call cancel() on deinit in case machine is still running.
1 parent 0aee5b6 commit 8ce8dd6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

SwiftTask/SwiftTask.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ public class Task<Progress, Value, Error>
221221

222222
}
223223

224-
// deinit
225-
// {
224+
deinit
225+
{
226226
// println("deinit: \(self)")
227-
// }
227+
228+
// cancel in case machine is still running
229+
self._cancel(error: nil)
230+
}
228231

229232
public func progress(progressClosure: Progress -> Void) -> Task
230233
{
@@ -426,9 +429,13 @@ public class Task<Progress, Value, Error>
426429

427430
public func cancel(error: Error? = nil) -> Bool
428431
{
429-
return self.machine <-! (.Reject, ErrorInfo(error: error, isCancelled: true))
432+
return self._cancel(error: error)
430433
}
431434

435+
internal func _cancel(error: Error? = nil) -> Bool
436+
{
437+
return self.machine <-! (.Reject, ErrorInfo(error: error, isCancelled: true))
438+
}
432439
}
433440

434441
extension Task

0 commit comments

Comments
 (0)