This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/avito-tech | |
private class ObserverBox<T>: Hashable { | |
typealias Observer = T | |
private(set) weak var disposable: AnyObject? | |
private let objectIdentifier: ObjectIdentifier | |
var observers = [Observer]() | |
let hashValue: Int | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/avito-tech | |
// | |
// Sampler is like a baby of Debouncer and Throttler. | |
// | |
// Unlike Debouncer, sampler executes action immediately (if there are no actions before, for time > delay) | |
// Unlike Throttler it guarantees that last action in sequence will be executed (see last error in example) | |
/// CAUTION: This class isn't thread-safe | |
public final class Sampler { | |
// MARK: - Public properite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func with<T>(_ item: inout T, action: (inout T) -> Void) { | |
action(&item) | |
} | |
public func with<T>(_ item: T, action: (T) -> Void) { | |
action(item) | |
} | |
public func with<T: AnyObject>(_ item: T, action: (T) -> Void) { | |
action(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Result<T, E> { | |
case value(T) | |
case error(E) | |
var value: T? { | |
switch self { | |
case .value(let value): | |
return value | |
case .error: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private let timerQueue = DispatchQueue(label: "com.timer.queue", attributes: []) | |
final class Timer : NSObject { | |
private var timer: DispatchSourceTimer? | |
var active: Bool { | |
return timer != nil | |
} | |
func start(_ interval: Int, repeats: Bool = false, handler: @escaping () -> Void) { |