[
https://issues.apache.org/jira/browse/THRIFT-3773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15660337#comment-15660337
]
ASF GitHub Bot commented on THRIFT-3773:
----------------------------------------
Github user apocolipse commented on the issue:
https://github.com/apache/thrift/pull/1084
Update:
I've modified the generated Async clients to use a new `TAsyncResult<T>`
parameter for callbacks rather than Optional Return/Error tuples. Short
version of why is that those parameters are always mutually exclusive, and
there's no really good way to have a non-optional return or throw pattern for
async.
With the `TAsyncResult<T>`, non-optional return values are encapsulated
within a throwing func in the enum, such that you can handle your do/catch
block in a callback. Consider the following example:
```swift
/// normal: public func hello() throws -> String
do {
let world = try hello()
} catch let e { handle(e) }
/// async: public func hello(completion: @escaping (TAsyncResult<String>)
-> Void)
hello() {
do {
let world = try $0.value()
catch let e { handle(e) }
}
```
> Swift Library
> -------------
>
> Key: THRIFT-3773
> URL: https://issues.apache.org/jira/browse/THRIFT-3773
> Project: Thrift
> Issue Type: New Feature
> Components: Swift - Library
> Reporter: Thomas Bartelmess
> Assignee: Chris Simpson
>
> We already have the option to generate Swift code in the Cocoa compiler,
> however large parts of the (Objective-C) Cocoa Library still depend on Cocoa
> and Objective-C.
> It would be good to have a native Swift library that doesn't depend on the
> Cocoa libraries.
> Design goals:
> - Fully compatible with the code that is currently generated by the Cocoa
> compiler (both Objective-C and Swift).
> - Ability to run on Linux
> - Pure Swift, no Objective-C code.
> - No dependencies on closed source apple libraries
> - Keep the same interface, so that the library is compatible with the code
> the current cocoa compiler generates
> - Better server support that the current Objective-C library.
> - Follow the new Swift packaging format to be compatible with the Swift
> Package manager
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)