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.
-
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 returnedResult
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 theStream.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
Parameters
source
The upstream publisher which emits item to be sent to the peer.