Decode Twitter and Reddit on a background queue.
This commit is contained in:
parent
2324d652cd
commit
48ceb655d6
|
@ -253,13 +253,18 @@ private extension RedditFeedProvider {
|
|||
self.rateLimitReset = Date(timeIntervalSinceNow: Double(reset) ?? 0)
|
||||
}
|
||||
|
||||
let decoder = JSONDecoder()
|
||||
|
||||
do {
|
||||
let result = try decoder.decode(resultType, from: response.data)
|
||||
completion(.success(result))
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
let decoder = JSONDecoder()
|
||||
do {
|
||||
let result = try decoder.decode(resultType, from: response.data)
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(result))
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case .failure(let oathError):
|
||||
|
|
|
@ -359,21 +359,27 @@ private extension TwitterFeedProvider {
|
|||
self.rateLimitReset = Date(timeIntervalSince1970: Double(reset) ?? 0)
|
||||
}
|
||||
|
||||
do {
|
||||
let tweets: [TwitterStatus]
|
||||
if isSearch {
|
||||
let searchResult = try decoder.decode(TwitterSearchResult.self, from: response.data)
|
||||
if let statuses = searchResult.statuses {
|
||||
tweets = statuses
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
do {
|
||||
let tweets: [TwitterStatus]
|
||||
if isSearch {
|
||||
let searchResult = try decoder.decode(TwitterSearchResult.self, from: response.data)
|
||||
if let statuses = searchResult.statuses {
|
||||
tweets = statuses
|
||||
} else {
|
||||
tweets = [TwitterStatus]()
|
||||
}
|
||||
} else {
|
||||
tweets = [TwitterStatus]()
|
||||
tweets = try decoder.decode([TwitterStatus].self, from: response.data)
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
completion(.success(tweets))
|
||||
}
|
||||
} catch {
|
||||
DispatchQueue.main.async {
|
||||
completion(.failure(error))
|
||||
}
|
||||
} else {
|
||||
tweets = try decoder.decode([TwitterStatus].self, from: response.data)
|
||||
}
|
||||
completion(.success(tweets))
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
|
|
Loading…
Reference in New Issue