This commit is contained in:
Ali
2019-11-14 23:27:44 +04:00
parent ca0668df3d
commit fec9a9b28e
267 changed files with 1273 additions and 3613 deletions

View File

@@ -0,0 +1,65 @@
import Foundation
import UIKit
import SwiftSignalKit
public typealias ListViewTransaction = (@escaping () -> Void) -> Void
public final class ListViewTransactionQueue {
private var transactions: [ListViewTransaction] = []
public final var transactionCompleted: () -> Void = { }
public init() {
}
public func addTransaction(_ transaction: @escaping ListViewTransaction) {
precondition(Thread.isMainThread)
let beginTransaction = self.transactions.count == 0
self.transactions.append(transaction)
if beginTransaction {
transaction({ [weak self] in
precondition(Thread.isMainThread)
if Thread.isMainThread {
if let strongSelf = self {
strongSelf.endTransaction()
}
} else {
Queue.mainQueue().async {
if let strongSelf = self {
strongSelf.endTransaction()
}
}
}
})
}
}
private func endTransaction() {
precondition(Thread.isMainThread)
Queue.mainQueue().async {
self.transactionCompleted()
if !self.transactions.isEmpty {
let _ = self.transactions.removeFirst()
}
if let nextTransaction = self.transactions.first {
nextTransaction({ [weak self] in
precondition(Thread.isMainThread)
if Thread.isMainThread {
if let strongSelf = self {
strongSelf.endTransaction()
}
} else {
Queue.mainQueue().async {
if let strongSelf = self {
strongSelf.endTransaction()
}
}
}
})
}
}
}
}