Skip to content

Commit

Permalink
TaskQueue no longer retains Task during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 16, 2017
1 parent 6aa1d3e commit b0bdafe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ internal final class TaskQueue {
private func _executeTask(_ task: Task) {
guard !task.token.isCancelling else { return } // check if still not cancelled
executingTaskCount += 1
var isFinished = false
task.execute { [weak self] in
self?.queue.async {
guard !task.isFinished else { return } // finish called twice
task.isFinished = true
guard !isFinished else { return } // finish called twice
isFinished = true
self?.executingTaskCount -= 1
self?._executeTasksIfNecessary()
}
Expand All @@ -184,7 +185,6 @@ internal final class TaskQueue {
private final class Task {
let token: CancellationToken
let execute: (_ finish: @escaping () -> Void) -> Void
var isFinished: Bool = false

init(token: CancellationToken, execute: @escaping (_ finish: @escaping () -> Void) -> Void) {
self.token = token
Expand Down

0 comments on commit b0bdafe

Please sign in to comment.