code: def register_event(self, name, callback, validator):
          
  
          async def _validate_and_call(message):
              payload = message.get('payload')
  
              try:
                  payload = validator.verify(payload)
              except ValidationError:
                  self._logger.warning("Dropping invalid payload for event %s, payload=%s",
                                       name, payload)
                  return
  
              try:
                  result = callback(payload)
                  if inspect.isawaitable(result):
                      await result
              except:  # pylint:disable=bare-except;This is a background logging routine
                  self._logger.error("Error calling callback for event %s, payload=%s",
                                     name, payload, exc_info=True)
  
          self._manager.every_match(_validate_and_call, type="event", name=name)
docs: Register a callback to receive events.
  
          Every event with the matching name will have its payload validated
          using validator and then will be passed to callback if validation
          succeeds.
  
          Callback must be a normal callback function, coroutines are not
          allowed.  If you need to run a coroutine you are free to schedule it
          from your callback.
  
          Args:
              name (str): The name of the event that we are listening
                  for
              callback (callable): The function that should be called
                  when a message that matches validator is received.
              validator (Verifier): A schema verifier that will
                  validate a received message uniquely