Disconnect with intent - #5782
Conversation
| Local(PendingMutation<M>), | ||
| } | ||
|
|
||
| fn disconnect_result( |
There was a problem hiding this comment.
Making this a function might be a little overkill 🤷🏻
|
Hey @onx2, thanks for opening a PR. Just a heads up that we're currently in the process of reworking the client connection logic; it will probably land sometime in September. I think we'll want to re-evaluate something like this after that. That said, we would likely want to implement this for all SDKs if we're going to move forward with it. |
NP, thanks for the quick turnaround. Let me know when that time comes, I'd love to be a fly on the wall and am happy to implement for all SDKs when a final approach is decided. |
Description of Changes
Adds a new
DisconnectIntentAPI to the Rust SDK. Consumers can useon_disconnect_with_intentto distinguish client-requested disconnects, lost connections, and SDK errors. The existingon_disconnectAPI remains unchanged for compatibility.Use case
Automatic reconnect should apply only to unexpected disconnects, and application-requested disconnects are distinct. For example, when a game player logs out or switches accounts, the client intentionally calls
disconnect(). If the reconnect system treats that event like a network failure, it may reconnect with the cached credentials, restore subscriptions, and make the player appear online again—or reconnect to the wrong account or database (depending on user's implementation).Exposing whether a disconnect was intentional lets integrations such as
bevy_stdbreconnect after network/server failures while remaining disconnected after explicit application shutdown or logout using internal SDK semantics.API and ABI breaking changes
This is additive and does not break the existing API or ABI, but I think in v3 the
on_disconnectshould be replaced by this version.Expected complexity level and risk
1/5
This adds disconnect intent information without changing existing behavior for current consumers.
Testing
cargo check -p spacetimedb-sdkcargo test -p spacetimedb-sdk --lib