Pulishers.IgnoreOutput

μ œλ„€λ¦­ ꡬ쑰체 | μƒμœ„μ— 흐λ₯΄λŠ” μš”μ†ŒλŠ” λͺ¨λ‘ λ¬΄μ‹œν•˜λ‚˜, μ™„λ£Œ μƒνƒœ(μ’…λ£Œ λ˜λŠ” μ‹€νŒ¨)λŠ” λ”°λ₯΄λŠ” Publisher

μ΄λ‹ˆμ…œλΌμ΄μ €λŠ” ν•œ 개의 인자λ₯Ό λ°›λŠ”λ‹€.

  • upstream : μƒμœ„μ— 흐λ₯΄λŠ” Publisher

μƒμœ„μ— 흐λ₯΄λŠ” Publisher의 μ—λŸ¬λ‚˜ μ™„λ£Œμ™€ 같은 μ™„λ£Œ μƒνƒœλ§Œ λ°›μ•„ μ²˜λ¦¬ν•˜κ³  싢을 λ•Œ μ‚¬μš©ν•  수 μžˆλ‹€.

ignoreOutput μ˜€νΌλ ˆμ΄ν„°μ™€ 관련이 μžˆλ‹€.

// Publishers.IgnoreOutput Publisher
Publishers
  .IgnoreOutput(upstream: Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3]))
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine IgnoreOutput Error")
    case .finished:
      print("Combine IgnoreOutput Finish")
    }
  }, receiveValue: { value in
    print("Combine IgnoreOutput : \(value)")
   })
  .store(in: &cancellables)

// ignoreOutput Operator
Publishers.Sequence<[Int], Never>(sequence: [1, 2, 3])
  .ignoreOutput()
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine IgnoreOutput Error")
    case .finished:
      print("Combine IgnoreOutput Finish")
    }
  }, receiveValue: { value in
    print("Combine IgnoreOutput : \(value)")
  })
  .store(in: &cancellables)

// Combine IgnoreOutput Finish

μƒμœ„ Publisherκ°€ 1, 2, 3의 값을 μ°¨λ‘€λŒ€λ‘œ λ‚΄μ§€λ§Œ ignoreOutput에 μ˜ν•΄ λͺ¨λ‘ λ¬΄μ‹œλ˜κ³ , μ •μƒμ μœΌλ‘œ μ’…λ£Œν•˜κΈ° λ•Œλ¬Έμ— μ’…λ£Œμ— λŒ€ν•΄μ„œλ§Œ μ²˜λ¦¬ν•œλ‹€.

RxSwift

ignoreElements μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„ν•  수 μžˆλ‹€.

Observable.from([1, 2, 3])
  .ignoreElements()
  .subscribe(onCompleted: {
    print("RxSwift IgnoreOutput Finish")
  }, onError: { _ in
    print("RxSwift IgnoreOutput Error")
  })
  .disposed(by: disposeBag)

// RxSwift IgnoreOutput Finish

ReactiveSwift

ν•΄λ‹Ή κΈ°λŠ₯을 κ΅¬ν˜„ν•  수 μžˆλŠ” 방법을 μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

μ°Έκ³ 

ReactiveX - Operators - IgnoreElements

Last updated