mapbox / mapbox/mapbox-maps-ios
Completion not being called when using "withCheckedThrowingContinuation"
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 14.2
- iOS version: 16.3
- Devices affected: sim and hardware
- Maps SDK Version: 10.10
## Observed behavior and steps to reproduce
Trying to make an async version of the callback-based API in MapBox, using the following code as example:
```
public func asyncTileRegions() async throws -> [TileRegion] {
return try await withCheckedThrowingContinuation { continuation in
TileStore.default.allTileRegions { result in
// depending on the content of result, we either resume with a value or an error
switch result {
case .success(let value):
value.forEach { region in
print("Region: \(region.id), \(region.completedResourceSize.formatted(.byteCount(style: .binary)))")
}
continuation.resume(returning: value)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}
```
The callback from ```allTileRegions``` does not get called. Console output is: SWIFT TASK CONTINUATION MISUSE: asyncTileRegions() leaked its continuation!
## Expected behavior
The callback is executed, and the region id and size is printed.
## Notes / preliminary analysis
This works as expected without the async and "withCheckedThrowingContinuation".
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the asyncTileRegions wrapper and the TileStore.default.allTileRegions callback shown in the issue, then compare this path with the working non-async version. Done means the callback executes, the region id and size are printed, and the checked continuation no longer leaks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100