Skip to content

Commit

Permalink
Add back setting for stored client
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Feb 1, 2025
1 parent a84b044 commit 33d741b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Sources/SendGrid/Application+SendGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ extension Application {
private let sendableBox: NIOLockedValueBox<SendableBox>

var client: SendGridClient {
self.sendableBox.withLockedValue { box in
box.client
get {
self.sendableBox.withLockedValue { box in
box.client
}
}
set {
self.sendableBox.withLockedValue { box in
box.client = newValue
}
}
}

Expand All @@ -38,7 +45,8 @@ extension Application {
}

public var client: SendGridClient {
self.storage.client
get { self.storage.client }
nonmutating set { self.storage.client = newValue }
}

private var storage: Storage {
Expand Down
7 changes: 7 additions & 0 deletions Tests/SendGridTests/SendGridTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ struct SendGridTests {
do {
try await app.sendgrid.client.send(email: email)
} catch {}

// Change the client and try sending again
app.sendgrid.client = .init(httpClient: app.http.client.shared, apiKey: "new-api-key")

do {
try await app.sendgrid.client.send(email: email)
} catch {}
}
}
}

0 comments on commit 33d741b

Please sign in to comment.