CompactChangeStreamDelegate

public protocol CompactChangeStreamDelegate : AnyObject

A delegate that must be provided when opening a change stream for compact events. The methods called by this delegate will be called whenever the stream receives an event or encounters an error. To implement a class conforming to this protocol, be sure to add a typealias for the type of BSON documents that the delegate will react to. In most cases, this will be Document, but if you have specified your own Codable type, specify it instead.

 public class MyNormalDelegate: CompactChangeStreamDelegate {
     typealias DocumentT = Document

     public func didReceive(event: CompactChangeEvent<Document>) {
         // react to events
     }

     // ...other method implementations
 }

 public class MyCustomDelegate: CompactChangeStreamDelegate {
     typealias DocumentT = MyCustomType

     public func didReceive(event: CompactChangeEvent<MyCustomType>) {
         // react to events
     }

     // ...other method implementations
 }
  • Undocumented

    Declaration

    Swift

    associatedtype DocumentT : Decodable, Encodable
  • Called when the change stream receives a Compact MongoDB Change Event. The change event is generic with respect to the type of the documents from the collection. In most collections this will be the Document type from MongoSwift, but you can customize it to have your own type.

    Declaration

    Swift

    func didReceive(event: CompactChangeEvent<DocumentT>)

    Parameters

    event

    the event received on the stream

  • Called when the change stream encounters an error. Errors are uncommon, but may happen if the HTTP stream from the Stitch server sends invalid or corrupted events that cannot be decoded.

    Declaration

    Swift

    func didReceive(streamError: Error)

    Parameters

    streamError

    the error that the stream encountered

  • Called when the initial opening of the stream is complete, meaning that the stream will receive future events that the user is able to see via rules, until the stream is closed.

    Declaration

    Swift

    func didOpen()
  • Called when the stream is closed, meaning there will be no more incoming events.

    Declaration

    Swift

    func didClose()