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

Dispatch dot lottie file loading onto a single serial queue #2229

Merged
merged 1 commit into from
Nov 7, 2023
Merged
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
17 changes: 12 additions & 5 deletions Sources/Public/DotLottie/DotLottieFileHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extension DotLottieFile {
bundle: Bundle = Bundle.main,
subdirectory: String? = nil,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
dispatchQueue: DispatchQueue = .dotLottie,
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
{
dispatchQueue.async {
Expand Down Expand Up @@ -186,7 +186,7 @@ extension DotLottieFile {
public static func loadedFrom(
filepath: String,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
dispatchQueue: DispatchQueue = .dotLottie,
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
{
dispatchQueue.async {
Expand Down Expand Up @@ -228,7 +228,7 @@ extension DotLottieFile {
named name: String,
bundle: Bundle = Bundle.main,
dotLottieCache: DotLottieCacheProvider? = DotLottieCache.sharedCache,
dispatchQueue: DispatchQueue = .global(),
dispatchQueue: DispatchQueue = .dotLottie,
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
{
dispatchQueue.async {
Expand Down Expand Up @@ -331,7 +331,7 @@ extension DotLottieFile {
public static func loadedFrom(
data: Data,
filename: String,
dispatchQueue: DispatchQueue = .global(),
dispatchQueue: DispatchQueue = .dotLottie,
handleResult: @escaping (Result<DotLottieFile, Error>) -> Void)
{
dispatchQueue.async {
Expand All @@ -358,7 +358,7 @@ extension DotLottieFile {
public static func loadedFrom(
data: Data,
filename: String,
dispatchQueue: DispatchQueue = .global())
dispatchQueue: DispatchQueue = .dotLottie)
async throws -> DotLottieFile
{
try await withCheckedThrowingContinuation { continuation in
Expand All @@ -367,5 +367,12 @@ extension DotLottieFile {
}
}
}
}

extension DispatchQueue {
/// A serial dispatch queue ensures that IO related to loading dot Lottie files don't overlap,
/// which can trigger file loading errors due to concurrent unzipping on a single archive.
public static let dotLottie = DispatchQueue(
label: "com.airbnb.lottie.dot-lottie",
qos: .userInitiated)
}
Loading