   public func deferredDataTask(qos: DispatchQoS = .current,
                                with request: URLRequest) -> DeferredURLSessionTask<(Data, HTTPURLResponse)>
   {
-    let tbd = DeferredURLSessionTask<(Data, HTTPURLResponse)>(qos: qos)
-    tbd.urlSessionTask = dataTask(with: request, completionHandler: dataCompletion(tbd))
-    return tbd
+    let tbd = TBD<(Data, HTTPURLResponse)>(qos: qos)
+    let task = dataTask(with: request, completionHandler: dataCompletion(tbd))
+    return DeferredURLSessionTask(source: tbd, task: task)
   }
 
   public func deferredDataTask(qos: DispatchQoS = .current,

  public func deferredDownloadTask(qos: DispatchQoS = .current,
                                   withResumeData data: Data) -> DeferredURLSessionTask<(URL, FileHandle, HTTPURLResponse)>
  {
    let tbd = DeferredDownloadTask<(URL, FileHandle, HTTPURLResponse)>(qos: qos)

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
    tbd.urlSessionTask = downloadTask(withResumeData: data, completionHandler: downloadCompletion(tbd))
#else // swift-corelibs-foundation has the wrong signature for URLSession.downloadTask(withResumeData: …)
    tbd.cancel("URLSession.downloadTask(withResumeData: ) is not implemented in swift-corelibs-foundation")
#endif

    return tbd
  }
}

extension URLSession
{
  private func uploadCompletion(_ tbd: DeferredURLSessionTask<(Data, HTTPURLResponse)>) -> (Data?, URLResponse?, Error?) -> Void
  {
    return {
      (data: Data?, response: URLResponse?, error: Error?) in
      if let error = error
      {
        tbd.determine(error)
        return
      }

      if let d = data, let r = response as? HTTPURLResponse
      {
        tbd.determine( (d,r) )
        return
      }
      // Probably an impossible situation
      tbd.determine(URLSessionError.InvalidState)
    }
  }

  public func deferredUploadTask(qos: DispatchQoS = .current,
                                 with request: URLRequest, fromData bodyData: Data) -> DeferredURLSessionTask<(Data, HTTPURLResponse)>
  {
    let tbd = DeferredURLSessionTask<(Data, HTTPURLResponse)>(qos: qos)
    tbd.urlSessionTask = uploadTask(with: request, from: bodyData, completionHandler: uploadCompletion(tbd))
    return tbd
  }

  public func deferredUploadTask(qos: DispatchQoS = .current,
                                 with request: URLRequest, fromFile fileURL: URL) -> DeferredURLSessionTask<(Data, HTTPURLResponse)>
  {
    let tbd = DeferredURLSessionTask<(Data, HTTPURLResponse)>(qos: qos)
    tbd.urlSessionTask = uploadTask(with: request, fromFile: fileURL, completionHandler: uploadCompletion(tbd))
    return tbd
  }
}

  {
    return deferredDataTask(qos: qos, with: URLRequest(url: url))
  }

  public func deferredUploadTask(qos: DispatchQoS = .current,
                                 with request: URLRequest, fromData bodyData: Data) -> DeferredURLSessionTask<(Data, HTTPURLResponse)>
  {
    let tbd = TBD<(Data, HTTPURLResponse)>(qos: qos)
    let task = uploadTask(with: request, from: bodyData, completionHandler: dataCompletion(tbd))
    return DeferredURLSessionTask(source: tbd, task: task)
  }

  public func deferredUploadTask(qos: DispatchQoS = .current,
                                 with request: URLRequest, fromFile fileURL: URL) -> DeferredURLSessionTask<(Data, HTTPURLResponse)>
  {
    let tbd = TBD<(Data, HTTPURLResponse)>(qos: qos)
    let task = uploadTask(with: request, fromFile: fileURL, completionHandler: dataCompletion(tbd))
    return DeferredURLSessionTask(source: tbd, task: task)
  }
}

private class DeferredDownloadTask<Value>: DeferredURLSessionTask<Value>
