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

Fix concurrency warnings #533

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Sources/Navigator/Audiobook/AudioNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,9 @@ public final class AudioNavigator: Navigator, Configurable, AudioSessionUser, Lo
// Seeks to time
let time = locator.locations.time?.begin ?? ((resourceDuration ?? 0) * (locator.locations.progression ?? 0))

await withCheckedContinuation { continuation in
player.seek(to: CMTime(seconds: time, preferredTimescale: 1000)) { [weak self] finished in
if let self = self, finished {
Task { @MainActor in
self.delegate?.navigator(self, didJumpTo: locator)
}
}
continuation.resume()
}
let finished = await player.seek(to: CMTime(seconds: time, preferredTimescale: 1000))
if finished {
await delegate?.navigator(self, didJumpTo: locator)
}

return true
Expand Down
8 changes: 7 additions & 1 deletion Sources/Navigator/Audiobook/PublicationMediaLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ReadiumShared
/// Serves `Publication`'s `Resource`s as an `AVURLAsset`.
///
/// Useful for local resources or when you need to customize the way HTTP requests are sent.
final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Loggable {
final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Loggable, @unchecked Sendable {
public enum AssetError: Error {
/// Can't produce an URL to create an AVAsset for the given HREF.
case invalidHREF(String)
Expand Down Expand Up @@ -51,6 +51,8 @@ final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Log
private var resources: [AnyURL: (Link, Resource)] = [:]

private func resource<T: URLConvertible>(forHREF href: T) -> (Link, Resource)? {
dispatchPrecondition(condition: .onQueue(queue))

let href = href.anyURL
if let res = resources[equivalent: href] {
return res
Expand All @@ -75,6 +77,8 @@ final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Log

/// Adds a new loading request.
private func registerRequest<T: URLConvertible>(_ request: AVAssetResourceLoadingRequest, task: Task<Void, Never>, for href: T) {
dispatchPrecondition(condition: .onQueue(queue))

let href = href.anyURL
var reqs: [CancellableRequest] = requests[href] ?? []
reqs.append((request, task))
Expand All @@ -83,6 +87,8 @@ final class PublicationMediaLoader: NSObject, AVAssetResourceLoaderDelegate, Log

/// Terminates and removes the given loading request, cancelling it if necessary.
private func finishRequest(_ request: AVAssetResourceLoadingRequest) {
dispatchPrecondition(condition: .onQueue(queue))

guard
let href = request.request.url?.audioHREF,
var reqs = requests[href],
Expand Down