What's the best way to debounce a single value using Async Algorithms and AsyncSequence
?
In Combine
you could use something like this for a published property:
@Published var username = ""
var validateUsername: AnyPublisher<String, Never> {
$username
.debounce(for: 0.5, scheduler: RunLoop.main)
.removeDuplicates()
.eraseToAnyPublisher()
}
I've seen debounce
in Async Algorithms, but how can I observe a property to collect into an AsyncSequence
? didSet
or a better way?
@observable class Account {
var username = ""
fun validateUsername(_ usernames: some AsyncSequence) {
let queries = usernames
.debounce(for: .milliseconds(300))
// do something with queries
}
}
Thanks