Created
February 22, 2018 00:08
-
-
Save ole/efa4c2a36ec81eb09cc6d1d65df37beb to your computer and use it in GitHub Desktop.
Paste this into a playground and let it run for 5 seconds. You’ll get a non-nil response *and* error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import PlaygroundSupport | |
let bigFile = URL(string: "https://speed.hetzner.de/1GB.bin")! | |
let task = URLSession.shared.dataTask(with: bigFile) { (data, response, error) in | |
print("data: \(data)") | |
print("response: \(response)") | |
print("error: \(error)") | |
} | |
task.resume() | |
DispatchQueue.main.asyncAfter(deadline: .now() + 5) { | |
print("Cancelling dataTask") | |
task.cancel() | |
} | |
PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment