Skip to content

Instantly share code, notes, and snippets.

@itsthejb
Created April 17, 2017 15:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsthejb/7d370eefda3a944427f18700340734ed to your computer and use it in GitHub Desktop.
Save itsthejb/7d370eefda3a944427f18700340734ed to your computer and use it in GitHub Desktop.
Simple Async Swift commandline tool outline
#!/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