Should we allow async code in event listeners callbacks?

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: async
    • None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • 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:
            Steve Silvester
            Reporter:
            Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: