Publishers.Breakpoint

μ œλ„€λ¦­ ꡬ쑰체 | 제곡된 ν΄λ‘œμ €κ°€ λ””λ²„κ±°μ—μ„œ κ·Έ ν”„λ‘œμ„ΈμŠ€λ₯Ό μ€‘λ‹¨ν•˜λŠ” 것을 ν•„μš”λ‘œ ν•  λ•Œ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚€λŠ” Publisher

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

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

  • receiveSubscription : Publisherκ°€ ꡬ독을 전달받을 λ•Œ μ‹€ν–‰λ˜λ©°, true 값을 λ°˜ν™˜ν•˜μ—¬ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¬ 수 μžˆλŠ” ν΄λ‘œμ €

  • receiveOutput : Publisherκ°€ μƒμœ„ Publisherλ‘œλΆ€ν„° 좜λ ₯을 전달받을 λ•Œ μ‹€ν–‰λ˜λ©°, true 값읇 λ°˜ν™˜ν•˜μ—¬ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¬ 수 μžˆλŠ” ν΄λ‘œμ €

  • receiveCompletion : Publisherκ°€ μ™„λ£Œλ₯Ό 전달받을 λ•Œ μ‹€ν–‰λ˜λ©°, true 값을 λ°˜ν™˜ν•˜μ—¬ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¬ 수 μžˆλŠ” ν΄λ‘œμ €

handleEvents와 같은 μ‹œμ μ— λ™μž‘ν•˜λ‚˜ ν΄λ‘œμ €κ°€ trueλ₯Ό λ°˜ν™˜ν•˜κ²Œ ν•˜λ©΄ ν•΄λ‹Ή 이벀트 μ‹œμ μ—μ„œ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¬ 수 μžˆλ‹€.

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

// 1. Publishers.Breakpoint Publisher
Publishers.Breakpoint(upstream: Just(Void()),
                          receiveSubscription: { _ in true },
                          receiveOutput: { _ in true },
                          receiveCompletion: { _ in true })
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Breakpoint Error")
    case .finished:
      print("Combine Breakpoint Finish")
    }
  }, receiveValue: {
    print("Combine Breakpoint")
  })
  .store(in: &cancellables)

// 2. breakpoint Operator
Just(Void())
  .breakpoint(receiveSubscription: { _ in true },
              receiveOutput: { _ in true },
              receiveCompletion: { _ in true })
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Breakpoint Error")
    case .finished:
      print("Combine Breakpoint Finish")
    }
  }, receiveValue: {
    print("Combine Breakpoint")
  })
  .store(in: &cancellables)

// 3. breakpointOnError Operator
Fail<Void, Error>(error: error)
  .breakpointOnError()
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine Breakpoint Error")
    case .finished:
      print("Combine Breakpoint Finish")
    }
  }, receiveValue: {
    print("Combine Breakpoint")
  })
  .store(in: &cancellables)

1κ³Ό 2의 μ½”λ“œλŠ” ꡬ독, κ°’ λ°œν–‰, μ™„λ£Œ μ΄λ²€νŠΈκ°€ 일어날 λ•Œ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¨λ‹€.

3의 μ½”λ“œλŠ” μƒμœ„ Publisherκ°€ μ—λŸ¬λ₯Ό λ‚΄λ―€λ‘œ breakpointOnError에 μ˜ν•΄ 디버거 μ‹œκ·Έλ„μ„ μΌμœΌν‚¨λ‹€.

RxSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜λŠ” μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

ReactiveSwift

ν•΄λ‹Ή λ™μž‘μ„ κ΅¬ν˜„ν•˜λŠ” μ˜€νΌλ ˆμ΄ν„°λ₯Ό μ œκ³΅ν•˜μ§€ μ•ŠλŠ”λ‹€.

Last updated

Was this helpful?