Single

public class Single<Element> : Subscribable

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

  • Declaration

    Swift

    @discardableResult
    public func subscribe<O>(_ observer: O) -> any Disposable where Element == O.Element, O : Observer
  • 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) -> any Disposable where Element : ValueExtractor, Value == Element.ValueType

    Return Value

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

  • 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) -> any Disposable where Element : ErrorExtractor, ErrorType == Element.ErrorType

    Return Value

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

  • toAsync() Asynchronous

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

    Declaration

    Swift

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