ContextualMessageHandler

public class ContextualMessageHandler : MessageParser

A utility to parse RawMessages and call their attached handlers within a certain context. This class is similar to PureMessageHandler with the difference that the registered handlers are also passed a certain context in addition to the attached message. This context can be used to determine where the message comes from.

  • Undocumented

    Declaration

    Swift

    public typealias Context = ConnectionState
  • Attaches a message handler to a concrete Message type. Every time a message of this type comes in, the provided handler will be called. The handler takes one generic argument message. The type of this argument indicates the type that this message handler will be attached to.

    Declaration

    Swift

    public func when<M>(_ handler: @escaping (_ message: M, _ context: Context) -> Void) where M : DeserializableMessage

    Parameters

    handler

    The handler to attach

    message

    The message to which the handler is attached

    context

    The context message was sent from.