mapbox / mapbox/mapbox-maps-ios

Completion not being called when using "withCheckedThrowingContinuation"

Open
#1,930 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle:
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.