Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Swift connection close callback from global executor #2635

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ csharp/AppX
cpp/AppX
cpp/test/Slice/errorDetection/tmp

Carthage

# iOS builds

**/objs-*/
**/build-*/

.classpath
.project
.settings
Expand Down
9 changes: 4 additions & 5 deletions swift/src/Ice/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ public protocol ConnectionInfo: AnyObject {
var connectionId: String { get set }
}

/// An application can implement this interface to receive notifications when a connection closes.
/// An application can register a callback to be notified when a connection is closed.
///
/// This method is called by the connection when the connection is closed. If the callback needs more information
/// about the closure, it can call Connection.throwException.
///
/// - parameter _: `Connection?` The connection that closed.
public typealias CloseCallback = (Connection?) -> Void
public typealias CloseCallback = (Connection?) async -> Void

/// The user-level interface to a connection.
public protocol Connection: AnyObject, CustomStringConvertible {
Expand Down Expand Up @@ -195,9 +195,8 @@ public protocol Connection: AnyObject, CustomStringConvertible {
_ compress: CompressBatch
) async throws

/// Set a close callback on the connection. The callback is called by the connection when it's closed. The callback
/// is called from the Ice thread pool associated with the connection. If the callback needs more information about
/// the closure, it can call Connection.throwException.
/// Set a close callback on the connection. The callback is called (on the global executor) by the connection when
/// it's closed. If the callback needs more information about the closure, it can call Connection.throwException.
///
/// - parameter _: `CloseCallback?` The close callback object.
func setCloseCallback(_ callback: CloseCallback?) throws
Expand Down
4 changes: 3 additions & 1 deletion swift/src/Ice/ConnectionI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class ConnectionI: LocalObject<ICEConnection>, Connection {

try handle.setCloseCallback { c in
precondition(c.getCachedSwiftObject(ConnectionI.self) === self)
cb(self)
Task {
await cb(self)
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions swift/src/IceImpl/Connection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ - (BOOL)setCloseCallback:(void (^)(ICEConnection*))callback error:(NSError**)err
{
try
{
if (!callback)
{
self.connection->setCloseCallback(nullptr);
}
else
if (callback)
{
self.connection->setCloseCallback(
[callback](auto connection)
Expand All @@ -106,6 +102,10 @@ - (BOOL)setCloseCallback:(void (^)(ICEConnection*))callback error:(NSError**)err
}
});
}
else
{
self.connection->setCloseCallback(nullptr);
}
return YES;
}
catch (...)
Expand Down
Loading