Observables
public enum Observables
Contains factory methods for creating common Observable instances for use with the Tealium SDK.
-
Creates a custom observable from a subscription handler.
The handler is invoked every time the returned
Observableis subscribed to. Within the handler, callobserver.onNext(_:)to emit elements andobserver.onComplete()to signal termination.The
Disposablereturned from the handler is disposed when the subscription is externally disposed, allowing the handler to cancel any ongoing work.Declaration
Swift
static func create<Element>(subscriptionHandler: @escaping Observable<Element>.SubscriptionHandler) -> Observable<Element>Parameters
subscriptionHandlerA block invoked on each subscription. Receives an
Observerand must return aDisposablethat will be disposed when the subscription is cancelled.Return Value
An
Observablethat invokessubscriptionHandleron each subscription. -
Returns an observable that will send only one event once the asyncFunction has completed.
Declaration
Swift
static func callback<Element>(from asyncFunction: @escaping (@escaping (Element) -> Void) -> Void) -> Observable<Element>Parameters
asyncFunctionis the function that needs to be called and needs to report the completion to the provided observer. This function will only be called when an observer subscribes to the returned Observable. Every subscription will cause the asyncFunction to be called again.
Return Value
a
Observablethat, when a new observer subscribes, will call the asyncFunction and emit a new event to the subscribers when the function completes. -
Returns an observable that will send only one event once the asyncFunction has completed.
Declaration
Swift
static func callback<Element>(from asyncFunction: @escaping (@escaping (Element) -> Void) -> any Disposable) -> Observable<Element>Parameters
asyncFunctionis the function that needs to be called and needs to report the completion to the provided observer. This function will only be called when an observer subscribes to the returned Observable. Every subscription will cause the asyncFunction to be called again. The
Disposablereturned by this function will be disposed if the subscription is disposed before the event is emitted, allowing to cancel the ongoing work.Return Value
a
Observablethat, when a new observer subscribes, will call the asyncFunction and emit a new event to the subscribers when the function completes. -
Returns an observable that just reports the provided elements in order to each new subscriber.
Declaration
Swift
static func just<Element>(_ elements: Element...) -> Observable<Element> -
Returns an observable that just reports the provided elements in order to each new subscriber.
Declaration
Swift
static func from<Element>(_ elements: [Element]) -> Observable<Element> -
Returns an observable that completes immediately without emitting any elements.
Declaration
Swift
static func empty<Element>() -> Observable<Element> -
Combines the latest values from all provided observables into an array.
The first emission occurs once every source observable has emitted at least one element. After that, a new array is emitted each time any source emits a new value.
Completion: Completes when all sources complete, or early if any source completes without ever having emitted a value (since a full combination can never be formed).
Declaration
Swift
static func combineLatest<Element>(_ observables: [Observable<Element>]) -> Observable<[Element]>
View on GitHub