firebase / firebase/firebase-ios-sdk

[FR]: Add cancellation support to Storage async/await APIs

Open
#11,786 3 comments 3 reactions 0 assignees View on GitHub
api: storage Swift API type: feature request
Dominant language
C++
Stars
6.7k
Forks
1.8k
Avg merge
2d 14h
Merged PRs (30d)
72

Description

### Description

There are many functions on FirebaseStorage with callback parameter for async operations. These functions return an object to cancel the operations. Such as `StorageReference.getData(maxSize: Int64, completion: @escaping (Result) -> Void) -> StorageDownloadTask`.

These functions also has a wrapper function which support Swfit Concurrency.

However, these wrapper functions simply use `withCheckedThrowingContinuation` without any cancellation feature. It would be better that these functions also utilize `withTaskCancellationHandler` feature.

```
class Holder {
var value: T?
}

public extension StorageReference {
// This is the current Firebase implementation
func dataNotCancellable(maxSize: Int64) async throws -> Data {
return try await withCheckedThrowingContinuation { continuation in
_ = self.getData(maxSize: maxSize) { result in
continuation.resume(with: result)
}
}
}

// This is the proposed implementation
func dataCancallable(maxSize: Int64) async throws -> Data {
let holder: Holder = .init()
return try await withTaskCancellationHandler(operation: {
try await withCheckedThrowingContinuation { continuation in
holder.value = self.getData(maxSize: maxSize) { result in
continuation.resume(with: result)
}
}
}, onCancel: {
holder.value?.cancel()
})
}
}
```

### API Proposal

_No response_

### Firebase Product(s)

Storage

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.