Finite observables and infinite observables refer to the number of elements that an observable sequence can emit.
- A finite observable is an observable sequence that emits a limited number of elements and then completes.
- It's important to note that finite observables must complete, otherwise, it can lead to memory leaks or unexpected behavior in application.
- An Infinite observable is an observable sequence that never completes.
- Infinite observables must have a mechanism for stopping or disposing of the subscription, otherwise, it can also lead to unexpected behavior or performance issues.
let items = [1, 2, 3, 4, 5]
let observable = Observable.from(items)
observable.subscribe(onNext: { item in
print(item)
}, onCompleted: {
print("Completed")
})
// 1
// 2
// 3
// 4
// 5
// Completed
let observable = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
observable.subscribe(onNext: { time in
print(time)
})
- chat.openai.com "what is �different Hot Observable VS Cold Observable"
- [[RxSwift-Ch 2. Observables]]
- [[3. RxSwift 기본 개념]]
- #IOS/RxSwift/Observable/finite
- #IOS/RxSwift/Observable/Infinite