Skip to content

Make syncShutdown unavailable from async #667

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

Merged
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
}
```

You should always shut down `HTTPClient` instances you created using `try httpClient.syncShutdown()`. Please note that you must not call `httpClient.syncShutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
You should always shut down `HTTPClient` instances you created using `try httpClient.shutdown()`. Please note that you must not call `httpClient.shutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.

### async/await examples

Expand Down
2 changes: 1 addition & 1 deletion Sources/AsyncHTTPClient/Docs.docc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
}
```

You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/syncShutdown()``. Please note that you must not call ``HTTPClient/syncShutdown()`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
You should always shut down ``HTTPClient`` instances you created using ``HTTPClient/shutdown()-96ayw()``. Please note that you must not call ``HTTPClient/shutdown()-96ayw()`` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.

### async/await examples

Expand Down
14 changes: 13 additions & 1 deletion Sources/AsyncHTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,29 @@ public class HTTPClient {
""")
case .upAndRunning:
preconditionFailure("""
Client not shut down before the deinit. Please call client.syncShutdown() when no \
Client not shut down before the deinit. Please call client.shutdown() when no \
longer needed. Otherwise memory will leak.
""")
}
}
}

#if swift(>=5.7)
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
///
/// This method blocks the thread indefinitely, prefer using ``shutdown()-96ayw``.
@available(*, noasync, message: "syncShutdown() can block indefinitely, prefer shutdown()", renamed: "shutdown()")
public func syncShutdown() throws {
try self.syncShutdown(requiresCleanClose: false)
}
#else
/// Shuts down the client and `EventLoopGroup` if it was created by the client.
///
/// This method blocks the thread indefinitely, prefer using ``shutdown()-96ayw``.
public func syncShutdown() throws {
try self.syncShutdown(requiresCleanClose: false)
}
#endif

/// Shuts down the client and `EventLoopGroup` if it was created by the client.
///
Expand Down