Publishers

extension Publishers

Publisher

  • Converts a materialized publisher of Signals into the represented sequence. Fails on a malformed source sequence.

    Use this operator to convert a stream of Signal values from an upstream publisher into its materially represented publisher type. Malformed sequences will fail with a DematerializationError.

    For each element:

    • .subscription elements are ignored
    • .input(_) elements are unwrapped and forwarded to the subscriber
    • .completion(_) elements are forwarded within the DematerializationError wrapper

    If the integrity of the upstream sequence can be guaranteed, applying the assertNoDematerializationFailure() operator to this publisher will force unwrap any errors and produce a publisher with a Failure type that matches the materially represented original sequence.

    See more

    Declaration

    Swift

    public struct Dematerialize<Upstream> : Publisher where Upstream : Publisher, Upstream.Output : SignalConvertible
  • Wraps all the elements as well as the subscription and completion events of an upstream publisher into a stream of Signal elements

    See more

    Declaration

    Swift

    public struct Materialize<Upstream> : Publisher where Upstream : Publisher
  • Automates the process of connecting to a multicast publisher. Connects when the first subscriber connects then cancels and discards when the subscriber count falls to zero.

    See more

    Declaration

    Swift

    public final class ReferenceCounted<Upstream: Publisher, SubjectType: Subject>: Publisher
        where Upstream.Output == SubjectType.Output, Upstream.Failure == SubjectType.Failure

Operator

Publisher configuration

  • Configuration values for the Publishers.Signpost operator.

    Pass Publishers.SignpostConfiguration.Marker values to the initializer to define how signposts for each event should be labelled:

    • A nil marker value will disable signposts for that event
    • A .default marker value will use the event name as the event label
    • A .named(_:) marker value will use the passed string as the event label
    See more

    Declaration

    Swift

    public struct SignpostConfiguration
  • A publisher that combines the latest value from another publisher with each value from an upstream publisher

    See more

    Declaration

    Swift

    public struct WithLatestFrom<Upstream, Other, Output> : Publisher where Upstream : Publisher, Other : Publisher, Upstream.Failure == Other.Failure
  • Creates a simple publisher inline from a provided closure

    This publisher can be used to turn any arbitrary source of values (such as a timer or a user authorization request) into a new publisher sequence.

    From within the scope of the closure passed into the initializer, it is possible to call the methods of the Dispatcher object – which is passed in as a parameter – to send values down stream.

    Example

    
    import Entwine
    
    let photoKitAuthorizationStatus = Publishers.Factory<PHAuthorizationStatus, Never> { dispatcher in
        let status = PHPhotoLibrary.authorizationStatus()
        dispatcher.forward(status)
        switch status {
        case .notDetermined:
            PHPhotoLibrary.requestAuthorization { newStatus in
                dispatcher.forward(newStatus)
                dispatcher.forward(completion: .finished)
            }
        default:
            dispatcher.forward(completion: .finished)
        }
        return AnyCancellable {}
    }
    

    Warning

    Developers should be aware that a Dispatcher has an unbounded buffer that stores values yet to be requested by the downstream subscriber.

    When creating a publisher from a source with an unbounded rate of production that cannot be influenced, developers should consider following this operator with a Publishers.Buffer operator to prevent a strain on resources

    See more

    Declaration

    Swift

    public struct Factory<Output, Failure> : Publisher where Failure : Error