From 1121971d91f9ea162172cd9095643994a8f52b19 Mon Sep 17 00:00:00 2001 From: Nikolai Guyot Date: Wed, 27 Apr 2022 16:24:40 +0200 Subject: [PATCH] Add async/await API --- .../SendGridClient+Concurrency.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Sources/SendGridKit/SendGridClient+Concurrency.swift diff --git a/Sources/SendGridKit/SendGridClient+Concurrency.swift b/Sources/SendGridKit/SendGridClient+Concurrency.swift new file mode 100644 index 0000000..fcd6466 --- /dev/null +++ b/Sources/SendGridKit/SendGridClient+Concurrency.swift @@ -0,0 +1,18 @@ +#if compiler(>=5.5) && canImport(_Concurrency) + +import NIOCore + +@available(macOS 12, iOS 15, watchOS 8, tvOS 15, *) +extension SendGridClient { + public func send(emails: [SendGridEmail]) async throws { + let eventLoop = httpClient.eventLoopGroup.next() + try await send(emails: emails, on: eventLoop).get() + } + + public func send(email: SendGridEmail) async throws { + let eventLoop = httpClient.eventLoopGroup.next() + try await send(email: email, on: eventLoop).get() + } +} + +#endif