diff options
author | Joe George <joe@zeroc.com> | 2019-03-18 12:31:28 -0400 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2019-03-18 12:31:28 -0400 |
commit | 0eb46a6dfb1d620ce910848f5ff60ecb00e6824c (patch) | |
tree | 04ad77176ec20f6a5e90fafe2c9da55d513b3169 /swift/src | |
parent | Proxy unmarshaling fixes (diff) | |
download | ice-0eb46a6dfb1d620ce910848f5ff60ecb00e6824c.tar.bz2 ice-0eb46a6dfb1d620ce910848f5ff60ecb00e6824c.tar.xz ice-0eb46a6dfb1d620ce910848f5ff60ecb00e6824c.zip |
Async fixes
Diffstat (limited to 'swift/src')
-rw-r--r-- | swift/src/Ice/Proxy.swift | 103 |
1 files changed, 49 insertions, 54 deletions
diff --git a/swift/src/Ice/Proxy.swift b/swift/src/Ice/Proxy.swift index 26072bf1547..9f8091adb28 100644 --- a/swift/src/Ice/Proxy.swift +++ b/swift/src/Ice/Proxy.swift @@ -610,77 +610,72 @@ open class _ObjectPrxI: ObjectPrx { exceptions: [UserException.Type] = [], context: Context? = nil, sent sendCallback: ((Bool) -> Void)? = nil, + sentOn: DispatchQueue? = PromiseKit.conf.Q.map, unmarshalResult: @escaping ((InputStream) throws -> T)) -> Promise<T> { if twowayOnly, !self.isTwoway { return Promise(error: TwowayOnlyException(operation: op)) } - // - // Create a pending promise. This way we can call into ObjC++ using the current thread - // - let (promise, resolver) = Promise<T>.pending() - - // - // Response callback - // - func response(ok: Bool, inputStream istrHandle: ICEInputStream) { - do { - let istr = InputStream(communicator: self.communicator, inputStream: istrHandle) - if self.isTwoway { - guard ok else { - throw try _ObjectPrxI.unmarshalUserException(stream: istr, exceptions: exceptions) - } - if !hasOutParams { - try istr.skipEmptyEncapsulation() + return Promise<T> { seal in + // + // Response callback + // + func response(ok: Bool, inputStream istrHandle: ICEInputStream) { + do { + let istr = InputStream(communicator: self.communicator, inputStream: istrHandle) + if self.isTwoway { + guard ok else { + throw try _ObjectPrxI.unmarshalUserException(stream: istr, exceptions: exceptions) + } + if !hasOutParams { + try istr.skipEmptyEncapsulation() + } } + try seal.fulfill(unmarshalResult(istr)) + } catch let error { + seal.reject(error) } - try resolver.fulfill(unmarshalResult(istr)) - } catch let error { - resolver.reject(error) } - } - // - // Exception callback - // - func exception(error: Error) { - resolver.reject(error) - } + // + // Exception callback + // + func exception(error: Error) { + seal.reject(error) + } - // - // Sent callback (optional) - // - var sent: ((Bool) -> Void)? - - if let s = sendCallback { - sent = { (sentSynchronously: Bool) -> Void in - // - // Use PromiseKit's return queue if not nil, otherwise use call with the current thread - // - if let queue = PromiseKit.conf.Q.return { - queue.async { - s(sentSynchronously) + // + // Sent callback (optional) + // + var sent: ((Bool) -> Void)? + + if let s = sendCallback { + sent = { (sentSynchronously: Bool) -> Void in + // + // Use PromiseKit's map queue if not nil, otherwise use call with the current thread + // + if let queue = PromiseKit.conf.Q.map { + queue.async { + s(sentSynchronously) + } } + s(sentSynchronously) } - s(sentSynchronously) } - } - do { - try autoreleasepool { - try handle.iceInvokeAsync(op, mode: Int(mode.rawValue), - inParams: inParams?.getBytes(), - inSize: inParams?.getCount() ?? 0, - context: context, - response: response, exception: exception, sent: sent) + do { + try autoreleasepool { + try handle.iceInvokeAsync(op, mode: Int(mode.rawValue), + inParams: inParams?.getBytes(), + inSize: inParams?.getCount() ?? 0, + context: context, + response: response, exception: exception, sent: sent) + } + } catch let error { + seal.reject(error) } - } catch let error { - resolver.reject(error) } - - return promise - } static func unmarshalUserException(stream istr: InputStream, |