Skip to content

Commit b981f4d

Browse files
feat: Swift 6.2 update
1 parent d06f828 commit b981f4d

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

Sources/GoodAsyncExtensions/AsyncExtensions.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,25 @@ public extension Publisher where Output == Alamofire.Empty {
214214
@available(*, deprecated, message: "Heads up: this is unsafe!")
215215
public func unsafeBlockingSync<T: Sendable>(_ asyncFunction: sending @escaping () async throws -> T) throws -> T {
216216
let semaphore = DispatchSemaphore(value: 0)
217-
var result: T?
218-
var failure: (any Error)?
217+
var result: Result<T, Error>?
219218
Task.detached {
220219
defer { semaphore.signal() }
221220
do {
222-
result = try await asyncFunction()
221+
result = .success(try await asyncFunction())
223222
} catch let error {
224-
failure = error
223+
result = .failure(error)
225224
}
226225
}
227226
semaphore.wait()
228-
229-
guard let result else { throw failure ?? preconditionFailure("Async function did not return") }
230-
return result
227+
228+
switch result {
229+
case .success(let value):
230+
return value
231+
case .failure(let failure):
232+
throw failure
233+
case nil:
234+
preconditionFailure("Async function did not return")
235+
}
231236
}
232237

233238
/// Calls an asynchronous function synchronously, waiting for the result and blocking the caller.

Sources/GoodExtensions/Typealiases/Typealiases.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public typealias NonSendableFunction<T, U> = (T) -> (U)
3434

3535
// MARK: Throwing
3636

37-
public typealias ThrowingVoidClosure<E> = @Sendable () throws(E) -> ()
38-
public typealias ThrowingSupplier<T, E> = @Sendable () throws(E) -> (T)
39-
public typealias ThrowingConsumer<T, E> = @Sendable (T) throws(E) -> ()
40-
public typealias ThrowingBiConsumer<T, U, E> = @Sendable (T, U) throws(E) -> ()
41-
public typealias ThrowingPredicate<T, E> = @Sendable (T) throws(E) -> Bool
42-
public typealias ThrowingFunction<T, U, E> = @Sendable (T) throws(E) -> (U)
37+
public typealias ThrowingVoidClosure<E: Error> = @Sendable () throws(E) -> ()
38+
public typealias ThrowingSupplier<T, E: Error> = @Sendable () throws(E) -> (T)
39+
public typealias ThrowingConsumer<T, E: Error> = @Sendable (T) throws(E) -> ()
40+
public typealias ThrowingBiConsumer<T, U, E: Error> = @Sendable (T, U) throws(E) -> ()
41+
public typealias ThrowingPredicate<T, E: Error> = @Sendable (T) throws(E) -> Bool
42+
public typealias ThrowingFunction<T, U, E: Error> = @Sendable (T) throws(E) -> (U)
4343

4444
// MARK: MainActor
4545

@@ -52,9 +52,9 @@ public typealias MainFunction<T, U> = @MainActor (T) -> (U)
5252

5353
// MARK: MainActor + Throwing
5454

55-
public typealias MainThrowingVoidClosure<E> = @MainActor () throws(E) -> ()
56-
public typealias MainThrowingSupplier<T, E> = @MainActor () throws(E) -> (T)
57-
public typealias MainThrowingConsumer<T, E> = @MainActor (T) throws(E) -> ()
58-
public typealias MainThrowingBiConsumer<T, U, E> = @MainActor (T, U) throws(E) -> ()
59-
public typealias MainThrowingPredicate<T, E> = @MainActor (T) throws(E) -> Bool
60-
public typealias MainThrowingFunction<T, U, E> = @MainActor (T) throws(E) -> (U)
55+
public typealias MainThrowingVoidClosure<E: Error> = @MainActor () throws(E) -> ()
56+
public typealias MainThrowingSupplier<T, E: Error> = @MainActor () throws(E) -> (T)
57+
public typealias MainThrowingConsumer<T, E: Error> = @MainActor (T) throws(E) -> ()
58+
public typealias MainThrowingBiConsumer<T, U, E: Error> = @MainActor (T, U) throws(E) -> ()
59+
public typealias MainThrowingPredicate<T, E: Error> = @MainActor (T) throws(E) -> Bool
60+
public typealias MainThrowingFunction<T, U, E: Error> = @MainActor (T) throws(E) -> (U)

0 commit comments

Comments
 (0)