         }
         else if let workItem = self.workItem {
             workItem.wait()
-            waitDispatchGroupIfNeeded()
+            waitDispatchGroup()
 
             guard let result = self.result else {
                 fatalError("Task may be not properly finished. See `Task.finish(with: _)`.")

        }
        else if let workItem = self.workItem {
            workItem.wait()
            waitDispatchGroupIfNeeded()

            guard let result = self.result else {
                fatalError()

    }

}

// MARK: - CancellableTask

fileprivate protocol CancellableTask: AnyObject {
    var cancellation: Cancellation { get }
    func cancel()
}

extension Task: CancellableTask where E == Error {

}

extension Thread {

    fileprivate var cancellableTaskBox: CancellableTaskBox? {
        get {
            return self.threadDictionary["___AAK_TASK"] as? CancellableTaskBox
        }
        set {
            self.threadDictionary["___AAK_TASK"] = newValue
        }
    }

}

fileprivate struct CancellableTaskBox {
    fileprivate weak var value: CancellableTask?

    fileprivate init(_ value: CancellableTask?) {
        self.value = value
    }
}
