Skip to content

Latest commit

 

History

History
48 lines (43 loc) · 1.43 KB

5. Finite Observable VS Infinite Observable.md

File metadata and controls

48 lines (43 loc) · 1.43 KB

날짜: 2023-02-12 15:22

주제: What is �different Hot Observable VS Cold Observable


메모:

Finite observables and infinite observables refer to the number of elements that an observable sequence can emit.

Finite Observable

  • 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.

Infinite Observable

  • 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.

Example

Finite
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 
Infinite
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 기본 개념]]

Tag

  • #IOS/RxSwift/Observable/finite
  • #IOS/RxSwift/Observable/Infinite