diff options
Diffstat (limited to 'swift/src')
-rw-r--r-- | swift/src/Ice/ConnectionI.swift | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/swift/src/Ice/ConnectionI.swift b/swift/src/Ice/ConnectionI.swift index 62ddd779103..470a7ac4b2b 100644 --- a/swift/src/Ice/ConnectionI.swift +++ b/swift/src/Ice/ConnectionI.swift @@ -38,6 +38,37 @@ public extension Connection { } } } + + func setCloseCallback(runOn queue: DispatchQueue = DispatchQueue.global(), callback: CloseCallback?) throws { + let handle = (self as! ConnectionI)._handle + return try autoreleasepool { + guard let cb = callback else { + try handle.setCloseCallback(nil) + return + } + + try handle.setCloseCallback { c in + queue.async { + precondition(c.getCachedSwiftObject(ConnectionI.self) === self) + cb(self) + } + } + } + } + + func setHeartbeatCallback(runOn queue: DispatchQueue = DispatchQueue.global(), callback: HeartbeatCallback?) { + let handle = (self as! ConnectionI)._handle + guard let cb = callback else { + handle.setHeartbeatCallback(nil) + return + } + handle.setHeartbeatCallback { c in + queue.async { + precondition(c.getCachedSwiftObject(ConnectionI.self) === self) + cb(self) + } + } + } } class ConnectionI: LocalObject<ICEConnection>, Connection { @@ -132,36 +163,3 @@ class ConnectionI: LocalObject<ICEConnection>, Connection { } } } - -public extension Connection { - func setCloseCallback(runOn queue: DispatchQueue = DispatchQueue.global(), callback: CloseCallback?) throws { - let handle = (self as! ConnectionI)._handle - return try autoreleasepool { - guard let cb = callback else { - try handle.setCloseCallback(nil) - return - } - - try handle.setCloseCallback { c in - queue.async { - precondition(c.getCachedSwiftObject(ConnectionI.self) === self) - cb(self) - } - } - } - } - - func setHeartbeatCallback(runOn queue: DispatchQueue = DispatchQueue.global(), callback: HeartbeatCallback?) { - let handle = (self as! ConnectionI)._handle - guard let cb = callback else { - handle.setHeartbeatCallback(nil) - return - } - handle.setHeartbeatCallback { c in - queue.async { - precondition(c.getCachedSwiftObject(ConnectionI.self) === self) - cb(self) - } - } - } -} |