Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync handlers #98

Open
danielknell opened this issue May 31, 2024 · 0 comments
Open

feat: sync handlers #98

danielknell opened this issue May 31, 2024 · 0 comments
Labels
feat A new feature

Comments

@danielknell
Copy link
Member

danielknell commented May 31, 2024

Description

Allow registering regular functions as handlers.

Context

Sometimes asynchronous options are not available for handling a request, to handle these cases it would be useful to be able to register regular functions as handlers instead of co-routines.

@registry.subscribe_to(CreateWidget)
def handler(command: CreateWidget, bus: banshee.SyncBus) -> None:
    # synchronous task here
    ...

    bus.handle(WidgetCreated(id=command.id))

Possible implementation

Update the Registry class to allow synchronous functions to be subscribed to requests, and wrap them in a thread pool before registering via loop.run_in_executor.

These synchronous handlers would also need a synchronous wrapper around the MessageBus class to then further publish events.

This will need additional work and documentation around the injector integration to minimise problems with sharing resources between threads.

@danielknell danielknell added the feat A new feature label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat A new feature
Projects
None yet
Development

No branches or pull requests

1 participant