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
Result. Also note that the publisher never completes.
Note that, in contrast to the
Response publisher, this publisher does not replay any
public typealias Failure = ServiceType.RequestError
public typealias Output = Result<StreamRequestType.Result, Squid.Error>
This simple variant of the
sendmethod 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
Resultinstance. Note that the returned publishers is shared and replays the result.
public func send( _ message: StreamRequestType.Message ) -> AnyPublisher<Result<Void, Squid.Error>, Never>
The message to send to the peer.
This variant of the
sendmethod 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.
The upstream publisher which emits item to be sent to the peer.