Single

public protocol Single<Element> : Subscribable

A Subscribable implementation whereby only a single result is expected to be emitted to the subscriber.

  • Declaration

    Swift

    @discardableResult
    func subscribe(_ observer: @escaping Observer) -> any Disposable
  • onSuccess(handler:) Extension method

    Subscribe an handler to this Single which will be called at most once if the Single is successful.

    Declaration

    Swift

    @discardableResult
    func onSuccess<Value>(handler: @escaping (_ output: Value) -> Void) -> Disposable where Value == Self.Element.ValueType, Self.Element : ValueExtractor

    Return Value

    A Disposable that can be disposed if the handler is no longer necessary.

  • onFailure(handler:) Extension method

    Subscribe an handler to this Single which will be called at most once if the Single is unsuccessful.

    Declaration

    Swift

    @discardableResult
    func onFailure<ErrorType>(handler: @escaping (_ error: ErrorType) -> Void) -> Disposable where ErrorType == Self.Element.ErrorType, Self.Element : ErrorExtractor

    Return Value

    A Disposable that can be disposed if the handler is no longer necessary.

  • toAsync() Extension method, asynchronous

    Transforms this single into an async function that can be awaited on.

    Declaration

    Swift

    func toAsync<Value>() async throws -> Value where Self.Element == Result<Value, any Error>