Re: [swift-users] Am I missing something on how the Package Manager works?

2017-08-25 Thread Daryle Walker via swift-users

> On Aug 21, 2017, at 4:46 AM, Tatsuyuki Kobayashi  
> wrote:
> 
> I think your process terminates immediately after calling ‘task.resume()’.
> 
> You can find the same issue at 
> https://stackoverflow.com/questions/31944011/how-to-prevent-a-command-line-tool-from-exiting-before-asynchronous-operation-co
>  
> .

Thank you. I ended up using a dispatch-semaphore.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Am I missing something on how the Package Manager works?

2017-08-21 Thread Tatsuyuki Kobayashi via swift-users
I think your process terminates immediately after calling ‘task.resume()’.

You can find the same issue at 
https://stackoverflow.com/questions/31944011/how-to-prevent-a-command-line-tool-from-exiting-before-asynchronous-operation-co
 
.


> 2017/08/21 14:55、Daryle Walker via swift-users のメール:
> 
> I’ve tried to make a command-line program with the Swift Package Manager, and 
> use Foundation for networking (on macOS):
> 
> import Foundation
> import Commander
> import HeliumLogger
> import LoggerAPI
> 
> enum ReturnCode: Int32 {
> case badUrlString = 10, retrievalError
> }
> HeliumLogger.use()
> let main = command { (urlArgument: String) in
> guard let url = URL(string: urlArgument) else {
> Log.error("Argument \"\(urlArgument)\" cannot be converted to a URL.")
> exit(ReturnCode.badUrlString.rawValue)
> }
> let session = URLSession(configuration: .ephemeral)
> let task = session.dataTask(with: url, completionHandler: { (data, 
> response, error) in
> if let error = error {
> Log.error("Retrieval Error: \(error)")
> exit(ReturnCode.retrievalError.rawValue)
> }
> guard let data = data else {
> print("(no data)")
> return
> }
> print(data.base64EncodedString())
> print("Hi there")
> })
> print("Hello world")
> task.resume()
> }
> main.run()
> 
> All I got from “swift build” and the Xcode project it made for me is just the 
> “Hello world” message. The task block was ignored. Did I get calling it wrong?
> 
> — 
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Am I missing something on how the Package Manager works?

2017-08-20 Thread Daryle Walker via swift-users
I’ve tried to make a command-line program with the Swift Package Manager, and 
use Foundation for networking (on macOS):

import Foundation
import Commander
import HeliumLogger
import LoggerAPI

enum ReturnCode: Int32 {
case badUrlString = 10, retrievalError
}
HeliumLogger.use()
let main = command { (urlArgument: String) in
guard let url = URL(string: urlArgument) else {
Log.error("Argument \"\(urlArgument)\" cannot be converted to a URL.")
exit(ReturnCode.badUrlString.rawValue)
}
let session = URLSession(configuration: .ephemeral)
let task = session.dataTask(with: url, completionHandler: { (data, 
response, error) in
if let error = error {
Log.error("Retrieval Error: \(error)")
exit(ReturnCode.retrievalError.rawValue)
}
guard let data = data else {
print("(no data)")
return
}
print(data.base64EncodedString())
print("Hi there")
})
print("Hello world")
task.resume()
}
main.run()

All I got from “swift build” and the Xcode project it made for me is just the 
“Hello world” message. The task block was ignored. Did I get calling it wrong?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users