Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage async await #8289

Merged
merged 18 commits into from
Jul 23, 2021
Prev Previous commit
Next Next commit
style
  • Loading branch information
paulb777 committed Jul 23, 2021
commit 7950d7ea42061dfe1f65148589eee2a66f1efa52
15 changes: 7 additions & 8 deletions FirebaseStorageSwift/Sources/AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,35 @@ import FirebaseStorage
#if swift(>=5.5)
@available(iOS 15, *)
public extension StorageReference {

func data(maxSize: Int64) async throws -> Data {
typealias DataContinuation = CheckedContinuation<Data, Error>
return try await withCheckedThrowingContinuation({ (continuation: DataContinuation) in
return try await withCheckedThrowingContinuation { (continuation: DataContinuation) in
// TODO: Use task to handle progress and cancellation.
let _ = self.getData(maxSize: maxSize) { result in
_ = self.getData(maxSize: maxSize) { result in
switch result {
case let .success(data):
continuation.resume(returning: data)
case let .failure(error):
continuation.resume(throwing: error)
}
}
})
}
}

func putDataAwait(_ uploadData: Data,
metadata: StorageMetadata? = nil) async throws -> StorageMetadata {
metadata: StorageMetadata? = nil) async throws -> StorageMetadata {
typealias MetadataContinuation = CheckedContinuation<StorageMetadata, Error>
return try await withCheckedThrowingContinuation({ (continuation: MetadataContinuation) in
return try await withCheckedThrowingContinuation { (continuation: MetadataContinuation) in
// TODO: Use task to handle progress and cancellation.
let _ = self.putData(uploadData, metadata: metadata) { result in
_ = self.putData(uploadData, metadata: metadata) { result in
switch result {
case let .success(data):
continuation.resume(returning: data)
case let .failure(error):
continuation.resume(throwing: error)
}
}
})
}
}
}
#endif
2 changes: 1 addition & 1 deletion FirebaseStorageSwift/Sources/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import FirebaseStorage

private enum DataError: Error {
case internalInconsistency // Thrown when both value and error are nil.
case internalInconsistency // Thrown when both value and error are nil.
}

/// Generates a closure that returns a `Result` type from a closure that returns an optional type
Expand Down