Publishers.HandleEvents

μ œλ„€λ¦­ ꡬ쑰체 | Publisher의 μ΄λ²€νŠΈκ°€ λ°œμƒν•  λ•Œ νŠΉμ • ν΄λ‘œμ €λ₯Ό μˆ˜ν–‰ν•˜λŠ” Publisher

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

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

  • receiveSubscription : Publisherκ°€ μƒμœ„ Publisherλ‘œλΆ€ν„° ꡬ독을 전달받을 λ•Œ μˆ˜ν–‰ν•  ν΄λ‘œμ €. 기본값은 nil

  • receiveOutput : Publisherκ°€ μƒμœ„ Publisherλ‘œλΆ€ν„° 값을 전달받을 λ•Œ μˆ˜ν–‰ν•  ν΄λ‘œμ €. 기본값은 nil

  • receiveCompletion : Publisherκ°€ μƒμœ„ Publisherλ‘œλΆ€ν„° μ™„λ£Œλ₯Ό 전달받을 λ•Œ μˆ˜ν–‰ν•  ν΄λ‘œμ €. 기본값은 nil

  • receiveCancel : ν•˜μœ„ λ¦¬μ‹œλ²„κ°€ λ°œν–‰μ„ μ·¨μ†Œν•  λ•Œ μˆ˜ν–‰ν•  ν΄λ‘œμ €. 기본값은 nil

  • receiveRequest : Publisherκ°€ 더 λ§Žμ€ μš”μ†Œλ₯Ό μœ„ν•΄ μš”μ²­μ„ 전달받을 λ•Œ μˆ˜ν–‰ν•  ν΄λ‘œμ €. 기본값은 nil

슀트림의 생λͺ… μ£ΌκΈ° λ™μ•ˆ λ°œμƒν•˜λŠ” μ—¬λŸ¬ μ΄λ²€νŠΈμ—μ„œ μ‹€ν–‰ν•  μ•‘μ…˜μ„ λ“±λ‘ν•œλ‹€.

νŠΉμ • μ΄λ²€νŠΈκ°€ λ°œμƒν•  λ•Œ νŠΉμ • μž‘μ—…μ„ μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

Publisher의 생λͺ… μ£ΌκΈ°λ₯Ό μ΄ν•΄ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•  수 μžˆλ‹€.

sinkλŠ” Subscriber에 λŒ€ν•œ μ˜€νΌλ ˆμ΄ν„°κ³ , handleEventsλŠ” Publisher에 λŒ€ν•œ μ˜€νΌλ ˆμ΄ν„°λ‹€.

  • sinkλŠ” Subscriber의 ꡬ독에 μ˜ν•΄ μ΅œμ’…μ μœΌλ‘œ λ°œν–‰λœ μ΄λ²€νŠΈμ— λŒ€ν•΄ λ™μž‘ν•œλ‹€.

  • handleEventsλŠ” ꡬ독에 μ˜ν•΄ μƒμœ„ Publisherκ°€ λ°œν–‰ν•˜λŠ” μ΄λ²€νŠΈμ— λŒ€ν•΄ λ™μž‘ν•œλ‹€.

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

// Publishers.HandleEvents Publisher
Publishers
  .HandleEvents(upstream: Just(Void()),
                receiveSubscription: { _ in print("Combine HandleEvents ReceiveSubscription") },
                receiveOutput: { print("Combine HandleEvents ReceiveOutput") },
                receiveCompletion: { _ in print("Combine HandleEvents ReceiveCompletion") },
                receiveCancel: { print("Combine HandleEvents ReceiveCancel") },
                receiveRequest: { _ in print("Combine HandleEvents ReceiveRequest") })
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine HandleEvents Error")
    case .finished:
      print("Combine HandleEvents Finish")
    }
  }, receiveValue: {
    print("Combine HandleEvents")
  })
  .store(in: &cancellables)

// handleEvents Operator
Just(Void())
  .handleEvents(receiveSubscription: { _ in print("Combine HandleEvents ReceiveSubscription") },
                receiveOutput: { print("Combine HandleEvents ReceiveOutput") },
                receiveCompletion: { _ in print("Combine HandleEvents ReceiveCompletion") },
                receiveCancel: { print("Combine HandleEvents ReceiveCancel") },
                receiveRequest: { _ in print("Combine HandleEvents ReceiveRequest") })
  .sink(receiveCompletion: { completion in
    switch completion {
    case .failure:
      print("Combine HandleEvents Error")
    case .finished:
      print("Combine HandleEvents Finish")
    }
  }, receiveValue: {
    print("Combine HandleEvents")
  })
  .store(in: &cancellables)

// Combine HandleEvents Receive Request
// Combine HandleEvents Receive Subscription
// Combine HandleEvents Receive Output
// Combine HandleEvents
// Combine HandleEvents Receive Completion
// Combine HandleEvents Finish

κ²°κ³Όλ₯Ό 톡해 PublisherλŠ” μ—λŸ¬λ₯Ό λ‚΄μ§€ μ•ŠλŠ” 경우 λ‹€μŒκ³Ό 같은 μˆœμ„œλ‘œ λ™μž‘ν•œλ‹€λŠ” 것을 μ•Œ 수 μžˆλ‹€.

  1. Publisher : Receive Request

  2. Publisher : Receive Subscription

  3. Publisher : Receive Output

  4. Subscriber : Receive Value

  5. Publisher : Receive Completion

  6. Subscriber : Receive Finished

RxSwift

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

ReactiveSwift

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

μ°Έκ³ 

ReactiveX - Operators - Doarrow-up-right

Last updated