Skip to content

Commit c25ee91

Browse files
committed
feature: completion added to start function
1 parent 1e4f51c commit c25ee91

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

SwifterExample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ server["/files/:path"] = directoryBrowser("/")
1515

1616
let semaphore = DispatchSemaphore(value: 0)
1717
do {
18-
try server.start(9080, forceIPv4: true)
18+
try server.start(9080, forceIPv4: true){_ in}
1919
print("Server has started ( port = \(try server.port()) ). Try to connect now...")
2020
semaphore.wait()
2121
} catch {

Xcode/Sources/HttpServerIO.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ open class HttpServerIO {
6868
}
6969

7070
@available(macOS 10.10, *)
71-
public func start(_ port: in_port_t = 8080, forceIPv4: Bool = false, priority: DispatchQoS.QoSClass = DispatchQoS.QoSClass.background) throws {
71+
public func start(_ port: in_port_t = 8080, forceIPv4: Bool = false, priority: DispatchQoS.QoSClass = DispatchQoS.QoSClass.background, completion: (Bool) -> ()) throws {
7272
guard !self.operating else { return }
7373
stop()
7474
self.state = .starting
7575
let address = forceIPv4 ? listenAddressIPv4 : listenAddressIPv6
7676
self.socket = try Socket.tcpSocketForListen(port, forceIPv4, SOMAXCONN, address)
7777
self.state = .running
78+
completion(true)
7879
DispatchQueue.global(qos: priority).async { [weak self] in
7980
guard let strongSelf = self else { return }
8081
guard strongSelf.operating else { return }

0 commit comments

Comments
 (0)