Skip to content

Add support for unsubscribing after using EventBus.on #5

@chowder

Description

@chowder

Firstly, thanks for developing this library, the API is great.

What feels somewhat missing though is an easy way to unsubscribe after using EventBus.on

I'd like to propose two patterns for this, both of which I think would be very trivial to implement:

bus.on(MyEvent, handler)
# unsubscribe with the same handler and event
bus.remove(MyEvent, handler)
cancel = bus.on(MyEvent, handler)
# unsubscribe using the cancellation callback returned by .on
cancel()

Another small nicety is that this would let you simplify the cleanup in EventBus.expect here: https://github.com/browser-use/bubus/blob/main/bubus/service.py#L611-L614

Happy to be the one raising a PR for this as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions