Stream

public class Stream<StreamRequestType> : Publisher where StreamRequestType : StreamRequest

An instance of the stream class is returned whenever a StreamRequest is scheduled. The stream publisher produces arbitrarily many values (depending on the messages from the connected peer). The publisher also provides additional send methods to enable bidirectional communication. Note that publisher only errors out if the stream fails and continues to exist if single messages from the peer cause an error. This is the reason for the stream’s output to be of the type Result. Also note that the publisher never completes.

Note that, in contrast to the Response publisher, this publisher does not replay any messages received.

Types

  • Declaration

    Swift

    public typealias Failure = Squid.Error
  • Declaration

    Swift

    public typealias Output = Result<StreamRequestType.Result, Squid.Error>

Instance Methods

  • This simple variant of the send method sends a message to the peer to which the WebSocket is connected. The result is a publisher which never errors out. Whether the request was successful can be deduced from the publisher’s single returned Result instance. Note that the returned publishers is shared and replays the result.

    Declaration

    Swift

    public func send(
        _ message: StreamRequestType.Message
    ) -> AnyPublisher<Result<Void, Squid.Error>, Never>

    Parameters

    message

    The message to send to the peer.

  • This variant of the send method provides a more reactive approach towards sending messages to a peer. Every value emitted by the publisher will be sent via the Stream.send(_:) method and the response will be emitted by the publisher returned by this method. Note that, due to missing documentation on Apple’s side, we cannot guarantee that the order of the items emitted by the returned publisher is the same as the order of the items emitted by the upstream publisher. Also, the returned publisher will never fail. The user is responsible for cancelling the subscription as soon as the stream is cancelled.

    Declaration

    Swift

    public func send<P>(from source: P) -> some Publisher
    where P: Publisher, P.Output == StreamRequestType.Message, P.Failure == Never

    Parameters

    source

    The upstream publisher which emits item to be sent to the peer.

Publisher