Skip to content

Commit

Permalink
Dispatch dot lottie file loading onto a single serial queue (#2229)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erichoracek authored Nov 7, 2023
1 parent f081afa commit 3d46f3f
Showing 1 changed file with 12 additions and 5 deletions.
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)
}

0 comments on commit 3d46f3f

Please sign in to comment.