Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4595

Should we allow async code in event listeners callbacks?

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 4.13
    • Affects Version/s: None
    • Component/s: async
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Should we allow async code in event listeners callbacks? Like a CommandListener that publishes events to some other service via an await:

      class MyListener(AsyncCommandListener):
          async def started(self, event: CommandStartedEvent) -> None:
              await apublish(event)
      

      We could also decide that event listener callbacks should never do blocking I/O. Users that want to use async in a callback would need to defer the work to another thread/loop:

      class MyListener(CommandListener):
          def __init__(self):
              self.async_worker = ...
      
          def started(self, event: CommandStartedEvent) -> None:
              self.async_worker.publish(event)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None