Skip to content

Commit

Permalink
fix(postgrest): race condition when executing request (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Apr 6, 2024
1 parent 97d1900 commit 8063610
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/PostgREST/PostgrestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class PostgrestBuilder: @unchecked Sendable {
options: FetchOptions,
decode: (Data) throws -> T
) async throws -> PostgrestResponse<T> {
mutableState.withValue {
let request = mutableState.withValue {
$0.fetchOptions = options

if $0.fetchOptions.head {
Expand All @@ -103,9 +103,11 @@ public class PostgrestBuilder: @unchecked Sendable {
$0.request.headers["Content-Profile"] = schema
}
}

return $0.request
}

let response = try await http.fetch(mutableState.value.request, baseURL: configuration.url)
let response = try await http.fetch(request, baseURL: configuration.url)

guard 200 ..< 300 ~= response.statusCode else {
let error = try configuration.decoder.decode(PostgrestError.self, from: response.data)
Expand Down

0 comments on commit 8063610

Please sign in to comment.