Skip to content

feat: add EventBus.remove() to unsubscribe handlers - #35

Open
HankGrimm wants to merge 2 commits into
browser-use:mainfrom
HankGrimm:feat/eventbus-remove-handler
Open

HankGrimm wants to merge 2 commits into
browser-use:mainfrom
HankGrimm:feat/eventbus-remove-handler

Conversation

@HankGrimm

@HankGrimm HankGrimm commented Sep 11, 2026 •

Copy link
Copy Markdown

What

Add a public EventBus.remove(event_pattern, handler) method so callers can unsubscribe a handler registered with EventBus.on(). Returns True if the handler was found and removed, False otherwise.

Also extract the event-key resolution from on() into _get_event_key() and reuse it in on() and remove(), and refactor expect() cleanup to use remove().

Why

There is no way to unsubscribe after EventBus.on() — the only cleanup path is expect()'s internal self.handlers[...].remove(...). Closes #5.

How tested

  • Added tests/test_remove_handler.py (4 cases: by class, by string name, scoped removal, wildcard *).
  • Core suite: 63 passed.

🤖 Generated with Claude Code


Summary by cubic

Adds EventBus.remove() to unsubscribe a handler registered with EventBus.on(). Returns True if the handler was found and removed, False otherwise. Closes #5.

Changes

  • Extracts event-key resolution into _get_event_key() and reuses it in on(), remove(), and expect() cleanup.
  • Adds overloads mirroring on() so typed handlers remain valid when removed, and drops the event key from the registry once its last handler is gone.
  • Adds tests covering removal by class, string name, scoped handlers, and * wildcard.

Written for commit af4fb71. Summary will update on new commits.

View guided diff

Add a public EventBus.remove(event_pattern, handler) method so callers can
unsubscribe a handler registered with EventBus.on(). Returns True if the
handler was found and removed, False otherwise.

Extract event-key resolution from on() into _get_event_key() and reuse it in
on() and remove(), and refactor expect() cleanup to use remove().

Co-Authored-By: Claude Code <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread bubus/service.py Outdated
Comment thread bubus/service.py
Co-Authored-By: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for unsubscribing after using EventBus.on

1 participant