Observer

public final class Observer<Value, Error: Swift.Error>

An Observer is a simple wrapper around a function which can receive Events (typically from a Signal).

  • An action that will be performed upon arrival of the event.

    Declaration

    Swift

    public let action: Action
  • An initializer that accepts a closure accepting an event for the observer.

    Declaration

    Swift

    public init(_ action: @escaping Action)

    Parameters

    action

    A closure to lift over received event.

  • An initializer that accepts closures for different event types.

    Declaration

    Swift

    public convenience init(
    		value: ((Value) -> Void)? = nil,
    		failed: ((Error) -> Void)? = nil,
    		completed: (() -> Void)? = nil,
    		interrupted: (() -> Void)? = nil
    	)

    Parameters

    value

    Optional closure executed when a value event is observed.

    failed

    Optional closure that accepts an Error parameter when a failed event is observed.

    completed

    Optional closure executed when a completed event is observed.

    interruped

    Optional closure executed when an interrupted event is observed.

  • Puts a value event into self.

    Declaration

    Swift

    public func send(value: Value)

    Parameters

    value

    A value sent with the value event.

  • Puts a failed event into self.

    Declaration

    Swift

    public func send(error: Error)

    Parameters

    error

    An error object sent with failed event.

  • Puts a completed event into self.

    Declaration

    Swift

    public func sendCompleted()
  • Puts an interrupted event into self.

    Declaration

    Swift

    public func sendInterrupted()