Created
April 17, 2017 15:18
-
-
Save itsthejb/7d370eefda3a944427f18700340734ed to your computer and use it in GitHub Desktop.
Simple Async Swift commandline tool outline
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
#!/usr/bin/swift | |
import Foundation | |
var keepAlive = true | |
dump(ProcessInfo().arguments) | |
let runLoop = RunLoop.current | |
let distantFuture = Date.distantFuture | |
//let config = URLSessionConfiguration() | |
//let session = URLSession(configuration: config) | |
let session = URLSession.shared | |
let url = URL(string: "http://news.bbc.co.uk")! | |
session.dataTask(with: url) { (data, response, error) in | |
guard error == nil, let data = data, let response = response else { return } | |
dump(response) | |
dump(data) | |
keepAlive = false | |
}.resume() | |
while keepAlive == true { | |
print("waiting...") | |
runLoop.run(until: Date().addingTimeInterval(0.1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment