Should we allow async code in event listeners callbacks?

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • next
    • 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
            Reporter:
            Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: