func main()

in Sources/NIOAsyncAwaitDemo/main.swift [31:66]


func main() async {
    let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
    do {
        let channel = try await makeHTTPChannel(host: "httpbin.org", port: 80, group: group)
        print("OK, connected to \(channel)")

        print("Sending request 1", terminator: "")
        let response1 = try await channel.sendRequest(HTTPRequestHead(version: .http1_1,
                                                                     method: .GET,
                                                                     uri: "/base64/SGVsbG8gV29ybGQsIGZyb20gSFRUUEJpbiEgCg==",
                                                                     headers: ["host": "httpbin.org"]))
        print(", response:", String(buffer: response1.body ?? ByteBuffer()))

        print("Sending request 2", terminator: "")
        let response2 = try await channel.sendRequest(HTTPRequestHead(version: .http1_1,
                                                                     method: .GET,
                                                                     uri: "/get",
                                                                     headers: ["host": "httpbin.org"]))
        print(", response:", String(buffer: response2.body ?? ByteBuffer()))

        try await channel.close()

        print("Shutting down event loop group...")
        try await group.shutdownGracefully()

        print("all, done")
    } catch {
        print("ERROR: \(error)")
        print("Shutting down event loop group (possibly for a second time)...")
        do {
            try await group.shutdownGracefully()
        } catch {
            print("Error shutting down event loop group: \(error)")
        }
    }
}