Kitura / Kitura-redis

Swift Redis library
Apache License 2.0
95 stars 26 forks source link

Remove callback from Redis.connect() #9

Closed collinhundley closed 8 years ago

collinhundley commented 8 years ago

Description

The Redis.connect() method currently accepts a completion handler with an optional NSError indicating the status of the connection. This pull request removes the completion handler entirely, and instead allows the connect() method to throw. It may now be used as such:

try redis.connect(host: "127.0.0.1", port: 6379)

Motivation and Context

Requiring a completion handler suggests to the user that the connect() method is an asynchronous operation, which it is not. In addition, the use of optional NSErrors is reminiscent of Swift 1.x error handling and has generally been replaced by throw.

Checklist:

collinhundley commented 8 years ago

I just realized I forgot to update the tests to reflect the changes. I'll have to do it tomorrow when I get a chance.

Also, it looks like auth() needs to be updated as well. I'm starting to wonder about this form of error handling throughout the package... I haven't dug too deep into it but I suspect that it's present in other places too. Can somebody explain to me why this form of error handling was chosen? It doesn't seem very Swifty at all.