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.
    

    Throws

    The generic Failure emitted by the underlying Single, or a CancellationError if the Single completes before emitting the Result.

    Declaration

    Swift

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

    Return Value

    The generic Value emitted by the underlying Single.