This file contains hidden or 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
/// Wait for async operation to return value and call callback with the value | |
/// This class is intended to workaround/simplify async/await + actors isolation | |
/// https://twitter.com/krzyzanowskim/status/1523233140914876416 | |
private class AsyncWaiter<T> { | |
var didReceiveValue: Bool = false | |
let value: (T) -> Void | |
let operation: () async throws -> T | |
init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) { | |
self.value = value |
This file contains hidden or 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
import Foundation | |
class Debounce { | |
private let queue: DispatchQueue | |
private let delay: Double | |
private var workItem: DispatchWorkItem? | |
private var cancelBlock: (() -> Void)? | |
init(queue: DispatchQueue, delay: Double) { | |
self.queue = queue |
This file contains hidden or 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
import Foundation | |
class Throttle { | |
private let queue: DispatchQueue | |
private let delay: Double | |
private var delayedBlock: (() -> Void)? | |
private var cancelBlock: (() -> Void)? | |
private var timer: DispatchSourceTimer? | |
private var isReady = true | |
private var hasDelayedBlock: Bool { delayedBlock != nil } |