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

Main queue replaced with custom serial queue #396

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions Haneke/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ open class Cache<T: DataConvertible> where T.Result == T, T : DataRepresentable
Log.error(message: "Failed to remove path \(path)", error: error)
}
if let completion = completion {
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
completion()
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ open class Cache<T: DataConvertible> where T.Result == T, T : DataRepresentable
let value = T.convertFromData(data)
if let value = value {
let descompressedValue = self.decompressedImageIfNeeded(value)
DispatchQueue.main.async(execute: {
HanekeGlobals.Queue.async(execute: {
succeed(descompressedValue)
let wrapper = ObjectWrapper(value: descompressedValue)
memoryCache.setObject(wrapper, forKey: key as AnyObject)
Expand Down Expand Up @@ -264,7 +264,7 @@ open class Cache<T: DataConvertible> where T.Result == T, T : DataRepresentable
}
}

DispatchQueue.main.async {
HanekeGlobals.Queue.async {
succeed(formatted)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Haneke/DiskCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ open class DiskCache {
let path = self.path(forKey: key)
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: Data.ReadingOptions())
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
succeed(data)
}
self.updateDiskAccessDate(atPath: path)
} catch {
if let block = fail {
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
block(error)
}
}
Expand Down Expand Up @@ -100,7 +100,7 @@ open class DiskCache {
Log.error(message: "Failed to list directory", error: error)
}
if let completion = completion {
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
completion()
}
}
Expand Down
6 changes: 3 additions & 3 deletions Haneke/DiskFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class DiskFetcher<T : DataConvertible> : Fetcher<T> {
do {
data = try Data(contentsOf: URL(fileURLWithPath: self.path), options: Data.ReadingOptions())
} catch {
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
if self.cancelled {
return
}
Expand All @@ -76,13 +76,13 @@ open class DiskFetcher<T : DataConvertible> : Fetcher<T> {
let localizedFormat = NSLocalizedString("Failed to convert value from data at path %@", comment: "Error description")
let description = String(format:localizedFormat, self.path)
let error = errorWithCode(HanekeGlobals.DiskFetcher.ErrorCode.invalidData.rawValue, description: description)
DispatchQueue.main.async {
HanekeGlobals.Queue.async {
fail(error)
}
return
}

DispatchQueue.main.async(execute: {
HanekeGlobals.Queue.async(execute: {
if self.cancelled {
return
}
Expand Down
3 changes: 3 additions & 0 deletions Haneke/Haneke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import UIKit
public struct HanekeGlobals {

public static let Domain = "io.haneke"
public static let Queue:DispatchQueue = {
return DispatchQueue(label: "io.haneke.callback_queue")
}()

}

Expand Down
6 changes: 3 additions & 3 deletions Haneke/NetworkFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class NetworkFetcher<T : DataConvertible> : Fetcher<T> {
if ((error as NSError).domain == NSURLErrorDomain && (error as NSError).code == NSURLErrorCancelled) { return }

Log.debug(message: "Request \(URL.absoluteString) failed", error: error)
DispatchQueue.main.async(execute: { fail(error) })
HanekeGlobals.Queue.async(execute: { fail(error) })
return
}

Expand All @@ -93,13 +93,13 @@ open class NetworkFetcher<T : DataConvertible> : Fetcher<T> {
return
}

DispatchQueue.main.async { succeed(value) }
HanekeGlobals.Queue.async { succeed(value) }

}

fileprivate func failWithCode(_ code: HanekeGlobals.NetworkFetcher.ErrorCode, localizedDescription: String, failure fail: @escaping ((Error?) -> ())) {
let error = errorWithCode(code.rawValue, description: localizedDescription)
Log.debug(message: localizedDescription, error: error)
DispatchQueue.main.async { fail(error) }
HanekeGlobals.Queue.async { fail(error) }
}
}
12 changes: 8 additions & 4 deletions Haneke/UIImageView+Haneke.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public extension UIImageView {
if didSetImage { return }

if let placeholder = placeholder {
self.image = placeholder
DispatchQueue.main.async {
self.image = placeholder
}
}
}

Expand Down Expand Up @@ -121,9 +123,11 @@ public extension UIImageView {
if let succeed = succeed {
succeed(image)
} else if animated {
UIView.transition(with: self, duration: HanekeGlobals.UIKit.SetImageAnimationDuration, options: .transitionCrossDissolve, animations: {
self.image = image
}, completion: nil)
DispatchQueue.main.async {
UIView.transition(with: self, duration: HanekeGlobals.UIKit.SetImageAnimationDuration, options: .transitionCrossDissolve, animations: {
self.image = image
}, completion: nil)
}
} else {
self.image = image
}
Expand Down