Skip to content

Commit 419d061

Browse files
authored
Merge pull request #125 from swhitty/run
rename HTTPServer.start() -> run()
2 parents 0b6f770 + ea3cdfc commit 419d061

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

FlyingFox/Sources/HTTPServer.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public final actor HTTPServer {
8989
handlers.appendRoute(route, handler: handler)
9090
}
9191

92-
public func start() async throws {
92+
public func run() async throws {
9393
guard state == nil else {
9494
logger.logCritical("server error: already started")
9595
throw SocketError.unsupportedAddress
@@ -109,6 +109,11 @@ public final actor HTTPServer {
109109
}
110110
}
111111

112+
@available(*, deprecated, renamed: "run")
113+
public func start() async throws {
114+
try await run()
115+
}
116+
112117
func preparePoolAndSocket() async throws -> Socket {
113118
do {
114119
try await config.pool.prepare()

FlyingFox/Tests/HTTPClientTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct HTTPClientTests {
4242
func client_sends_request() async throws {
4343
// given
4444
let server = HTTPServer(address: .loopback(port: 0))
45-
let task = Task { try await server.start() }
45+
let task = Task { try await server.run() }
4646
defer { task.cancel() }
4747
let client = _HTTPClient()
4848

FlyingFox/Tests/HTTPServerTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ actor HTTPServerTests {
4545
self.stopServer = server
4646
Task {
4747
try await HTTPServer.$preferConnectionsDiscarding.withValue(preferConnectionsDiscarding) {
48-
try await server.start()
48+
try await server.run()
4949
}
5050
}
5151
return try await server.waitForListeningPort()
@@ -54,7 +54,7 @@ actor HTTPServerTests {
5454
@discardableResult
5555
func startServer(_ server: HTTPServer) async throws -> Task<Void, any Error> {
5656
self.stopServer = server
57-
let task = Task { try await server.start() }
57+
let task = Task { try await server.run() }
5858
try await server.waitUntilListening()
5959
return task
6060
}
@@ -69,7 +69,7 @@ actor HTTPServerTests {
6969
try await startServer(server)
7070

7171
await #expect(throws: SocketError.unsupportedAddress) {
72-
try await server.start()
72+
try await server.run()
7373
}
7474
}
7575

@@ -93,9 +93,9 @@ actor HTTPServerTests {
9393
defer { try! socket.close() }
9494

9595
await #expect(throws: SocketError.self) {
96-
try await server.start()
96+
try await server.run()
9797
}
98-
// await AsyncAssertThrowsError(try await server.start(), of: SocketError.self) {
98+
// await AsyncAssertThrowsError(try await server.run(), of: SocketError.self) {
9999
// XCTAssertTrue(
100100
// $0.errorDescription?.contains("Address already in use") == true
101101
// )
@@ -430,7 +430,7 @@ actor HTTPServerTests {
430430
return true
431431
}
432432

433-
Task { try await server.start() }
433+
Task { try await server.run() }
434434
self.stopServer = server
435435

436436
#expect(try await waiting.value == true)

FlyingFox/XCTests/HTTPClientTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class HTTPClientTests: XCTestCase {
4141
func testClient() async throws {
4242
// given
4343
let server = HTTPServer(address: .loopback(port: 0))
44-
let task = Task { try await server.start() }
44+
let task = Task { try await server.run() }
4545
defer { task.cancel() }
4646
let client = _HTTPClient()
4747

FlyingFox/XCTests/HTTPServerTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class HTTPServerTests: XCTestCase {
4545
self.stopServer = server
4646
Task {
4747
try await HTTPServer.$preferConnectionsDiscarding.withValue(preferConnectionsDiscarding) {
48-
try await server.start()
48+
try await server.run()
4949
}
5050
}
5151
return try await server.waitForListeningPort()
@@ -54,7 +54,7 @@ final class HTTPServerTests: XCTestCase {
5454
@discardableResult
5555
func startServer(_ server: HTTPServer) async throws -> Task<Void, any Error> {
5656
self.stopServer = server
57-
let task = Task { try await server.start() }
57+
let task = Task { try await server.run() }
5858
try await server.waitUntilListening()
5959
return task
6060
}
@@ -67,7 +67,7 @@ final class HTTPServerTests: XCTestCase {
6767
let server = HTTPServer.make()
6868
try await startServer(server)
6969

70-
await AsyncAssertThrowsError(try await server.start(), of: SocketError.self) {
70+
await AsyncAssertThrowsError(try await server.run(), of: SocketError.self) {
7171
XCTAssertEqual($0, .unsupportedAddress)
7272
}
7373
}
@@ -89,7 +89,7 @@ final class HTTPServerTests: XCTestCase {
8989
let socket = try await server.makeSocketAndListen()
9090
defer { try! socket.close() }
9191

92-
await AsyncAssertThrowsError(try await server.start(), of: SocketError.self) {
92+
await AsyncAssertThrowsError(try await server.run(), of: SocketError.self) {
9393
XCTAssertTrue(
9494
$0.errorDescription?.contains("Address already in use") == true
9595
)
@@ -405,7 +405,7 @@ final class HTTPServerTests: XCTestCase {
405405
return true
406406
}
407407

408-
Task { try await server.start() }
408+
Task { try await server.run() }
409409
self.stopServer = server
410410

411411
await AsyncAssertEqual(try await waiting.value, true)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Start the server by providing a port number:
4444
import FlyingFox
4545

4646
let server = HTTPServer(port: 80)
47-
try await server.start()
47+
try await server.run()
4848
```
4949

5050
The server runs within the the current task. To stop the server, cancel the task terminating all connections immediatley:
5151

5252
```swift
53-
let task = Task { try await server.start() }
53+
let task = Task { try await server.run() }
5454
task.cancel()
5555
```
5656

@@ -72,7 +72,7 @@ Retrieve the current listening address:
7272
await server.listeningAddress
7373
```
7474

75-
> Note: iOS will hangup the listening socket when an app is suspended in the background. Once the app returns to the foreground, `HTTPServer.start()` detects this, throwing `SocketError.disconnected`. The server must then be started once more.
75+
> Note: iOS will hangup the listening socket when an app is suspended in the background. Once the app returns to the foreground, `HTTPServer.run()` detects this, throwing `SocketError.disconnected`. The server must then be started once more.
7676
7777
## Handlers
7878

@@ -360,7 +360,7 @@ struct MyHandler {
360360
}
361361

362362
let server = HTTPServer(port: 80, handler: MyHandler())
363-
try await server.start()
363+
try await server.run()
364364
```
365365

366366
The annotations are implemented via [SE-0389 Attached Macros](https://github.com/apple/swift-evolution/blob/main/proposals/0389-attached-macros.md).

0 commit comments

Comments
 (0)