Add OnConnectionChangeFunc callback to BroflakeOptions#330
Conversation
Allows callers to receive consumer connection state change events (connected/disconnected with worker index and IP) by passing a callback via BroflakeOptions. The callback is set on UIImpl before it gets copied to bus handlers in NewBroflake, ensuring the value receiver method works. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a callback mechanism to allow external callers (such as "radiance") to receive consumer connection state change notifications without modifying broflake's internals. It introduces a new ConnectionChangeFunc type and adds an OnConnectionChangeFunc field to BroflakeOptions, which is wired through the UI implementation to be invoked when consumer connections change state.
Changes:
- Added
ConnectionChangeFunctype for connection state change callbacks - Extended
BroflakeOptionswith optionalOnConnectionChangeFuncfield - Updated non-WASM
UIImplto store and invoke the callback inOnConsumerConnectionChange
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| clientcore/settings.go | Defines ConnectionChangeFunc type and adds OnConnectionChangeFunc field to BroflakeOptions struct |
| clientcore/ui_default_impl.go | Adds OnConnectionChangeFunc field to non-WASM UIImpl struct and invokes callback in OnConsumerConnectionChange method |
| clientcore/broflake.go | Wires the callback from BroflakeOptions to UIImpl before UI is copied to bus handlers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| UI | ||
| BroflakeEngine *BroflakeEngine | ||
| BroflakeEngine *BroflakeEngine | ||
| OnConnectionChangeFunc ConnectionChangeFunc |
There was a problem hiding this comment.
The OnConnectionChangeFunc field is only added to the non-WASM UIImpl struct but not to the WASM version in ui_wasm_impl.go. Since both implementations share the same BroflakeOptions struct and NewBroflake function (which sets ui.OnConnectionChangeFunc at line 171 in broflake.go), this will cause a compilation error for WASM builds. The field needs to be added to the UIImpl struct in ui_wasm_impl.go as well, and the OnConsumerConnectionChange method in that file should also be updated to call the callback if set.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@myleshorton I've opened a new pull request, #331, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: myleshorton <1143966+myleshorton@users.noreply.github.com>
Co-authored-by: myleshorton <1143966+myleshorton@users.noreply.github.com>
[WIP] Update implementation based on feedback for OnConnectionChangeFunc
|
Gonna YOLO this -- pretty small change. |
Summary
ConnectionChangeFunctype andOnConnectionChangeFuncfield toBroflakeOptionsUIImpl.OnConsumerConnectionChangecalls the callback when setNewBroflakewires the callback ontoUIImplbefore it gets copied to bus handlersAllows callers (e.g. radiance) to receive consumer connection state change events without modifying the broflake internals.
🤖 Generated with Claude Code