Publishers.AssertNoFailure

μ œλ„€λ¦­ ꡬ쑰체 | μ–΄λ– ν•œ μ‹€νŒ¨λ₯Ό μ „λ‹¬λ°›μœΌλ©΄ 치λͺ…적인 μ—λŸ¬λ₯Ό λ°œμƒμ‹œν‚€κ³ , 그렇지 μ•ŠμœΌλ©΄ 전달받은 λͺ¨λ“  μž…λ ₯을 λ‹€μ‹œ λ°œν–‰ν•˜λŠ” Publisher

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

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

  • prefix : μ—λŸ¬ λ©”μ„Έμ§€μ˜ μ‹œμž‘μ— 이어 뢙일 λ¬Έμžμ—΄

  • file : μ—λŸ¬ 메세지에 μ‚¬μš©λ  파일 이름

  • line : μ—λŸ¬ 메세지에 μ‚¬μš©λ  쀄 번호

말 κ·ΈλŒ€λ‘œ μ‹€νŒ¨κ°€ μ—†μŒμ„ λ‹¨μ–Έν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œλ‹€.

ν…ŒμŠ€νŠΈ μ€‘μ—λŠ” ν™œμ„±ν™”λ˜λ‚˜ μ‹€μ œ μ½”λ“œμ˜ μ„±λŠ₯μ—λŠ” 영ν–₯을 λ―ΈμΉ˜μ§€ μ•ŠλŠ” λ‚΄λΆ€ 검사λ₯Ό ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

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

// Publishers.AssertNoFailure Publisher
Publishers.AssertNoFailure(upstream: Fail<Void, Error>(error: error), prefix: "prefix", file: #file, line: #line)
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine AssertNoFailure Error")
    case .finished:
      print("Combine AssertNoFailure Finish")
    }
  }, receiveValue: { value in
    print("Combine AssertNoFailure : \(value)")
  })
  .store(in: &cancellables)

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

// 좜λ ₯ 값이 μ—†κ³ , λŸ°νƒ€μž„ μ—λŸ¬ λ°œμƒ

μƒμœ„ Publisherκ°€ Fail Publisher이기 λ•Œλ¬Έμ— μ—λŸ¬λ₯Ό λ‚΄κ³ , assertNoFailure에 μ˜ν•΄ λŸ°νƒ€μž„ μ—λŸ¬κ°€ λ°œμƒν•œλ‹€.

RxSwift

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

ReactiveSwift

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

Last updated