Signal
public struct Signal<Payload>
extension Signal: Combine.Publisher
Signal is a typed interface for observing arbitrary values over time.
Signal delegates observers managing logic to the observeImpl closure, but provides flexible interface for observing.
Note
Signal is iOS12-compatible simplified alternative to Combine.Publisher. It’s behavior is
aligned with Publisher for easier future migration to Combine. If your app supports iOS >= 13.0, use Signal as Combine.Publisher .
-
Handles received payloads.
Declaration
Swift
public typealias Handler = (Payload) -> Void -
A closure that implements observing.
Declaration
Swift
public typealias ObserveImpl = (@escaping Handler) -> AnyCancelable -
Adds an observer closure that will be called every time signal is triggered.
Note
Analogous to
sinkin Combine.Declaration
Swift
public func observe(_ handler: @escaping Handler) -> AnyCancelableParameters
handlerA handler closure.
Return Value
Cancellable object that is used to cancel the subscription. If it is canceled or deinited the subscription will be cancelled immediately.
-
Creates a signal.
Declaration
Swift
public init(observeImpl: @escaping ObserveImpl)Parameters
observeImplA closure that implements observing.
-
Declaration
Swift
public typealias Output = Payload -
Declaration
Swift
public typealias Failure = Never -
Declaration
Swift
public func receive<S>(subscriber: S) where Payload == S.Input, S : Subscriber, S.Failure == Never -
Creates a signal that sends payload once to every subscribed.
Note
The created signal is analogous to the
Combine.Just.Declaration
Swift
public init(just constant: Payload)Parameters
justA payload.
-
Adds an observer closure that will be triggered only once.
Note
Analogous to
prefix(1).sinkin Combine.Declaration
Swift
public func observeNext(_ handler: @escaping Handler) -> AnyCancelableParameters
handlerA handler closure.
Return Value
Cancellable object that is used to cancel the subscription. If it is canceled or deinited the subscription will be cancelled immediately.
Signal Structure Reference