SubscriberType

public struct SubscriberType<Element, ErrorType> where ErrorType : Error

Abstraction over subscriber/observer types from reactive frameworks. This abstraction uses concept similar to type-erasure or protocol witness pattern, wrapping the behaviour of concrete implementations and delegating to them once the wrapper funcions are called.

  • Closure to handle new values received

    Declaration

    Swift

    public let onValue: (Element) -> Void
  • Closure to handle completion, which has an optional error in case the completion happened due to an error being emitted

    Declaration

    Swift

    public let onCompleted: (ErrorType?) -> Void
  • Closure to handle subscription event

    Declaration

    Swift

    public let onSubscribe: (SubscriptionType) -> Void
  • Protocol-witness of a subscriber. Configure the behaviour of this wrapper from a concrete implementation from your favourite reactive framework.

    Declaration

    Swift

    public init(onValue: ((Element) -> Void)? = nil,
                onCompleted: ((ErrorType?) -> Void)? = nil,
                onSubscribe: ((SubscriptionType) -> Void)? = nil)

    Parameters

    onValue

    Closure to handle new values received

    onCompleted

    Closure to handle completion, which has an optional error in case the completion happened due to an error being emitted

    onSubscribe

    Closure to handle subscription event

  • Transforms any subscriber into a Unfailable subscriber with the same element type. After calling this method, a subscriber will be derived and it won’t accept publishers that can fail.

    Declaration

    Swift

    public func assertNoFailure() -> SubscriberType<Element, Never>